mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-06 19:54:42 +01:00
parent
dacc578e12
commit
b8c6115603
@ -141,23 +141,35 @@
|
||||
};
|
||||
|
||||
const proxies = new Map();
|
||||
const changedToStrings = new WeakMap();
|
||||
scope.createProxyFunction = function createProxyFunction(window, original, replacement){
|
||||
if (!changedToStrings.get(window)){
|
||||
const functionPrototype = scope.getWrapped(window).Function.prototype;
|
||||
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 changedWindowsForProxies = new WeakMap();
|
||||
function setupWindowForProxies(window){
|
||||
if (changedWindowsForProxies.get(window)){
|
||||
return;
|
||||
}
|
||||
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);
|
||||
handler.apply = scope.exportFunctionWithName(function(target, thisArgs, args){
|
||||
try {
|
||||
@ -175,7 +187,13 @@
|
||||
}
|
||||
}, window, "");
|
||||
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);
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user