mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 12:36:37 +02:00
Changed settings
This commit is contained in:
parent
430a9226dc
commit
40d059311a
5 changed files with 292 additions and 269 deletions
188
data/inject.js
188
data/inject.js
|
@ -1,40 +1,82 @@
|
|||
var getContext = unsafeWindow.HTMLCanvasElement.prototype.getContext;
|
||||
var askFunctionName = Math.random().toString(16);
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
var getContext = unsafeWindow.HTMLCanvasElement.prototype.getContext;
|
||||
var askFunctionName = Math.random().toString(16);
|
||||
|
||||
function checkPDF(blocking){
|
||||
if (unsafeWindow.document.contentType.match(/\/pdf$/i)){
|
||||
self.port.emit("isPDF", blocking);
|
||||
return true;
|
||||
function checkPDF(blocking){
|
||||
if (document.contentType.match(/\/pdf$/i)){
|
||||
self.port.emit("isPDF", blocking);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function block(force){
|
||||
if (force || !checkPDF("block")){
|
||||
// consoe.log("block");
|
||||
delete unsafeWindow.HTMLCanvasElement.prototype[askFunctionName];
|
||||
unsafeWindow.HTMLCanvasElement.prototype.getContext = null;
|
||||
function block(force){
|
||||
if (force || !checkPDF("block")){
|
||||
// consoe.log("block");
|
||||
delete unsafeWindow.HTMLCanvasElement.prototype[askFunctionName];
|
||||
unsafeWindow.HTMLCanvasElement.prototype.getContext = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ask(force){
|
||||
if (force || !checkPDF("ask")){
|
||||
// console.log("ask");
|
||||
|
||||
Object.defineProperty(
|
||||
unsafeWindow.HTMLCanvasElement.prototype,
|
||||
askFunctionName,
|
||||
{
|
||||
value: getContext,
|
||||
enumerabe: false
|
||||
}
|
||||
);
|
||||
unsafeWindow.HTMLCanvasElement.prototype.getContext = new unsafeWindow.Function(
|
||||
function(){
|
||||
if (this.parentNode){
|
||||
function askVisible(force){
|
||||
if (force || !checkPDF("askVisible")){
|
||||
|
||||
Object.defineProperty(
|
||||
unsafeWindow.HTMLCanvasElement.prototype,
|
||||
askFunctionName,
|
||||
{
|
||||
value: getContext,
|
||||
enumerabe: false
|
||||
}
|
||||
);
|
||||
unsafeWindow.HTMLCanvasElement.prototype.getContext = new unsafeWindow.Function(
|
||||
function(){
|
||||
if (this.parentNode){
|
||||
var oldBorder = this.style.border;
|
||||
this.style.border = "2px dashed red";
|
||||
var confirmText = "askForPermission";
|
||||
var allow = confirm(confirmText);
|
||||
this.style.border = oldBorder;
|
||||
if (allow){
|
||||
this.getContext = this["askFunctionName"];
|
||||
return this["askFunctionName"].apply(this, arguments);
|
||||
}
|
||||
else {
|
||||
this.getContext = null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}.toString()
|
||||
.replace(/^function\s*\(\)\s*\{|\}\s*$/g, "")
|
||||
.replace(/askFunctionName/g, askFunctionName)
|
||||
.replace(/askForPermission/g, _("askForPermission"))
|
||||
);
|
||||
}
|
||||
}
|
||||
function askInvisible(force){
|
||||
if (force || !checkPDF("askInvisible")){
|
||||
|
||||
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 = "askForPermission";
|
||||
var confirmText =
|
||||
this.parentNode?
|
||||
"askForPermission":
|
||||
"askForInvisiblePermission";
|
||||
var allow = confirm(confirmText);
|
||||
this.style.border = oldBorder;
|
||||
if (allow){
|
||||
|
@ -45,70 +87,30 @@ function ask(force){
|
|||
this.getContext = null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}.toString()
|
||||
.replace(/^function\s*\(\)\s*\{|\}\s*$/g, "")
|
||||
.replace(/askFunctionName/g, askFunctionName)
|
||||
.replace(/askForPermission/g, _("askForPermission"))
|
||||
);
|
||||
}.toString()
|
||||
.replace(/^function\s*\(\)\s*\{|\}\s*$/g, "")
|
||||
.replace(/askFunctionName/g, askFunctionName)
|
||||
.replace(/askForPermission/g, _("askForPermission"))
|
||||
.replace(/askForInvisiblePermission/g, _("askForInvisiblePermission"))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
function askInvisible(force){
|
||||
if (force || !checkPDF("askInvisible")){
|
||||
// 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?
|
||||
"askForPermission":
|
||||
"askForInvisiblePermission";
|
||||
var allow = confirm(confirmText);
|
||||
this.style.border = oldBorder;
|
||||
if (allow){
|
||||
this.getContext = this["askFunctionName"];
|
||||
return this["askFunctionName"].apply(this, arguments);
|
||||
}
|
||||
else {
|
||||
this.getContext = null;
|
||||
return null;
|
||||
}
|
||||
}.toString()
|
||||
.replace(/^function\s*\(\)\s*\{|\}\s*$/g, "")
|
||||
.replace(/askFunctionName/g, askFunctionName)
|
||||
.replace(/askForPermission/g, _("askForPermission"))
|
||||
.replace(/askForInvisiblePermission/g, _("askForInvisiblePermission"))
|
||||
);
|
||||
function unblock(){
|
||||
// console.log("unblock");
|
||||
unsafeWindow.HTMLCanvasElement.prototype.getContext = getContext;
|
||||
}
|
||||
}
|
||||
function unblock(){
|
||||
// console.log("unblock");
|
||||
unsafeWindow.HTMLCanvasElement.prototype.getContext = getContext;
|
||||
}
|
||||
|
||||
var _ = function(name){
|
||||
return _[name] || name;
|
||||
}
|
||||
self.port.on("setTranslation", function(name, translation){
|
||||
_[name] = translation;
|
||||
});
|
||||
var _ = function(name){
|
||||
return _[name] || name;
|
||||
}
|
||||
self.port.on("setTranslation", function(name, translation){
|
||||
_[name] = translation;
|
||||
});
|
||||
|
||||
block();
|
||||
self.port.on("block", block);
|
||||
self.port.on("ask", ask);
|
||||
self.port.on("askInvisible", askInvisible);
|
||||
self.port.on("unblock", unblock);
|
||||
self.port.on("detach", unblock);
|
||||
block();
|
||||
self.port.on("block", block);
|
||||
self.port.on("askVisible", askVisible);
|
||||
self.port.on("askInvisible", askInvisible);
|
||||
self.port.on("unblock", unblock);
|
||||
self.port.on("detach", unblock);
|
||||
}());
|
Loading…
Add table
Add a link
Reference in a new issue