mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-07 20:24:47 +01:00
parent
dacc578e12
commit
b8c6115603
@ -141,23 +141,35 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const proxies = new Map();
|
const proxies = new Map();
|
||||||
const changedToStrings = new WeakMap();
|
const changedWindowsForProxies = new WeakMap();
|
||||||
scope.createProxyFunction = function createProxyFunction(window, original, replacement){
|
function setupWindowForProxies(window){
|
||||||
if (!changedToStrings.get(window)){
|
if (changedWindowsForProxies.get(window)){
|
||||||
const functionPrototype = scope.getWrapped(window).Function.prototype;
|
return;
|
||||||
const originalToString = functionPrototype.toString;
|
|
||||||
changedToStrings.set(window, originalToString);
|
|
||||||
const alteredToString = scope.exportFunctionWithName(function toString(){
|
|
||||||
return proxies.get(this) || originalToString.call(this);
|
|
||||||
}, window, "toString");
|
|
||||||
proxies.set(alteredToString, originalToString.call(originalToString));
|
|
||||||
scope.changeProperty(window, "toString", {
|
|
||||||
object: functionPrototype,
|
|
||||||
name: "toString",
|
|
||||||
type: "value",
|
|
||||||
changed: alteredToString
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
const wrappedWindow = scope.getWrapped(window);
|
||||||
|
|
||||||
|
const functionPrototype = wrappedWindow.Function.prototype;
|
||||||
|
const originalToString = functionPrototype.toString;
|
||||||
|
changedWindowsForProxies.set(window, originalToString);
|
||||||
|
const alteredToString = scope.createProxyFunction(
|
||||||
|
window,
|
||||||
|
originalToString,
|
||||||
|
function toString(){
|
||||||
|
if (proxies.has(this)){
|
||||||
|
return proxies.get(this).string;
|
||||||
|
}
|
||||||
|
return originalToString.call(scope.getWrapped(this));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
scope.changeProperty(window, "toString", {
|
||||||
|
object: functionPrototype,
|
||||||
|
name: "toString",
|
||||||
|
type: "value",
|
||||||
|
changed: alteredToString
|
||||||
|
});
|
||||||
|
}
|
||||||
|
scope.createProxyFunction = function createProxyFunction(window, original, replacement){
|
||||||
|
setupWindowForProxies(window);
|
||||||
const handler = scope.getWrapped(window).Object.create(null);
|
const handler = scope.getWrapped(window).Object.create(null);
|
||||||
handler.apply = scope.exportFunctionWithName(function(target, thisArgs, args){
|
handler.apply = scope.exportFunctionWithName(function(target, thisArgs, args){
|
||||||
try {
|
try {
|
||||||
@ -175,7 +187,13 @@
|
|||||||
}
|
}
|
||||||
}, window, "");
|
}, window, "");
|
||||||
const proxy = new window.Proxy(original, handler);
|
const proxy = new window.Proxy(original, handler);
|
||||||
proxies.set(proxy, changedToStrings.get(window).call(original));
|
const proxyData = {
|
||||||
|
original: original,
|
||||||
|
wrappedOriginal: scope.getWrapped(original),
|
||||||
|
string: changedWindowsForProxies.get(window).call(original),
|
||||||
|
};
|
||||||
|
proxies.set(proxy, proxyData);
|
||||||
|
proxies.set(scope.getWrapped(proxy), proxyData);
|
||||||
return scope.getWrapped(proxy);
|
return scope.getWrapped(proxy);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user