|
|
@ -17,138 +17,198 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import { Devs } from "@utils/constants";
|
|
|
|
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 { relaunch } from "@utils/native";
|
|
|
|
import { canonicalizeMatch, canonicalizeReplace, canonicalizeReplacement } from "@utils/patches";
|
|
|
|
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 * as Webpack from "@webpack";
|
|
|
|
import { extract, filters, findAll, findModuleId, search } from "@webpack";
|
|
|
|
import { extract, filters, findAll, findModuleId, search } from "@webpack";
|
|
|
|
import * as Common 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 DESKTOP_ONLY = (f: string) => () => {
|
|
|
|
throw new Error(`'${f}' is Discord Desktop only.`);
|
|
|
|
throw new Error(`'${f}' is Discord Desktop only.`);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function makeShortcuts() {
|
|
|
|
|
|
|
|
function newFindWrapper(filterFactory: (...props: any[]) => Webpack.FilterFn) {
|
|
|
|
|
|
|
|
const cache = new Map<string, unknown>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return function (...filterProps: unknown[]) {
|
|
|
|
|
|
|
|
const cacheKey = String(filterProps);
|
|
|
|
|
|
|
|
if (cache.has(cacheKey)) return cache.get(cacheKey);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const matches = findAll(filterFactory(...filterProps));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result = (() => {
|
|
|
|
|
|
|
|
switch (matches.length) {
|
|
|
|
|
|
|
|
case 0: return null;
|
|
|
|
|
|
|
|
case 1: return matches[0];
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
const uniqueMatches = [...new Set(matches)];
|
|
|
|
|
|
|
|
if (uniqueMatches.length > 1)
|
|
|
|
|
|
|
|
console.warn(`Warning: This filter matches ${matches.length} modules. Make it more specific!\n`, uniqueMatches);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return matches[0];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
if (result && cacheKey) cache.set(cacheKey, result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let fakeRenderWin: WeakRef<Window> | undefined;
|
|
|
|
|
|
|
|
const find = newFindWrapper(f => f);
|
|
|
|
|
|
|
|
const findByProps = newFindWrapper(filters.byProps);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
...Object.fromEntries(Object.keys(Common).map(key => [key, { getter: () => Common[key] }])),
|
|
|
|
|
|
|
|
wp: Webpack,
|
|
|
|
|
|
|
|
wpc: { getter: () => Webpack.cache },
|
|
|
|
|
|
|
|
wreq: { getter: () => Webpack.wreq },
|
|
|
|
|
|
|
|
wpsearch: search,
|
|
|
|
|
|
|
|
wpex: extract,
|
|
|
|
|
|
|
|
wpexs: (code: string) => extract(findModuleId(code)!),
|
|
|
|
|
|
|
|
find,
|
|
|
|
|
|
|
|
findAll: findAll,
|
|
|
|
|
|
|
|
findByProps,
|
|
|
|
|
|
|
|
findAllByProps: (...props: string[]) => findAll(filters.byProps(...props)),
|
|
|
|
|
|
|
|
findByCode: newFindWrapper(filters.byCode),
|
|
|
|
|
|
|
|
findAllByCode: (code: string) => findAll(filters.byCode(code)),
|
|
|
|
|
|
|
|
findComponentByCode: newFindWrapper(filters.componentByCode),
|
|
|
|
|
|
|
|
findAllComponentsByCode: (...code: string[]) => findAll(filters.componentByCode(...code)),
|
|
|
|
|
|
|
|
findExportedComponent: (...props: string[]) => findByProps(...props)[props[0]],
|
|
|
|
|
|
|
|
findStore: newFindWrapper(filters.byStoreName),
|
|
|
|
|
|
|
|
PluginsApi: { getter: () => Vencord.Plugins },
|
|
|
|
|
|
|
|
plugins: { getter: () => Vencord.Plugins.plugins },
|
|
|
|
|
|
|
|
Settings: { getter: () => Vencord.Settings },
|
|
|
|
|
|
|
|
Api: { getter: () => Vencord.Api },
|
|
|
|
|
|
|
|
Util: { getter: () => Vencord.Util },
|
|
|
|
|
|
|
|
reload: () => location.reload(),
|
|
|
|
|
|
|
|
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")!;
|
|
|
|
|
|
|
|
fakeRenderWin = new WeakRef(win);
|
|
|
|
|
|
|
|
win.focus();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const doc = win.document;
|
|
|
|
|
|
|
|
doc.body.style.margin = "1em";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!win.prepared) {
|
|
|
|
|
|
|
|
win.prepared = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[...document.querySelectorAll("style"), ...document.querySelectorAll("link[rel=stylesheet]")].forEach(s => {
|
|
|
|
|
|
|
|
const n = s.cloneNode(true) as HTMLStyleElement | HTMLLinkElement;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (s.parentElement?.tagName === "HEAD")
|
|
|
|
|
|
|
|
doc.head.append(n);
|
|
|
|
|
|
|
|
else if (n.id?.startsWith("vencord-") || n.id?.startsWith("vcd-"))
|
|
|
|
|
|
|
|
doc.documentElement.append(n);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
doc.body.append(n);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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({
|
|
|
|
export default definePlugin({
|
|
|
|
name: "ConsoleShortcuts",
|
|
|
|
name: "ConsoleShortcuts",
|
|
|
|
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(): Record<PropertyKey, any> {
|
|
|
|
|
|
|
|
function newFindWrapper(filterFactory: (...props: any[]) => Webpack.FilterFn) {
|
|
|
|
|
|
|
|
const cache = new Map<string, unknown>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return function (...filterProps: unknown[]) {
|
|
|
|
|
|
|
|
const cacheKey = String(filterProps);
|
|
|
|
|
|
|
|
if (cache.has(cacheKey)) return cache.get(cacheKey);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const matches = findAll(filterFactory(...filterProps));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result = (() => {
|
|
|
|
|
|
|
|
switch (matches.length) {
|
|
|
|
|
|
|
|
case 0: return null;
|
|
|
|
|
|
|
|
case 1: return matches[0];
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
const uniqueMatches = [...new Set(matches)];
|
|
|
|
|
|
|
|
if (uniqueMatches.length > 1)
|
|
|
|
|
|
|
|
console.warn(`Warning: This filter matches ${matches.length} modules. Make it more specific!\n`, uniqueMatches);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return matches[0];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
if (result && cacheKey) cache.set(cacheKey, result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let fakeRenderWin: WeakRef<Window> | undefined;
|
|
|
|
|
|
|
|
const find = newFindWrapper(f => f);
|
|
|
|
|
|
|
|
const findByProps = newFindWrapper(filters.byProps);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
...Object.fromEntries(Object.keys(Common).map(key => [key, { getter: () => Common[key] }])),
|
|
|
|
|
|
|
|
wp: Webpack,
|
|
|
|
|
|
|
|
wpc: { getter: () => Webpack.cache },
|
|
|
|
|
|
|
|
wreq: { getter: () => Webpack.wreq },
|
|
|
|
|
|
|
|
wpsearch: search,
|
|
|
|
|
|
|
|
wpex: extract,
|
|
|
|
|
|
|
|
wpexs: (code: string) => extract(findModuleId(code)!),
|
|
|
|
|
|
|
|
find,
|
|
|
|
|
|
|
|
findAll: findAll,
|
|
|
|
|
|
|
|
findByProps,
|
|
|
|
|
|
|
|
findAllByProps: (...props: string[]) => findAll(filters.byProps(...props)),
|
|
|
|
|
|
|
|
findByCode: newFindWrapper(filters.byCode),
|
|
|
|
|
|
|
|
findAllByCode: (code: string) => findAll(filters.byCode(code)),
|
|
|
|
|
|
|
|
findComponentByCode: newFindWrapper(filters.componentByCode),
|
|
|
|
|
|
|
|
findAllComponentsByCode: (...code: string[]) => findAll(filters.componentByCode(...code)),
|
|
|
|
|
|
|
|
findExportedComponent: (...props: string[]) => findByProps(...props)[props[0]],
|
|
|
|
|
|
|
|
findStore: newFindWrapper(filters.byStoreName),
|
|
|
|
|
|
|
|
PluginsApi: { getter: () => Vencord.Plugins },
|
|
|
|
|
|
|
|
plugins: { getter: () => Vencord.Plugins.plugins },
|
|
|
|
|
|
|
|
Settings: { getter: () => Vencord.Settings },
|
|
|
|
|
|
|
|
Api: { getter: () => Vencord.Api },
|
|
|
|
|
|
|
|
reload: () => location.reload(),
|
|
|
|
|
|
|
|
restart: IS_WEB ? WEB_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")!;
|
|
|
|
|
|
|
|
fakeRenderWin = new WeakRef(win);
|
|
|
|
|
|
|
|
win.focus();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const doc = win.document;
|
|
|
|
|
|
|
|
doc.body.style.margin = "1em";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!win.prepared) {
|
|
|
|
|
|
|
|
win.prepared = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[...document.querySelectorAll("style"), ...document.querySelectorAll("link[rel=stylesheet]")].forEach(s => {
|
|
|
|
|
|
|
|
const n = s.cloneNode(true) as HTMLStyleElement | HTMLLinkElement;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (s.parentElement?.tagName === "HEAD")
|
|
|
|
|
|
|
|
doc.head.append(n);
|
|
|
|
|
|
|
|
else if (n.id?.startsWith("vencord-") || n.id?.startsWith("vcd-"))
|
|
|
|
|
|
|
|
doc.documentElement.append(n);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
doc.body.append(n);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Common.ReactDOM.render(Common.React.createElement(component, props), doc.body.appendChild(document.createElement("div")));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startAt: StartAt.Init,
|
|
|
|
startAt: StartAt.Init,
|
|
|
|
start() {
|
|
|
|
start() {
|
|
|
|
const shortcuts = this.getShortcuts();
|
|
|
|
const shortcuts = makeShortcuts();
|
|
|
|
window.shortcutList = {};
|
|
|
|
window.shortcutList = {};
|
|
|
|
|
|
|
|
|
|
|
|
for (const [key, val] of Object.entries(shortcuts)) {
|
|
|
|
for (const [key, val] of Object.entries(shortcuts)) {
|
|
|
|
if (val.getter != null) {
|
|
|
|
if ("getter" in val) {
|
|
|
|
Object.defineProperty(window.shortcutList, key, {
|
|
|
|
define(window.shortcutList, key, {
|
|
|
|
get: val.getter,
|
|
|
|
get: () => loadAndCacheShortcut(key, val, true)
|
|
|
|
configurable: true,
|
|
|
|
|
|
|
|
enumerable: true
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(window, key, {
|
|
|
|
define(window, key, {
|
|
|
|
get: () => window.shortcutList[key],
|
|
|
|
get: () => window.shortcutList[key]
|
|
|
|
configurable: true,
|
|
|
|
|
|
|
|
enumerable: true
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
window.shortcutList[key] = val;
|
|
|
|
window.shortcutList[key] = val;
|
|
|
|
window[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() {
|
|
|
|
stop() {
|
|
|
|
delete window.shortcutList;
|
|
|
|
delete window.shortcutList;
|
|
|
|
for (const key in this.getShortcuts()) {
|
|
|
|
for (const key in makeShortcuts()) {
|
|
|
|
delete window[key];
|
|
|
|
delete window[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|