Skip to content

Instantly share code, notes, and snippets.

@ArjixWasTaken
Last active June 15, 2025 16:55
Show Gist options
  • Save ArjixWasTaken/a54b686a5a94371a4945a102ee74de7d to your computer and use it in GitHub Desktop.
Save ArjixWasTaken/a54b686a5a94371a4945a102ee74de7d to your computer and use it in GitHub Desktop.
Userscript that patches webpack modules!

Most of the code was stolen from Vendicated/Vencord.

// ==UserScript==
// @name webpack-patcher
// @namespace http://tampermonkey.net/
// @version 2025-05-22
// @description Patches webpack modules
// @author Vendicated, Arjix
// @match https://www.cineby.app/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=cineby.app
// @grant none
// @run-at document-start
// ==/UserScript==
const patches = [
{
find: /detectors:\[(\d,?)+\]/, replacement: [
{ match: /detectors:\[(\d,?)+\]/, replace: "detectors:[]" },
{ match: "clearLog:!0,", replace: "clearLog:false," }
]
}
];
/// ======== Do not touch the below! ========
let wreq;
const values = o => (Array.isArray(o) ? o : Object.values(o));
function extractPrivateCache(wreq) {
let cache = null;
const sym = Symbol("wpgrabber.extract");
Object.defineProperty(Object.prototype, sym, {
get() {
cache = this;
return { exports: {} };
},
set() { },
configurable: true,
})
wreq(sym);
delete Object.prototype[sym];
if (cache) delete cache[sym];
return cache;
}
Object.defineProperty(Function.prototype, "m", {
set(v) {
const source = this.toString();
if (
source.includes("exports") &&
(source.includes("false") || source.includes("!1")) &&
!(Array.isArray(v) && v?.some(m => m.toString().includes("CHROME_WEBSTORE_EXTENSION_ID"))) // react devtools
) {
Object.defineProperty(this, "m", {
value: v,
configurable: true,
enumerable: true,
writable: true
});
patchFactories(v);
delete Function.prototype.m;
this.m = v;
console.log(
"%c%s%c %s %c%s",
"background-color: #babbf1; color: black; border-radius: 4px; padding: 2px 4px; font-weight: bold;",
"WebpackGrabber",
"",
"Found webpack_require! Check out",
"font-weight: 600",
"window.WEBPACK_GRABBER"
);
} else {
// huh not webpack_require
Object.defineProperty(this, "m", {
value: v,
configurable: true,
writable: true,
enumerable: true
});
}
},
configurable: true,
});
function patchPush(webpackGlobal) {
function handlePush(chunk) {
try {
patchFactories(chunk[1]);
} catch (err) {
console.error("Error in handlePush", err);
}
return handlePush.$$vencordOriginal.call(webpackGlobal, chunk);
}
handlePush.$$vencordOriginal = webpackGlobal.push;
handlePush.toString = handlePush.$$vencordOriginal.toString.bind(handlePush.$$vencordOriginal);
handlePush.bind = (...args) => handlePush.$$vencordOriginal.bind(...args);
Object.defineProperty(webpackGlobal, "push", {
configurable: true,
get: () => handlePush,
set(v) {
handlePush.$$vencordOriginal = v;
}
});
}
function patchFactories(factories) {
for (const id in factories) {
let mod = factories[id];
const originalMod = mod;
const factory = factories[id] = function (module, exports, require) {
try {
mod(module, exports, require);
} catch (e) {
if (mod === originalMod) throw e;
console.error("Error in patched module", e);
return void originalMod(module, exports, require);
}
exports = module.exports;
if (!exports) return;
}
factory.toString = originalMod.toString.bind(originalMod);
factory.original = originalMod;
let code = "0," + mod.toString();
for (let i=0; i<patches.length; i++) {
const patch = patches[i];
const moduleMatches = typeof patch.find === "string"
? code.includes(patch.find)
: patch.find.test(code);
if (!moduleMatches) continue;
const previousMod = mod;
const previousCode = code;
for (const replacement of patch.replacement) {
const lastMod = mod;
const lastCode = code;
try {
code = code.replace(replacement.match, replacement.replace);
mod = (0, eval)(code);
} catch (e) {
console.error("patch failed", code)
code = lastCode;
mod = lastMod;
}
}
patches.splice(i--, 1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment