mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-13 03:50:02 -04:00
Updated a few more things
This commit is contained in:
parent
c827e9f7e1
commit
73cdcb3186
47 changed files with 35805 additions and 1102 deletions
|
@ -1,26 +1,30 @@
|
|||
const { overrideFunction } = require("./utils");
|
||||
|
||||
function createHistoryRewriter(ctx) {
|
||||
if (ctx.serviceWorker) return () => null;
|
||||
if (ctx.window.History && ctx.window.History.prototype) {
|
||||
ctx.originalFn.historyPushstate = ctx.window.History.prototype.pushState;
|
||||
ctx.originalFn.historyReplacestate = ctx.window.History.prototype.replaceState;
|
||||
};
|
||||
function rewritePushReplaceState() {
|
||||
const handler = (target, that, args) => {
|
||||
if (args[2]) {
|
||||
/*if (new URL(args[2], ctx.meta.base).origin != ctx.location.origin) {
|
||||
args[2] = '';
|
||||
} else {*/
|
||||
args[2] = ctx.url.wrap(args[2], ctx.meta);
|
||||
//};
|
||||
};
|
||||
return target.apply(that, args);
|
||||
}
|
||||
if (ctx.originalFn.historyPushstate) overrideFunction(ctx.window.History.prototype, 'pushState', handler);
|
||||
if (ctx.originalFn.historyReplacestate) overrideFunction(ctx.window.History.prototype, 'replaceState', handler);
|
||||
return true;
|
||||
};
|
||||
return function rewriteHistory() {
|
||||
if (ctx.serviceWorker) return;
|
||||
if (ctx.window.History.prototype.pushState) {
|
||||
ctx.window.History.prototype.pushState = new Proxy(ctx.window.History.prototype.pushState, {
|
||||
apply: (target, that, args) => {
|
||||
if (args[2]) args[2] = ctx.url.wrap(args[2], ctx.meta);
|
||||
const ret = Reflect.apply(target, that, args);
|
||||
ctx.updateLocation();
|
||||
return ret;
|
||||
},
|
||||
});
|
||||
};
|
||||
if (ctx.window.History.prototype.replaceState) {
|
||||
ctx.window.History.prototype.replaceState = new Proxy(ctx.window.History.prototype.replaceState, {
|
||||
apply: (target, that, args) => {
|
||||
if (args[2]) args[2] = ctx.url.wrap(args[2], ctx.meta);
|
||||
const ret = Reflect.apply(target, that, args);
|
||||
ctx.updateLocation();
|
||||
return ret;
|
||||
},
|
||||
});
|
||||
};
|
||||
rewritePushReplaceState();
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = createHistoryRewriter;
|
Loading…
Add table
Add a link
Reference in a new issue