mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 12:36:37 +02:00
Added black list and ask.
This commit is contained in:
parent
0ab4f1b7d3
commit
ebe1d66ad5
4 changed files with 113 additions and 15 deletions
|
@ -1,12 +1,46 @@
|
|||
var getContext = unsafeWindow.HTMLCanvasElement.prototype.getContext
|
||||
var getContext = unsafeWindow.HTMLCanvasElement.prototype.getContext;
|
||||
var askFunctionName = Math.random().toString(16);
|
||||
|
||||
function block(){
|
||||
// consoe.log("block");
|
||||
delete unsafeWindow.HTMLCanvasElement.prototype[askFunctionName];
|
||||
unsafeWindow.HTMLCanvasElement.prototype.getContext = null;
|
||||
}
|
||||
function ask(){
|
||||
// console.log("ask");
|
||||
|
||||
Object.defineProperty(
|
||||
unsafeWindow.HTMLCanvasElement.prototype,
|
||||
askFunctionName,
|
||||
{
|
||||
value: getContext,
|
||||
enumerabe: false
|
||||
}
|
||||
);
|
||||
unsafeWindow.HTMLCanvasElement.prototype.getContext = new unsafeWindow.Function(function(){
|
||||
var oldBorder = this.style.border;
|
||||
this.style.border = "2px dashed red";
|
||||
var confirmText =
|
||||
this.parentNode?
|
||||
"Do you want to allow the red bordered <canvas>?":
|
||||
"Do you want to allow an invisibe <canvas>?";
|
||||
var allow = confirm(confirmText);
|
||||
this.style.border = oldBorder;
|
||||
if (allow){
|
||||
return this["askFunctionName"].apply(this, arguments);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}.toString().replace(/^function\s*\(\)\s*\{|\}\s*$/g, "").replace("askFunctionName", askFunctionName));
|
||||
}
|
||||
function unblock(){
|
||||
// console.log("unblock");
|
||||
unsafeWindow.HTMLCanvasElement.prototype.getContext = getContext;
|
||||
}
|
||||
|
||||
ask();
|
||||
self.port.on("block", block);
|
||||
self.port.on("ask", ask);
|
||||
self.port.on("unblock", unblock);
|
||||
self.port.on("detach", unblock);
|
Loading…
Add table
Add a link
Reference in a new issue