|
|
|
@ -17,24 +17,33 @@
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { Devs } from "@utils/constants";
|
|
|
|
|
import { getCurrentChannel, getCurrentGuild } from "@utils/discord";
|
|
|
|
|
import { SYM_LAZY_CACHED, SYM_LAZY_GET } from "@utils/lazy";
|
|
|
|
|
import { relaunch } from "@utils/native";
|
|
|
|
|
import { canonicalizeMatch, canonicalizeReplace, canonicalizeReplacement } from "@utils/patches";
|
|
|
|
|
import definePlugin, { StartAt } from "@utils/types";
|
|
|
|
|
import definePlugin, { PluginNative, StartAt } from "@utils/types";
|
|
|
|
|
import * as Webpack from "@webpack";
|
|
|
|
|
import { extract, filters, findAll, findModuleId, search } from "@webpack";
|
|
|
|
|
import * as Common from "@webpack/common";
|
|
|
|
|
import type { ComponentType } from "react";
|
|
|
|
|
|
|
|
|
|
const WEB_ONLY = (f: string) => () => {
|
|
|
|
|
const DESKTOP_ONLY = (f: string) => () => {
|
|
|
|
|
throw new Error(`'${f}' is Discord Desktop only.`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default definePlugin({
|
|
|
|
|
name: "ConsoleShortcuts",
|
|
|
|
|
description: "Adds shorter Aliases for many things on the window. Run `shortcutList` for a list.",
|
|
|
|
|
authors: [Devs.Ven],
|
|
|
|
|
const define: typeof Object.defineProperty =
|
|
|
|
|
(obj, prop, desc) => {
|
|
|
|
|
if (Object.hasOwn(desc, "value"))
|
|
|
|
|
desc.writable = true;
|
|
|
|
|
|
|
|
|
|
return Object.defineProperty(obj, prop, {
|
|
|
|
|
configurable: true,
|
|
|
|
|
enumerable: true,
|
|
|
|
|
...desc
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getShortcuts(): Record<PropertyKey, any> {
|
|
|
|
|
function makeShortcuts() {
|
|
|
|
|
function newFindWrapper(filterFactory: (...props: any[]) => Webpack.FilterFn) {
|
|
|
|
|
const cache = new Map<string, unknown>();
|
|
|
|
|
|
|
|
|
@ -87,14 +96,17 @@ export default definePlugin({
|
|
|
|
|
plugins: { getter: () => Vencord.Plugins.plugins },
|
|
|
|
|
Settings: { getter: () => Vencord.Settings },
|
|
|
|
|
Api: { getter: () => Vencord.Api },
|
|
|
|
|
Util: { getter: () => Vencord.Util },
|
|
|
|
|
reload: () => location.reload(),
|
|
|
|
|
restart: IS_WEB ? WEB_ONLY("restart") : relaunch,
|
|
|
|
|
restart: IS_WEB ? DESKTOP_ONLY("restart") : relaunch,
|
|
|
|
|
canonicalizeMatch,
|
|
|
|
|
canonicalizeReplace,
|
|
|
|
|
canonicalizeReplacement,
|
|
|
|
|
fakeRender: (component: ComponentType, props: any) => {
|
|
|
|
|
const prevWin = fakeRenderWin?.deref();
|
|
|
|
|
const win = prevWin?.closed === false ? prevWin : window.open("about:blank", "Fake Render", "popup,width=500,height=500")!;
|
|
|
|
|
const win = prevWin?.closed === false
|
|
|
|
|
? prevWin
|
|
|
|
|
: window.open("about:blank", "Fake Render", "popup,width=500,height=500")!;
|
|
|
|
|
fakeRenderWin = new WeakRef(win);
|
|
|
|
|
win.focus();
|
|
|
|
|
|
|
|
|
@ -117,38 +129,86 @@ export default definePlugin({
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Common.ReactDOM.render(Common.React.createElement(component, props), doc.body.appendChild(document.createElement("div")));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
preEnable: (plugin: string) => (Vencord.Settings.plugins[plugin] ??= { enabled: true }).enabled = true,
|
|
|
|
|
|
|
|
|
|
channel: { getter: () => getCurrentChannel(), preload: false },
|
|
|
|
|
channelId: { getter: () => Common.SelectedChannelStore.getChannelId(), preload: false },
|
|
|
|
|
guild: { getter: () => getCurrentGuild(), preload: false },
|
|
|
|
|
guildId: { getter: () => Common.SelectedGuildStore.getGuildId(), preload: false },
|
|
|
|
|
me: { getter: () => Common.UserStore.getCurrentUser(), preload: false },
|
|
|
|
|
meId: { getter: () => Common.UserStore.getCurrentUser().id, preload: false },
|
|
|
|
|
messages: { getter: () => Common.MessageStore.getMessages(Common.SelectedChannelStore.getChannelId()), preload: false }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadAndCacheShortcut(key: string, val: any, forceLoad: boolean) {
|
|
|
|
|
const currentVal = val.getter();
|
|
|
|
|
if (!currentVal || val.preload === false) return currentVal;
|
|
|
|
|
|
|
|
|
|
const value = currentVal[SYM_LAZY_GET]
|
|
|
|
|
? forceLoad ? currentVal[SYM_LAZY_GET]() : currentVal[SYM_LAZY_CACHED]
|
|
|
|
|
: currentVal;
|
|
|
|
|
|
|
|
|
|
if (value) define(window.shortcutList, key, { value });
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default definePlugin({
|
|
|
|
|
name: "ConsoleShortcuts",
|
|
|
|
|
description: "Adds shorter Aliases for many things on the window. Run `shortcutList` for a list.",
|
|
|
|
|
authors: [Devs.Ven],
|
|
|
|
|
|
|
|
|
|
startAt: StartAt.Init,
|
|
|
|
|
start() {
|
|
|
|
|
const shortcuts = this.getShortcuts();
|
|
|
|
|
const shortcuts = makeShortcuts();
|
|
|
|
|
window.shortcutList = {};
|
|
|
|
|
|
|
|
|
|
for (const [key, val] of Object.entries(shortcuts)) {
|
|
|
|
|
if (val.getter != null) {
|
|
|
|
|
Object.defineProperty(window.shortcutList, key, {
|
|
|
|
|
get: val.getter,
|
|
|
|
|
configurable: true,
|
|
|
|
|
enumerable: true
|
|
|
|
|
if ("getter" in val) {
|
|
|
|
|
define(window.shortcutList, key, {
|
|
|
|
|
get: () => loadAndCacheShortcut(key, val, true)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(window, key, {
|
|
|
|
|
get: () => window.shortcutList[key],
|
|
|
|
|
configurable: true,
|
|
|
|
|
enumerable: true
|
|
|
|
|
define(window, key, {
|
|
|
|
|
get: () => window.shortcutList[key]
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
window.shortcutList[key] = val;
|
|
|
|
|
window[key] = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unproxy loaded modules
|
|
|
|
|
Webpack.onceReady.then(() => {
|
|
|
|
|
setTimeout(() => this.eagerLoad(false), 1000);
|
|
|
|
|
|
|
|
|
|
if (!IS_WEB) {
|
|
|
|
|
const Native = VencordNative.pluginHelpers.ConsoleShortcuts as PluginNative<typeof import("./native")>;
|
|
|
|
|
Native.initDevtoolsOpenEagerLoad();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async eagerLoad(forceLoad: boolean) {
|
|
|
|
|
await Webpack.onceReady;
|
|
|
|
|
|
|
|
|
|
const shortcuts = makeShortcuts();
|
|
|
|
|
|
|
|
|
|
for (const [key, val] of Object.entries(shortcuts)) {
|
|
|
|
|
if (!Object.hasOwn(val, "getter") || (val as any).preload === false) continue;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
loadAndCacheShortcut(key, val, forceLoad);
|
|
|
|
|
} catch { } // swallow not found errors in DEV
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
|
delete window.shortcutList;
|
|
|
|
|
for (const key in this.getShortcuts()) {
|
|
|
|
|
for (const key in makeShortcuts()) {
|
|
|
|
|
delete window[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|