beef up ConsoleShortcuts
This commit is contained in:
parent
a2560ede1c
commit
6869705673
|
@ -62,23 +62,27 @@ export default definePlugin({
|
||||||
}
|
}
|
||||||
|
|
||||||
let fakeRenderWin: WeakRef<Window> | undefined;
|
let fakeRenderWin: WeakRef<Window> | undefined;
|
||||||
|
const find = newFindWrapper(f => f);
|
||||||
return {
|
return {
|
||||||
|
...Vencord.Webpack.Common,
|
||||||
wp: Vencord.Webpack,
|
wp: Vencord.Webpack,
|
||||||
wpc: Webpack.wreq.c,
|
wpc: Webpack.wreq.c,
|
||||||
wreq: Webpack.wreq,
|
wreq: Webpack.wreq,
|
||||||
wpsearch: search,
|
wpsearch: search,
|
||||||
wpex: extract,
|
wpex: extract,
|
||||||
wpexs: (code: string) => Vencord.Webpack.extract(Vencord.Webpack.findModuleId(code)!),
|
wpexs: (code: string) => extract(Webpack.findModuleId(code)!),
|
||||||
find: newFindWrapper(f => f),
|
find,
|
||||||
findAll,
|
findAll,
|
||||||
findByProps: newFindWrapper(filters.byProps),
|
findByProps: newFindWrapper(filters.byProps),
|
||||||
findAllByProps: (...props: string[]) => findAll(filters.byProps(...props)),
|
findAllByProps: (...props: string[]) => findAll(filters.byProps(...props)),
|
||||||
findByCode: newFindWrapper(filters.byCode),
|
findByCode: newFindWrapper(filters.byCode),
|
||||||
findAllByCode: (code: string) => findAll(filters.byCode(code)),
|
findAllByCode: (code: string) => findAll(filters.byCode(code)),
|
||||||
|
findComponentByCode: newFindWrapper(filters.componentByCode),
|
||||||
|
findAllComponentsByCode: (...code: string[]) => findAll(filters.componentByCode(...code)),
|
||||||
|
findExportedComponent: (...props: string[]) => find(...props)[props[0]],
|
||||||
findStore: newFindWrapper(filters.byStoreName),
|
findStore: newFindWrapper(filters.byStoreName),
|
||||||
PluginsApi: Vencord.Plugins,
|
PluginsApi: Vencord.Plugins,
|
||||||
plugins: Vencord.Plugins.plugins,
|
plugins: Vencord.Plugins.plugins,
|
||||||
React,
|
|
||||||
Settings: Vencord.Settings,
|
Settings: Vencord.Settings,
|
||||||
Api: Vencord.Api,
|
Api: Vencord.Api,
|
||||||
reload: () => location.reload(),
|
reload: () => location.reload(),
|
||||||
|
@ -92,7 +96,25 @@ export default definePlugin({
|
||||||
fakeRenderWin = new WeakRef(win);
|
fakeRenderWin = new WeakRef(win);
|
||||||
win.focus();
|
win.focus();
|
||||||
|
|
||||||
ReactDOM.render(React.createElement(component, props), win.document.body);
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ReactDOM.render(React.createElement(component, props), doc.body.appendChild(document.createElement("div")));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
|
@ -52,7 +52,18 @@ export const filters = {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
byStoreName: (name: string): FilterFn => m =>
|
byStoreName: (name: string): FilterFn => m =>
|
||||||
m.constructor?.displayName === name
|
m.constructor?.displayName === name,
|
||||||
|
|
||||||
|
componentByCode: (...code: string[]): FilterFn => {
|
||||||
|
const filter = filters.byCode(...code);
|
||||||
|
return m => {
|
||||||
|
if (filter(m)) return true;
|
||||||
|
if (!m.$$typeof) return false;
|
||||||
|
if (m.type) return filter(m.type); // memos
|
||||||
|
if (m.render) return filter(m.render); // forwardRefs
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const subscriptions = new Map<FilterFn, CallbackFn>();
|
export const subscriptions = new Map<FilterFn, CallbackFn>();
|
||||||
|
@ -397,18 +408,9 @@ export function findStoreLazy(name: string) {
|
||||||
* Finds the component which includes all the given code. Checks for plain components, memos and forwardRefs
|
* Finds the component which includes all the given code. Checks for plain components, memos and forwardRefs
|
||||||
*/
|
*/
|
||||||
export function findComponentByCode(...code: string[]) {
|
export function findComponentByCode(...code: string[]) {
|
||||||
const filter = filters.byCode(...code);
|
const res = find(filters.componentByCode(...code), { isIndirect: true });
|
||||||
const res = find(m => {
|
|
||||||
if (filter(m)) return true;
|
|
||||||
if (!m.$$typeof) return false;
|
|
||||||
if (m.type) return filter(m.type); // memos
|
|
||||||
if (m.render) return filter(m.render); // forwardRefs
|
|
||||||
return false;
|
|
||||||
}, { isIndirect: true });
|
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
handleModuleNotFound("findComponentByCode", ...code);
|
handleModuleNotFound("findComponentByCode", ...code);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue