ConsoleShortcuts: Start at Init
This commit is contained in:
parent
8f59cd8a1a
commit
a8e18f17e2
1 changed files with 39 additions and 19 deletions
|
@ -19,10 +19,10 @@
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { relaunch } from "@utils/native";
|
import { relaunch } from "@utils/native";
|
||||||
import { canonicalizeMatch, canonicalizeReplace, canonicalizeReplacement } from "@utils/patches";
|
import { canonicalizeMatch, canonicalizeReplace, canonicalizeReplacement } from "@utils/patches";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin, { StartAt } from "@utils/types";
|
||||||
import * as Webpack from "@webpack";
|
import * as Webpack from "@webpack";
|
||||||
import { extract, filters, findAll, search } from "@webpack";
|
import { extract, filters, findAll, findModuleId, search } from "@webpack";
|
||||||
import { React, ReactDOM } from "@webpack/common";
|
import * as Common from "@webpack/common";
|
||||||
import type { ComponentType } from "react";
|
import type { ComponentType } from "react";
|
||||||
|
|
||||||
const WEB_ONLY = (f: string) => () => {
|
const WEB_ONLY = (f: string) => () => {
|
||||||
|
@ -34,7 +34,7 @@ export default definePlugin({
|
||||||
description: "Adds shorter Aliases for many things on the window. Run `shortcutList` for a list.",
|
description: "Adds shorter Aliases for many things on the window. Run `shortcutList` for a list.",
|
||||||
authors: [Devs.Ven],
|
authors: [Devs.Ven],
|
||||||
|
|
||||||
getShortcuts() {
|
getShortcuts(): Record<PropertyKey, any> {
|
||||||
function newFindWrapper(filterFactory: (...props: any[]) => Webpack.FilterFn) {
|
function newFindWrapper(filterFactory: (...props: any[]) => Webpack.FilterFn) {
|
||||||
const cache = new Map<string, unknown>();
|
const cache = new Map<string, unknown>();
|
||||||
|
|
||||||
|
@ -64,16 +64,17 @@ export default definePlugin({
|
||||||
let fakeRenderWin: WeakRef<Window> | undefined;
|
let fakeRenderWin: WeakRef<Window> | undefined;
|
||||||
const find = newFindWrapper(f => f);
|
const find = newFindWrapper(f => f);
|
||||||
const findByProps = newFindWrapper(filters.byProps);
|
const findByProps = newFindWrapper(filters.byProps);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...Vencord.Webpack.Common,
|
...Object.fromEntries(Object.keys(Common).map(key => [key, { getter: () => Common[key] }])),
|
||||||
wp: Vencord.Webpack,
|
wp: Webpack,
|
||||||
wpc: Webpack.wreq.c,
|
wpc: { getter: () => Webpack.cache },
|
||||||
wreq: Webpack.wreq,
|
wreq: { getter: () => Webpack.wreq },
|
||||||
wpsearch: search,
|
wpsearch: search,
|
||||||
wpex: extract,
|
wpex: extract,
|
||||||
wpexs: (code: string) => extract(Webpack.findModuleId(code)!),
|
wpexs: (code: string) => extract(findModuleId(code)!),
|
||||||
find,
|
find,
|
||||||
findAll,
|
findAll: findAll,
|
||||||
findByProps,
|
findByProps,
|
||||||
findAllByProps: (...props: string[]) => findAll(filters.byProps(...props)),
|
findAllByProps: (...props: string[]) => findAll(filters.byProps(...props)),
|
||||||
findByCode: newFindWrapper(filters.byCode),
|
findByCode: newFindWrapper(filters.byCode),
|
||||||
|
@ -82,10 +83,10 @@ export default definePlugin({
|
||||||
findAllComponentsByCode: (...code: string[]) => findAll(filters.componentByCode(...code)),
|
findAllComponentsByCode: (...code: string[]) => findAll(filters.componentByCode(...code)),
|
||||||
findExportedComponent: (...props: string[]) => findByProps(...props)[props[0]],
|
findExportedComponent: (...props: string[]) => findByProps(...props)[props[0]],
|
||||||
findStore: newFindWrapper(filters.byStoreName),
|
findStore: newFindWrapper(filters.byStoreName),
|
||||||
PluginsApi: Vencord.Plugins,
|
PluginsApi: { getter: () => Vencord.Plugins },
|
||||||
plugins: Vencord.Plugins.plugins,
|
plugins: { getter: () => Vencord.Plugins.plugins },
|
||||||
Settings: Vencord.Settings,
|
Settings: { getter: () => Vencord.Settings },
|
||||||
Api: Vencord.Api,
|
Api: { getter: () => Vencord.Api },
|
||||||
reload: () => location.reload(),
|
reload: () => location.reload(),
|
||||||
restart: IS_WEB ? WEB_ONLY("restart") : relaunch,
|
restart: IS_WEB ? WEB_ONLY("restart") : relaunch,
|
||||||
canonicalizeMatch,
|
canonicalizeMatch,
|
||||||
|
@ -115,21 +116,40 @@ export default definePlugin({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ReactDOM.render(React.createElement(component, props), doc.body.appendChild(document.createElement("div")));
|
Common.ReactDOM.render(Common.React.createElement(component, props), doc.body.appendChild(document.createElement("div")));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
startAt: StartAt.Init,
|
||||||
start() {
|
start() {
|
||||||
const shortcuts = this.getShortcuts();
|
const shortcuts = this.getShortcuts();
|
||||||
window.shortcutList = shortcuts;
|
window.shortcutList = {};
|
||||||
for (const [key, val] of Object.entries(shortcuts))
|
|
||||||
window[key] = val;
|
for (const [key, val] of Object.entries(shortcuts)) {
|
||||||
|
if (val.getter != null) {
|
||||||
|
Object.defineProperty(window.shortcutList, key, {
|
||||||
|
get: val.getter,
|
||||||
|
configurable: true,
|
||||||
|
enumerable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(window, key, {
|
||||||
|
get: () => window.shortcutList[key],
|
||||||
|
configurable: true,
|
||||||
|
enumerable: true
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
window.shortcutList[key] = val;
|
||||||
|
window[key] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
delete window.shortcutList;
|
delete window.shortcutList;
|
||||||
for (const key in this.getShortcuts())
|
for (const key in this.getShortcuts()) {
|
||||||
delete window[key];
|
delete window[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue