mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-12 19:40:02 -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,21 +1,3 @@
|
|||
const { wrapFunction } = require("./utils");
|
||||
const locationProperties = [
|
||||
'hash',
|
||||
'host',
|
||||
'hostname',
|
||||
'href',
|
||||
'pathname',
|
||||
'port',
|
||||
'protocol',
|
||||
'search',
|
||||
'origin',
|
||||
];
|
||||
const locationMethods = [
|
||||
'replace',
|
||||
'reload',
|
||||
'assign',
|
||||
];
|
||||
|
||||
class Location {
|
||||
get [Symbol.toPrimitive]() {
|
||||
return () => this.href;
|
||||
|
@ -23,12 +5,24 @@ class Location {
|
|||
};
|
||||
|
||||
function createLocation(ctx, url) {
|
||||
const _url = new URL(url);
|
||||
const _location = new Location();
|
||||
for (const property of locationProperties) {
|
||||
const _url = new URL(url);
|
||||
[
|
||||
'hash',
|
||||
'host',
|
||||
'hostname',
|
||||
'href',
|
||||
'pathname',
|
||||
'port',
|
||||
'protocol',
|
||||
'search',
|
||||
'origin',
|
||||
].forEach(property => {
|
||||
Object.defineProperty(_location, property, {
|
||||
get: () => _url[property],
|
||||
set: val => {
|
||||
get() {
|
||||
return _url[property];
|
||||
},
|
||||
set(val) {
|
||||
if (ctx.serviceWorker || property == 'origin') return;
|
||||
if (property == 'href') {
|
||||
return ctx.window.location.href = ctx.url.wrap(new URL(val, _url).href);
|
||||
|
@ -37,18 +31,26 @@ function createLocation(ctx, url) {
|
|||
return ctx.window.location.href = ctx.url.wrap(_url);
|
||||
},
|
||||
});
|
||||
};
|
||||
if (!ctx.serviceWorker) {
|
||||
for (const method of locationMethods) {
|
||||
_location[method] = wrapFunction(ctx.window.location[method], (target, that, args) => {
|
||||
});
|
||||
if (!ctx.serviceWorker) [
|
||||
'assign',
|
||||
'replace',
|
||||
'reload',
|
||||
].forEach(method => {
|
||||
_location[method] = new Proxy(ctx.window.location[method], {
|
||||
apply(target, that, args) {
|
||||
if (args[0]) args[0] = ctx.url.wrap(args[0], ctx.meta);
|
||||
return target.apply(ctx.window.location, args);
|
||||
});
|
||||
};
|
||||
};
|
||||
_location.toString = wrapFunction(_url.toString, target => target.call(_url));
|
||||
ctx.proxyToOriginalMp.set(_location, ctx.window.location);
|
||||
return Reflect.apply(target.bind(ctx.window.location), that, args);
|
||||
},
|
||||
});
|
||||
});
|
||||
_location.toString = new Proxy(_url.toString, {
|
||||
apply(target, that, args) {
|
||||
return Reflect.apply(target.bind(_url), that, args);
|
||||
},
|
||||
});
|
||||
return _location;
|
||||
};
|
||||
|
||||
module.exports = { createLocation, Location, locationMethods, locationProperties };
|
||||
createLocation.Location = Location;
|
||||
module.exports = createLocation;
|
Loading…
Add table
Add a link
Reference in a new issue