Move from spitroast to internalized demonpatcher

No more of that christianized Cumcord code
typescript
Drake 2 years ago
parent e2f45acd3e
commit 3848a02879

2
dist/build.js vendored

File diff suppressed because one or more lines are too long

@ -1,5 +1,58 @@
//NOTE: this isn't even a wrapper around spitroast, it's more a convienence for importing patcher internally
import * as spitroast from "spitroast";
function wackyPatch(parentObj, name, patches) {
if (typeof parentObj === "string") {
//assume parentObj and name are switched around (for backcompat/convienence)
const tmp = parentObj
parentObj = name
name = tmp
}
const injId = Symbol()
const before = patches["before"];
const instead = patches["instead"];
const after = patches["after"];
const handler = {
apply: (target, thisArg, [ctx, args]) => {
if (before !== undefined) before.apply(ctx, [args]);
const res = (patches["instead"] !== undefined) ? instead.apply(ctx, [args, target.bind(ctx)]) : target.apply(ctx, args)
if (after === undefined) return res
return after.apply(ctx, [args, res]);
}
};
const prox = new Proxy(parentObj[name], handler);
const orig = parentObj[name];
parentObj[name] = function() {
return prox(this, arguments);
};
const unpatch = () => {
parentObj[name] = orig;
}
parentObj[injId] = {
name: name,
orig: orig,
unpatch: unpatch
};
return unpatch;
}
export * from "spitroast";
export default spitroast;
function before(parentObj, name, func) {
return wackyPatch(parentObj, name, {before: func})
}
function instead(parentObj, name, func) {
return wackyPatch(parentObj, name, {instead: func})
}
function after(parentObj, name, func) {
return wackyPatch(parentObj, name, {after: func})
}
export {
instead,
before,
after
}
export default {
instead,
before,
after
}

@ -55,8 +55,8 @@ function init() {
});
if (!!window.webpackChunkdiscord_app) {
after(
"getPredicateSections",
SettingsView.prototype,
"getPredicateSections",
(args, sections) => {
sections.unshift(
{

Loading…
Cancel
Save