mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-14 04:20:00 -04:00
Heroku/Repl.it fix?
This commit is contained in:
parent
73cdcb3186
commit
2cbcaebca8
44 changed files with 1097 additions and 35748 deletions
|
@ -1,16 +1,8 @@
|
|||
const createAttributeRewriter = require('./attributes');
|
||||
const createDocumentRewriter = require('./document');
|
||||
const createDomRewriter = require('./dom');
|
||||
const createFunctionRewriter = require('./function');
|
||||
const createHistoryRewriter = require('./history');
|
||||
const createHttpRewriter = require('./http');
|
||||
const createIframeRewriter = require('./iframe');
|
||||
const createInstrumentation = require('./instrumentation');
|
||||
const { createLocation } = require('./location');
|
||||
const createMessageRewriter = require('./message');
|
||||
const createLocation = require('./location');
|
||||
const createWorkerRewriter = require('./worker');
|
||||
const createStyleRewriter = require('./style');
|
||||
const utils = require('./utils');
|
||||
const defaultConfig = {
|
||||
prefix: '/service/',
|
||||
codec: 'plain',
|
||||
|
@ -26,78 +18,178 @@ class Corrosion extends require('../rewrite') {
|
|||
constructor(config = defaultConfig) {
|
||||
super(Object.assign(defaultConfig, config));
|
||||
const corrosion = this;
|
||||
this.utils = utils;
|
||||
this.serviceWorker = this.config.serviceWorker;
|
||||
this.window = config.window;
|
||||
this.Window = this.serviceWorker ? null : this.window.Window;
|
||||
this.Document = this.Window ? this.window.Document : null;
|
||||
this.docProto = (this.Document || {}).prototype;
|
||||
this.origin = this.window.location.origin;
|
||||
if (!this.config.window) throw 'Corrosion Error: No window was given.';
|
||||
this.serviceWorker = this.config.serviceWorker || false;
|
||||
this.window = this.config.window;
|
||||
this.document = this.serviceWorker ? this.window.document : {};
|
||||
this._url = new URL((this.config.url || this.url.unwrap(this.window.location.href, { origin: this.window.location.origin, })));
|
||||
this.proxyToOriginalMp = new Map();
|
||||
this.location = createLocation(this, this._url);
|
||||
this.originalXhr = this.window.XMLHttpRequest;
|
||||
this.meta = {
|
||||
origin: this.origin,
|
||||
origin: this.window.location.origin,
|
||||
get base() {
|
||||
if (corrosion.serviceWorker) return corrosion._url;
|
||||
return corrosion.window.document.baseURI != corrosion.location.href ? new URL(corrosion.window.document.baseURI) : corrosion._url;
|
||||
},
|
||||
url: this._url,
|
||||
};
|
||||
this.originalFn = {};
|
||||
this.originalAccessors = {};
|
||||
this.rewriteFunction = createFunctionRewriter(this);
|
||||
this.location = createLocation(this, this._url);
|
||||
this.rewriteHttp = createHttpRewriter(this);
|
||||
this.rewriteDocument = createDocumentRewriter(this);
|
||||
this.rewriteDom = createDomRewriter(this);
|
||||
this.rewriteAttributes = createAttributeRewriter(this);
|
||||
this.rewriteIframes = createIframeRewriter(this);
|
||||
this.rewriteMessage = createMessageRewriter(this);
|
||||
this.rewriteHistory = createHistoryRewriter(this);
|
||||
this.rewriteWorker = createWorkerRewriter(this);
|
||||
this.rewriteStyle = createStyleRewriter(this);
|
||||
this.instrumentation = createInstrumentation(this);
|
||||
this.windowEvents = [];
|
||||
this.window.__get$ = this.instrumentation.get;
|
||||
this.window.__get$Parent = this.instrumentation.getParent;
|
||||
this.window.__get$Top = this.instrumentation.getTop;
|
||||
this.window.__get$Loc = this.instrumentation.getLoc;
|
||||
this.window.__set$ = this.instrumentation.set;
|
||||
this.window.__set$Loc = this.instrumentation.setLoc;
|
||||
this.window.__processScript = this.processScript.bind(this);
|
||||
this.window.__processStyle = this.processStyle.bind(this);
|
||||
this.window.__processHtml = this.processHtml.bind(this);
|
||||
this.window.__call$ = this.call.bind(this);
|
||||
};
|
||||
processStyle(val, context) {
|
||||
return this.css.process(val, { meta: this.meta, context });
|
||||
if (!this.serviceWorker && this.window.document.currentScript) this.window.document.currentScript.remove();
|
||||
};
|
||||
processScript(val) {
|
||||
return this.js.process(val, this.meta.url.href);
|
||||
get parent() {
|
||||
if (this.serviceWorker) return false;
|
||||
try {
|
||||
return this.window.parent.$corrosion ? this.window.parent : this.window;
|
||||
} catch(e) {
|
||||
return this.window;
|
||||
};
|
||||
};
|
||||
processHtml(val, document = false) {
|
||||
if (!val) return val;
|
||||
return this.html.process(val, { document, meta: this.meta, });
|
||||
};
|
||||
call(obj, method, args) {
|
||||
return obj[method](...args);
|
||||
};
|
||||
proxyToOriginal(input) {
|
||||
return this.proxyToOriginalMp.get(input) || input;
|
||||
get top() {
|
||||
if (this.serviceWorker) return false;
|
||||
try {
|
||||
return this.window.top.$corrosion ? this.window.top : this.parent;
|
||||
} catch(e) {
|
||||
return this.parent;
|
||||
};
|
||||
};
|
||||
init() {
|
||||
this.rewriteFunction();
|
||||
this.rewriteHttp();
|
||||
this.rewriteDocument();
|
||||
this.rewriteDom();
|
||||
this.rewriteAttributes();
|
||||
this.rewriteIframes();
|
||||
this.rewriteMessage();
|
||||
this.rewriteHistory();
|
||||
this.rewriteWorker();
|
||||
this.rewriteStyle();
|
||||
console.log('Corrosion initiated.');
|
||||
this.window.Location = createLocation.Location;
|
||||
this.window.$corrosionGet$ = this.get$.bind(this);
|
||||
this.window.$corrosionSet$ = this.set$.bind(this);
|
||||
this.window.$corrosionGet$m = this.get$m.bind(this);
|
||||
this.window.$corrosionSet$m = this.set$m.bind(this);
|
||||
this.window.$corrosionCall$m = this.call$m.bind(this);
|
||||
};
|
||||
get$m(obj, key) {
|
||||
if (!this.serviceWorker && this.window != this.window.parent && obj == this.window.parent) {
|
||||
return this.parent.$corrosion.get$m(this.parent, key);
|
||||
};
|
||||
if (!this.serviceWorker && this.window != this.window.top && obj == this.window.top) {
|
||||
return this.top.$corrosion.get$m(this.top, key);
|
||||
};
|
||||
if (obj == this.window && key == 'location' || !this.serviceWorker && obj == this.window.document && key == 'location') return this.location;
|
||||
if (!this.serviceWorker && obj == this.window && key == 'parent' && this.window != this.window.parent) return this.parent;
|
||||
if (!this.serviceWorker && obj == this.window && key == 'top' && this.window != this.window.top) return this.top;
|
||||
return obj[key];
|
||||
};
|
||||
set$m(obj, key, val, operator) {
|
||||
if (!this.serviceWorker && this.window != this.window.parent && obj == this.window.parent) {
|
||||
return this.parent.$corrosion.set$m(this.parent, key, val, operator);
|
||||
};
|
||||
if (!this.serviceWorker && this.window != this.window.top && obj == this.window.top) {
|
||||
return this.top.$corrosion.set$m(this.top, key, val, operator);
|
||||
};
|
||||
if (obj == this.window && key == 'location' || !this.serviceWorker && obj == this.window.document && key == 'location') obj = this;
|
||||
switch(operator) {
|
||||
case '+=':
|
||||
return obj[key] += val;
|
||||
case '-=':
|
||||
return obj[key] -= val;
|
||||
case '*=':
|
||||
return obj[key] *= val;
|
||||
case '/=':
|
||||
return obj[key] /= val;
|
||||
case '%=':
|
||||
return obj[key] %= val;
|
||||
case '**=':
|
||||
return obj[key] **= val;
|
||||
case '<<=':
|
||||
return obj[key] <<= val;
|
||||
case '>>=':
|
||||
return obj[key] >>= val;
|
||||
case '>>>=':
|
||||
return obj[key] >>>= val;
|
||||
case '&=':
|
||||
return obj[key] &= val;
|
||||
case '^=':
|
||||
return obj[key] ^= val;
|
||||
case '|=':
|
||||
return obj[key] |= val;
|
||||
case '&&=':
|
||||
return obj[key] &&= val;
|
||||
case '||=':
|
||||
return obj[key] ||= val;
|
||||
case '??=':
|
||||
return obj[key] ??= val;
|
||||
case '++':
|
||||
return obj[key]++;
|
||||
case '--':
|
||||
return obj[key]--;
|
||||
case '=':
|
||||
default:
|
||||
return obj[key] = val;
|
||||
};
|
||||
};
|
||||
call$m(obj, key, args) {
|
||||
if (!this.serviceWorker && this.window != this.window.parent && obj == this.window.parent) {
|
||||
return this.parent.$corrosion.call$m(this.parent, key, args);
|
||||
};
|
||||
if (!this.serviceWorker && this.window != this.window.top && obj == this.window.top) {
|
||||
return this.top.$corrosion.call$m(this.top, key, args);
|
||||
};
|
||||
return obj[key](...args);
|
||||
};
|
||||
get$(obj) {
|
||||
if (obj == this.window.location) return this.location;
|
||||
if (!this.serviceWorker && obj == this.window.parent) return this.parent;
|
||||
if (!this.serviceWorker && obj == this.window.top) return this.top;
|
||||
return obj;
|
||||
};
|
||||
set$(obj, val, operator) {
|
||||
if (obj == this.window.location) return this.set$(this.location, val, operator);
|
||||
if (!this.serviceWorker && this.window != this.window.parent && obj == this.window.parent) return this.parent.set$(this.parent, val, operator);
|
||||
if (!this.serviceWorker && this.window != this.window.top && obj == this.window.top) return this.top.set$(this.top, val, operator);
|
||||
switch(operator) {
|
||||
case '+=':
|
||||
return obj += val;
|
||||
case '-=':
|
||||
return obj -= val;
|
||||
case '*=':
|
||||
return obj *= val;
|
||||
case '/=':
|
||||
return obj /= val;
|
||||
case '%=':
|
||||
return obj %= val;
|
||||
case '**=':
|
||||
return obj **= val;
|
||||
case '<<=':
|
||||
return obj <<= val;
|
||||
case '>>=':
|
||||
return obj >>= val;
|
||||
case '>>>=':
|
||||
return obj >>>= val;
|
||||
case '&=':
|
||||
return obj &= val;
|
||||
case '^=':
|
||||
return obj ^= val;
|
||||
case '|=':
|
||||
return obj |= val;
|
||||
case '&&=':
|
||||
return obj &&= val;
|
||||
case '||=':
|
||||
return obj ||= val;
|
||||
case '??=':
|
||||
return obj ??= val;
|
||||
case '++':
|
||||
return obj++;
|
||||
case '--':
|
||||
return obj--;
|
||||
case '=':
|
||||
default:
|
||||
return obj = val;
|
||||
};
|
||||
};
|
||||
updateLocation() {
|
||||
this._url = new URL(this.url.unwrap(this.window.location.href, this.meta));
|
||||
this.location = createLocation(this, this._url);
|
||||
};
|
||||
};
|
||||
|
||||
globalThis.Corrosion = Corrosion;
|
Loading…
Add table
Add a link
Reference in a new issue