mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-12 11:30:01 -04:00
45 lines
No EOL
1.4 KiB
JavaScript
45 lines
No EOL
1.4 KiB
JavaScript
const { overrideAccessors } = require("./utils");
|
|
|
|
function createIframeRewriter(ctx) {
|
|
if (ctx.serviceWorker) return () => null;
|
|
const {
|
|
HTMLIFrameElement
|
|
} = ctx.window;
|
|
function rewriteContentDocument() {
|
|
overrideAccessors(HTMLIFrameElement.prototype, 'contentDocument', {
|
|
getter: (target, that) => {
|
|
const doc = target.call(that);
|
|
try {
|
|
if (!doc.defaultView.$corrosion) initCorrosion(doc.defaultView);
|
|
return doc;
|
|
} catch(e) {
|
|
return doc;
|
|
};
|
|
},
|
|
});
|
|
};
|
|
function rewriteContentWindow() {
|
|
overrideAccessors(HTMLIFrameElement.prototype, 'contentWindow', {
|
|
getter: (target, that) => {
|
|
const win = target.call(that);
|
|
try {
|
|
if (!win.$corrosion) initCorrosion(win);
|
|
return win;
|
|
} catch(e) {
|
|
return win;
|
|
};
|
|
},
|
|
});
|
|
};
|
|
function initCorrosion(win) {
|
|
win.$corrosion = new ctx.constructor({ ...ctx.config, window: win, });
|
|
win.$corrosion.init();
|
|
win.$corrosion.meta = ctx.meta;
|
|
};
|
|
return function rewriteIframe() {
|
|
rewriteContentWindow();
|
|
rewriteContentDocument();
|
|
};
|
|
};
|
|
|
|
module.exports = createIframeRewriter; |