mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-11-12 08:08:52 +01:00
Added different answer tracking for visible and invisible canvas
This commit is contained in:
commit
3403bcaf95
Binary file not shown.
@ -15,8 +15,8 @@
|
|||||||
},
|
},
|
||||||
askStatus: {
|
askStatus: {
|
||||||
askOnce: false,
|
askOnce: false,
|
||||||
alreadyAsked: false,
|
alreadyAsked: {},
|
||||||
answer: null
|
answer: {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
readAPI: {
|
readAPI: {
|
||||||
@ -28,8 +28,8 @@
|
|||||||
},
|
},
|
||||||
askStatus: {
|
askStatus: {
|
||||||
askOnce: false,
|
askOnce: false,
|
||||||
alreadyAsked: false,
|
alreadyAsked: {},
|
||||||
answer: null
|
answer: {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -48,7 +48,7 @@
|
|||||||
function canvasAppearance(context){
|
function canvasAppearance(context){
|
||||||
var oldBorder = false;
|
var oldBorder = false;
|
||||||
var canvas = false;
|
var canvas = false;
|
||||||
var visible = false;
|
var inDOM = null;
|
||||||
if (context){
|
if (context){
|
||||||
if (context.nodeName === "CANVAS"){
|
if (context.nodeName === "CANVAS"){
|
||||||
canvas = context;
|
canvas = context;
|
||||||
@ -63,17 +63,28 @@
|
|||||||
if (canvas){
|
if (canvas){
|
||||||
oldBorder = canvas.style.border;
|
oldBorder = canvas.style.border;
|
||||||
canvas.style.border = "2px solid red";
|
canvas.style.border = "2px solid red";
|
||||||
if (canvas.ownerDocument.contains(canvas)){
|
inDOM = canvas.ownerDocument.contains(canvas);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
canvas: canvas,
|
||||||
|
askCategory: canvas? (inDOM? "visible": "invisible"): "nocanvas",
|
||||||
|
get text(){
|
||||||
|
var text = canvas? (this.visible? "visible": "invisible"): "nocanvas";
|
||||||
|
Object.defineProperty(this, "text", {value: text});
|
||||||
|
return text;
|
||||||
|
},
|
||||||
|
inDom: inDOM,
|
||||||
|
get visible(){
|
||||||
|
var visible = inDOM;
|
||||||
|
if (inDOM){
|
||||||
canvas.scrollIntoView();
|
canvas.scrollIntoView();
|
||||||
var rect = canvas.getBoundingClientRect();
|
var rect = canvas.getBoundingClientRect();
|
||||||
var foundEl = document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2);
|
var foundEl = document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2);
|
||||||
visible = (foundEl === canvas);
|
visible = (foundEl === canvas);
|
||||||
}
|
}
|
||||||
}
|
Object.defineProperty(this, "visible", {value: visible});
|
||||||
return {
|
return visible;
|
||||||
canvas: canvas,
|
},
|
||||||
text: canvas? (visible? "visible": "invisible"): "nocanvas",
|
|
||||||
visible: visible,
|
|
||||||
reset: function(){
|
reset: function(){
|
||||||
if (canvas){
|
if (canvas){
|
||||||
canvas.style.border = oldBorder;
|
canvas.style.border = oldBorder;
|
||||||
@ -145,13 +156,13 @@
|
|||||||
var status = changedFunction.mode.status;
|
var status = changedFunction.mode.status;
|
||||||
if (status === "ask"){
|
if (status === "ask"){
|
||||||
var askStatus = changedFunction.mode.askStatus;
|
var askStatus = changedFunction.mode.askStatus;
|
||||||
if (askStatus.askOnce && askStatus.alreadyAsked){
|
var appearance = canvasAppearance(this);
|
||||||
|
if (askStatus.askOnce && askStatus.alreadyAsked[appearance.askCategory]){
|
||||||
// console.log("already asked");
|
// console.log("already asked");
|
||||||
status = askStatus.answer;
|
status = askStatus.answer[appearance.askCategory];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//console.log("asking");
|
//console.log("asking");
|
||||||
var appearance = canvasAppearance(this);
|
|
||||||
var msg = _(changedFunction.mode.askText[appearance.text]);
|
var msg = _(changedFunction.mode.askText[appearance.text]);
|
||||||
if (settings.showCallingFile){
|
if (settings.showCallingFile){
|
||||||
var callers = new Error().stack.trim().split("\n");
|
var callers = new Error().stack.trim().split("\n");
|
||||||
@ -159,8 +170,11 @@
|
|||||||
var findme = callers.shift(); // Remove us from the stack
|
var findme = callers.shift(); // Remove us from the stack
|
||||||
findme = findme.replace(/(:[0-9]+){1,2}$/, ""); // rm line & column
|
findme = findme.replace(/(:[0-9]+){1,2}$/, ""); // rm line & column
|
||||||
// Eliminate squashed stack. stack may contain 2+ stacks, but why...
|
// Eliminate squashed stack. stack may contain 2+ stacks, but why...
|
||||||
|
var inDoubleStack = false;
|
||||||
callers = callers.filter(function(caller){
|
callers = callers.filter(function(caller){
|
||||||
return caller.search(findme) === -1;
|
var doubleStackStart = caller.search(findme) !== -1;
|
||||||
|
inDoubleStack = inDoubleStack || doubleStackStart;
|
||||||
|
return !inDoubleStack;
|
||||||
});
|
});
|
||||||
msg += "\n\n" + _("sourceOutput") + ": ";
|
msg += "\n\n" + _("sourceOutput") + ": ";
|
||||||
if (settings.showCompleteCallingStack){
|
if (settings.showCompleteCallingStack){
|
||||||
@ -173,8 +187,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
status = window.confirm(msg) ? "allow": "block";
|
status = window.confirm(msg) ? "allow": "block";
|
||||||
askStatus.alreadyAsked = true;
|
askStatus.alreadyAsked[appearance.text] = true;
|
||||||
askStatus.answer = status;
|
askStatus.answer[appearance.text] = status;
|
||||||
//console.log("asking (done)");
|
//console.log("asking (done)");
|
||||||
appearance.reset();
|
appearance.reset();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user