mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
parent
e2efb727b9
commit
f3f6df229f
5 changed files with 122 additions and 58 deletions
60
lib/frame.js
60
lib/frame.js
|
@ -45,13 +45,13 @@
|
|||
|
||||
let extensionSecret;
|
||||
function computeExtensionSecret(){
|
||||
function hashString(string){
|
||||
return hashing(new Uint16Array(
|
||||
string.split("").map(function(c){
|
||||
return c.charCodeAt(0);
|
||||
})
|
||||
));
|
||||
}
|
||||
function hashString(string){
|
||||
return hashing(new Uint16Array(
|
||||
string.split("").map(function(c){
|
||||
return c.charCodeAt(0);
|
||||
})
|
||||
));
|
||||
}
|
||||
const now = new Date();
|
||||
const lastTenMinutes = Math.floor(now.getMinutes() / 10) * 10;
|
||||
const nextRun = new Date(
|
||||
|
@ -125,7 +125,6 @@
|
|||
return settings.get(...args);
|
||||
}
|
||||
|
||||
|
||||
const interceptedWindows = new WeakMap();
|
||||
function interceptWindow(window){
|
||||
let wrappedTry;
|
||||
|
@ -144,9 +143,15 @@
|
|||
if (!enabled || interceptedWindows.get(wrappedWindow)){
|
||||
return false;
|
||||
}
|
||||
if (wrappedWindow.matchMedia(extensionSecret[0]) === extensionSecret[1]){
|
||||
interceptedWindows.set(wrappedWindow, true);
|
||||
return false;
|
||||
const canvasBlockerData = wrappedWindow.matchMedia(extensionSecret[0]);
|
||||
if (canvasBlockerData.secret === extensionSecret[1]){
|
||||
if (wrappedWindow.top === wrappedWindow){
|
||||
canvasBlockerData.undoIntercept(extension.extensionID);
|
||||
}
|
||||
else {
|
||||
interceptedWindows.set(wrappedWindow, true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
logging.message("intercepting window", window);
|
||||
|
@ -168,17 +173,28 @@
|
|||
|
||||
const matchMediaDescriptor = Object.getOwnPropertyDescriptor(wrappedWindow, "matchMedia");
|
||||
const originalMatchMedia = matchMediaDescriptor.value;
|
||||
matchMediaDescriptor.value = extension.exportFunctionWithName(function matchMedia(query){
|
||||
if (query === extensionSecret[0]){
|
||||
return extensionSecret[1];
|
||||
}
|
||||
else {
|
||||
return arguments.length > 1?
|
||||
originalMatchMedia.call(this, ...arguments):
|
||||
originalMatchMedia.call(this, query);
|
||||
}
|
||||
}, window, originalMatchMedia.name);
|
||||
Object.defineProperty(wrappedWindow, "matchMedia", matchMediaDescriptor);
|
||||
extension.changeProperty(window, "matchMedia", {
|
||||
object: wrappedWindow,
|
||||
name: "matchMedia",
|
||||
type: "value",
|
||||
changed: extension.exportFunctionWithName(function matchMedia(query){
|
||||
if (query === extensionSecret[0]){
|
||||
return {
|
||||
secret: extensionSecret[1],
|
||||
undoIntercept: function(token){
|
||||
if (token === extension.extensionID){
|
||||
extension.revertProperties(window);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
return arguments.length > 1?
|
||||
originalMatchMedia.call(this, ...arguments):
|
||||
originalMatchMedia.call(this, query);
|
||||
}
|
||||
}, window, originalMatchMedia.name)
|
||||
});
|
||||
|
||||
interceptedWindows.set(wrappedWindow, true);
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue