forked from Demon/demoncord
Compare commits
13 Commits
Author | SHA1 | Date |
---|---|---|
Drake | 17c6bfd336 | 2 years ago |
Drake | a694bb1f60 | 2 years ago |
Drake | 67612a8f1d | 2 years ago |
Drake | 428886645f | 2 years ago |
Drake | d50b3ef708 | 2 years ago |
Drake | 72606d3813 | 2 years ago |
Drake | 8dbed1dd82 | 2 years ago |
Drake | 1108ca097e | 2 years ago |
Drake | 017120d8d3 | 2 years ago |
Drake | 50741a3569 | 2 years ago |
Drake | 1cd06e2aab | 2 years ago |
Drake | a507bb52a1 | 2 years ago |
Drake | 2a4389a61b | 2 years ago |
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"presets": ["@babel/preset-flow", "@babel/preset-react"]
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
import esbuild from "esbuild";
|
||||||
|
import babel from "esbuild-plugin-babel";
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
await esbuild.build({
|
||||||
|
entryPoints: ["src/index.js"],
|
||||||
|
bundle: true,
|
||||||
|
minify: true,
|
||||||
|
format: "iife",
|
||||||
|
target: "es2021",
|
||||||
|
outfile: "dist/build.js",
|
||||||
|
plugins: [babel()]
|
||||||
|
});
|
||||||
|
console.log("Build succeeded!");
|
||||||
|
process.exit(0);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
console.log("Build failed!");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
})(); //IIFE to shutup lsp
|
@ -1,26 +1,25 @@
|
|||||||
{
|
{
|
||||||
"name": "demoncord",
|
"name": "demoncord",
|
||||||
"version": "0.0.1-indev",
|
"version": "0.0.1-indev",
|
||||||
"description": "a devilesque client mod 😈",
|
"description": "a devilesque client mod 😈",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rollup --config rollup.config.js",
|
"build": "node build.mjs",
|
||||||
"flow": "flow"
|
"flow": "flow"
|
||||||
},
|
},
|
||||||
"author": "Drake",
|
"author": "Drake",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-commonjs": "^21.0.1",
|
"@babel/core": "^7.17.8",
|
||||||
"@rollup/plugin-node-resolve": "^13.1.3",
|
"@babel/preset-flow": "^7.16.7",
|
||||||
"demonpatcher": "^0.1.0",
|
"@babel/preset-react": "^7.16.7",
|
||||||
"esbuild": "^0.14.11",
|
"esbuild": "^0.14.27",
|
||||||
"flow-bin": "^0.169.0",
|
"esbuild-plugin-babel": "^0.2.3",
|
||||||
"flow-remove-types": "^2.169.0",
|
"flow-bin": "^0.169.0",
|
||||||
"idb-keyval": "^6.0.3",
|
"flow-remove-types": "^2.174.1",
|
||||||
"rollup": "^2.63.0",
|
"idb-keyval": "^6.1.0",
|
||||||
"rollup-plugin-esbuild": "^4.8.2",
|
"react": "^17.0.2",
|
||||||
"rollup-plugin-flow": "^1.1.1",
|
"react-dom": "^17.0.2",
|
||||||
"rollup-plugin-uglify": "^6.0.4",
|
"simian": "^1.4.3"
|
||||||
"simian": "^1.4.3"
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,14 +0,0 @@
|
|||||||
import flow from "rollup-plugin-flow";
|
|
||||||
import { minify } from "rollup-plugin-esbuild";
|
|
||||||
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
||||||
import commonjs from "@rollup/plugin-commonjs";
|
|
||||||
import { defineConfig } from "rollup";
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
input: "src/index.js",
|
|
||||||
plugins: [flow(), commonjs(), nodeResolve(), minify()],
|
|
||||||
output: {
|
|
||||||
file: "dist/build.js",
|
|
||||||
format: "iife",
|
|
||||||
},
|
|
||||||
});
|
|
@ -0,0 +1,3 @@
|
|||||||
|
import { React } from "../src/api/common.js";
|
||||||
|
|
||||||
|
export { React };
|
@ -1,18 +1,18 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import webpack from "./webpack.js"
|
import webpack from "./webpack.js";
|
||||||
|
|
||||||
import * as idb from "idb-keyval";
|
import * as idb from "idb-keyval";
|
||||||
|
|
||||||
const common: {React: Object, ReactDOM: Object} = {
|
const common: { React: Object, ReactDOM: Object } = {
|
||||||
React: webpack.findByProps(
|
React: webpack.findByProps(
|
||||||
"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED",
|
"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED",
|
||||||
"createElement"
|
"createElement"
|
||||||
),
|
),
|
||||||
ReactDOM: webpack.findByProps(
|
ReactDOM: webpack.findByProps(
|
||||||
"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED",
|
"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED",
|
||||||
"hydrate"
|
"hydrate"
|
||||||
),
|
),
|
||||||
"idb_keyval": idb
|
idb_keyval: idb
|
||||||
}
|
};
|
||||||
|
|
||||||
export default common;
|
export default common;
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
// @flow
|
||||||
|
//TODO: proper typing
|
||||||
|
//TODO: use webpack to find
|
||||||
|
|
||||||
|
//TODO: funny sink code
|
||||||
|
//(() => {
|
||||||
|
// const raw = findAll(
|
||||||
|
// (m) =>
|
||||||
|
// typeof m === "object" &&
|
||||||
|
// Object.values(m).length > 0 &&
|
||||||
|
// Object.values(m).every((v) => typeof v === "string")
|
||||||
|
// );
|
||||||
|
// const map = new Map();
|
||||||
|
// for (const m of raw)
|
||||||
|
// for (const [k, v] of Object.entries(m))
|
||||||
|
// if (map.has(k)) map.get(k).push(v);
|
||||||
|
// else map.set(k, [v]);
|
||||||
|
// return map;
|
||||||
|
//})();
|
||||||
|
function getAllClasses() {
|
||||||
|
return document.styleSheets[0].rules || document.styleSheets[0].cssRules;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getClassListByName(className) {
|
||||||
|
const classes = getAllClasses();
|
||||||
|
return classes;
|
||||||
|
}
|
||||||
|
|
||||||
|
//how to define getters and setters on an object:
|
||||||
|
//
|
||||||
|
//Object.defineProperty(hello, "place", {
|
||||||
|
// set: (x) => {
|
||||||
|
// this.oldPlace = this.place;
|
||||||
|
// this.place = x;
|
||||||
|
// },
|
||||||
|
// get: (x) => {
|
||||||
|
// console.log(
|
||||||
|
// "Current place: " + this.place + "\nPlace before this: " + this.oldPlace
|
||||||
|
// );
|
||||||
|
// return this.place;
|
||||||
|
// },
|
||||||
|
//});
|
||||||
|
|
||||||
|
function getProxyObj(classes) {}
|
||||||
|
|
||||||
|
function init(obj: Object) {
|
||||||
|
obj.demon.css = {
|
||||||
|
classes: {
|
||||||
|
get: (className) => {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
init
|
||||||
|
};
|
@ -0,0 +1,83 @@
|
|||||||
|
// @flow
|
||||||
|
/*import { make, join } from '@modules/styles';
|
||||||
|
import SettingsAPI from '@modules/apis/Settings';
|
||||||
|
import Manager, { modules } from '@modules/manager';
|
||||||
|
|
||||||
|
const styles = make('pluginCard');
|
||||||
|
const Settings = SettingsAPI.create('modules');
|
||||||
|
|
||||||
|
const { Filters } = Webpack;
|
||||||
|
|
||||||
|
const [
|
||||||
|
SwitchItem,
|
||||||
|
{ Heading },
|
||||||
|
SettingsIcon,
|
||||||
|
] = Webpack.bulk(
|
||||||
|
Filters.byDisplayName('SwitchItem'),
|
||||||
|
Filters.byProps('Heading'),
|
||||||
|
Filters.byDisplayName('Gear'),
|
||||||
|
);*/
|
||||||
|
|
||||||
|
import common from "../../../common";
|
||||||
|
import webpack from "../../../webpack";
|
||||||
|
const React = common.React;
|
||||||
|
|
||||||
|
const SwitchItem = webpack.findByDisplayName("SwitchItem");
|
||||||
|
const { Heading } = webpack.findByProps("Heading");
|
||||||
|
const SettingsIcon = webpack.findByDisplayName("Gear");
|
||||||
|
|
||||||
|
function useDidUpdateEffect(effect, deps?) {
|
||||||
|
const didMountRef = React.useRef(false);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (didMountRef.current) return effect();
|
||||||
|
|
||||||
|
// else set didMount to true
|
||||||
|
didMountRef.current = true;
|
||||||
|
}, deps);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default (module: {
|
||||||
|
file: string,
|
||||||
|
name: string,
|
||||||
|
version: string,
|
||||||
|
description: string,
|
||||||
|
setPage: React.Dispatch<React.SetStateAction<string>>
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<div className={styles.container}>
|
||||||
|
<div className={styles.headerContainer}>
|
||||||
|
<div className={styles.textContainer}>
|
||||||
|
<Heading
|
||||||
|
level={2}
|
||||||
|
lineClamp={1}
|
||||||
|
className={styles.text}
|
||||||
|
variant="heading-lg/medium"
|
||||||
|
>
|
||||||
|
{module.name}
|
||||||
|
</Heading>
|
||||||
|
<div className={styles.version}>{module.version}</div>
|
||||||
|
</div>
|
||||||
|
<SwitchItem
|
||||||
|
hideBorder
|
||||||
|
value={enabled}
|
||||||
|
onChange={setEnabled}
|
||||||
|
className={styles.switch}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
className={join(
|
||||||
|
styles.settings,
|
||||||
|
!enabled || !settings ? styles.settingsDisabled : false
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<SettingsIcon
|
||||||
|
onClick={() =>
|
||||||
|
enabled && settings && setPage(module.file)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className={styles.description}>{module.description}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
@ -0,0 +1,16 @@
|
|||||||
|
// @flow
|
||||||
|
import webpack from "../../webpack.js";
|
||||||
|
import common from "../../common.js";
|
||||||
|
const React = common.React;
|
||||||
|
|
||||||
|
const FormTitle = webpack.findByDisplayName("FormTitle");
|
||||||
|
const FormDivider = webpack.findByDisplayName("FormDivider");
|
||||||
|
const FormSection = webpack.findByDisplayName("FormSection");
|
||||||
|
|
||||||
|
export default function (): any {
|
||||||
|
return (
|
||||||
|
<FormSection>
|
||||||
|
<FormTitle tag="h1">Demoncord Settings</FormTitle>
|
||||||
|
</FormSection>
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
// @flow
|
||||||
|
import tmp from "./settingsInj.js";
|
||||||
|
const registerSettingsEntry = tmp.registerSettingsEntry;
|
||||||
|
import common from "../common.js";
|
||||||
|
const React = common.React;
|
||||||
|
|
||||||
|
import Settings from "./components/settings.jsx";
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
console.log(Settings);
|
||||||
|
console.log(Settings());
|
||||||
|
registerSettingsEntry("General Settings", undefined, Settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
init
|
||||||
|
};
|
@ -1,60 +1,69 @@
|
|||||||
// @flow
|
// @flow
|
||||||
type ModuleType = Object/* { [symbol]: any } */;
|
type ModuleType = Object /* { [symbol]: any } */;
|
||||||
type FilterFunc = (module: ModuleType) => boolean;
|
type FilterFunc = (module: ModuleType) => boolean;
|
||||||
|
|
||||||
function getModules(): any {
|
function getModules(): any {
|
||||||
let modules: { c: mixed[] } = {};
|
let modules: { c: mixed[] } = {};
|
||||||
|
|
||||||
window.webpackChunkdiscord_app.push([
|
window.webpackChunkdiscord_app.push([
|
||||||
[Math.random().toString(36)],
|
[Math.random().toString(36)],
|
||||||
{},
|
{},
|
||||||
(e) => {
|
(e) => {
|
||||||
modules = e;
|
modules = e;
|
||||||
},
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return modules.c;
|
return modules.c;
|
||||||
}
|
}
|
||||||
|
|
||||||
function filter(filter: FilterFunc, moduleList: any): Array<Object> {
|
function filter(filter: FilterFunc, moduleList: any): Array<Object> {
|
||||||
let modules: Array<mixed[]> = [];
|
let modules: Array<mixed[]> = [];
|
||||||
for (const mod in moduleList) {
|
for (const mod in moduleList) {
|
||||||
const module = moduleList[mod].exports;
|
const module = moduleList[mod].exports;
|
||||||
if (module) {
|
if (module) {
|
||||||
if (module.default && module.__esModule && filter(module.default)) {
|
if (module.default && module.__esModule && filter(module.default)) {
|
||||||
modules.push(module.default);
|
modules.push(module.default);
|
||||||
} else if (filter(module)) {
|
} else if (filter(module)) {
|
||||||
modules.push(module);
|
modules.push(module);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return modules;
|
||||||
return modules;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebpackModules = {
|
type WebpackModules = {
|
||||||
modules: () => any,
|
modules: () => any,
|
||||||
filter: (filter: FilterFunc, moduleList: any) => Object[],
|
filter: (filter: FilterFunc, moduleList: any) => Object[],
|
||||||
find: (filter: FilterFunc) => Object,
|
find: (filter: FilterFunc) => Object,
|
||||||
findAll: (filter: FilterFunc) => Object[],
|
findAll: (filter: FilterFunc) => Object[],
|
||||||
findByProps: (...props: string[]) => Object,
|
findByProps: (...props: string[]) => Object,
|
||||||
findByPropsAll: (...props: string[]) => Object[],
|
findByPropsAll: (...props: string[]) => Object[],
|
||||||
|
findByDisplayName: (prop: string) => Object[],
|
||||||
|
reloadModules: () => void
|
||||||
};
|
};
|
||||||
|
|
||||||
let webpack: WebpackModules = {
|
let webpack: WebpackModules = {
|
||||||
modules: getModules(),
|
modules: getModules(),
|
||||||
filter: filter,
|
filter: filter,
|
||||||
find: (filter: FilterFunc) => webpack.filter(filter, webpack.modules)[0],
|
find: (filter: FilterFunc) => webpack.filter(filter, webpack.modules)[0],
|
||||||
findAll: (filter: FilterFunc) => webpack.filter(filter, webpack.modules),
|
findAll: (filter: FilterFunc) => webpack.filter(filter, webpack.modules),
|
||||||
findByProps: (...props: Array<string>) => {
|
findByProps: (...props: Array<string>) => {
|
||||||
return webpack.find((module) => {
|
return webpack.find((module) => {
|
||||||
return props.every((prop) => module[prop] !== undefined);
|
return props.every((prop) => module[prop] !== undefined);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
findByPropsAll: (...props: Array<string>) => {
|
findByPropsAll: (...props: Array<string>) => {
|
||||||
return webpack.findAll((module) =>
|
return webpack.findAll((module) =>
|
||||||
props.every((prop) => module[prop] !== undefined)
|
props.every((prop) => module[prop] !== undefined)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
findByDisplayName: (prop: string) => {
|
||||||
|
return webpack.find((m) => m?.default?.displayName === prop);
|
||||||
|
},
|
||||||
|
reloadModules: () => {
|
||||||
|
//NOTE: i have no idea why this could even feasibly need to be used, but i'm adding it anyways
|
||||||
|
webpack.modules = getModules();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default webpack;
|
export default webpack;
|
||||||
|
@ -1,7 +1,34 @@
|
|||||||
import init from "./init.js"
|
// @flow
|
||||||
|
import init from "./init.js";
|
||||||
|
import settingsInj from "./api/settings/settingsInj";
|
||||||
|
import commands from "./api/commands";
|
||||||
|
|
||||||
if (window.demon) {
|
const obj = {};
|
||||||
delete window.demon; // this is a very good idea
|
|
||||||
|
init(obj);
|
||||||
|
|
||||||
|
window.demon = {};
|
||||||
|
|
||||||
|
function isAllowed(mod: String): boolean {
|
||||||
|
//TODO: permissions checking
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
init(window)
|
window.demon.require = (mod: String): Object => {
|
||||||
|
if (!isAllowed(mod)) {
|
||||||
|
throw new Error("Not allowed!"); //TODO: make this not irrepairably error out
|
||||||
|
}
|
||||||
|
const mods = mod.split("/");
|
||||||
|
let res = obj.demon;
|
||||||
|
mods.forEach((m) => {
|
||||||
|
if (m in res) {
|
||||||
|
res = res[m];
|
||||||
|
} else {
|
||||||
|
throw new Error("Module does not exist!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
settingsInj.init();
|
||||||
|
commands.init(obj);
|
||||||
|
Loading…
Reference in new issue