1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-31 17:11:54 +01:00

Used api property to display correct text in ask mode.

This commit is contained in:
kkapsner 2018-06-21 00:13:32 +02:00
parent 1abc681e3f
commit 0f44820e3d
4 changed files with 49 additions and 16 deletions

View File

@ -135,6 +135,18 @@
"message": "Wollen Sie das Auslesen des rot umrandeten <canvas> erlauben?", "message": "Wollen Sie das Auslesen des rot umrandeten <canvas> erlauben?",
"description": "" "description": ""
}, },
"askForAudioPermission": {
"message": "Wollen Sie die Audio-API erlauben?",
"description": ""
},
"askForAudioInputPermission": {
"message": "Wollen Sie das Schreiben in über die Audio-API erlauben?",
"description": ""
},
"askForAudioReadoutPermission": {
"message": "Wollen Sie das Auslesen über die Audio-API erlauben?",
"description": ""
},
"askOnlyOnce_title": { "askOnlyOnce_title": {
"message": "Nur einmal nachfragen", "message": "Nur einmal nachfragen",
"description": "" "description": ""

View File

@ -135,6 +135,18 @@
"message": "Do you want to allow the readout of the red bordered <canvas>?", "message": "Do you want to allow the readout of the red bordered <canvas>?",
"description": "" "description": ""
}, },
"askForAudioPermission": {
"message": "Do you want to allow the audio API?",
"description": ""
},
"askForAudioInputPermission": {
"message": "Do you want to allow audio-API input?",
"description": ""
},
"askForAudioReadoutPermission": {
"message": "Do you want to allow audio readout?",
"description": ""
},
"askOnlyOnce_title": { "askOnlyOnce_title": {
"message": "Ask only once", "message": "Ask only once",
"description": "" "description": ""

View File

@ -15,11 +15,11 @@
const {parseErrorStack} = require("./callingStack"); const {parseErrorStack} = require("./callingStack");
// Check canvas appearance // Check canvas appearance
function canvasAppearance(window, context){ function canvasAppearance(window, api, context){
var oldBorder = false; var oldBorder = false;
var canvas = false; var canvas = false;
var inDOM = null; var inDOM = null;
if (context){ if (api === "canvas" && context){
var nodeName; var nodeName;
try { try {
nodeName = context.nodeName; nodeName = context.nodeName;
@ -44,9 +44,9 @@
} }
return { return {
canvas: canvas, canvas: canvas,
askCategory: canvas? (inDOM? "visible": "invisible"): "nocanvas", askCategory: canvas? (inDOM? "visible": "invisible"): (api === "canvas"? "nocanvas": api),
get text(){ get text(){
var text = canvas? (this.visible? "visible": "invisible"): "nocanvas"; var text = canvas? (this.visible? "visible": "invisible"): (api === "canvas"? "nocanvas": api);
Object.defineProperty(this, "text", {value: text}); Object.defineProperty(this, "text", {value: text});
return text; return text;
}, },
@ -85,7 +85,8 @@
askText: { askText: {
visible: _("askForVisiblePermission"), visible: _("askForVisiblePermission"),
invisible: _("askForInvisiblePermission"), invisible: _("askForInvisiblePermission"),
nocanvas: _("askForPermission") nocanvas: _("askForPermission"),
audio: _("askForAudioPermission")
}, },
askStatus: { askStatus: {
alreadyAsked: {}, alreadyAsked: {},
@ -96,7 +97,8 @@
askText: { askText: {
visible: _("askForVisibleInputPermission"), visible: _("askForVisibleInputPermission"),
invisible: _("askForInvisibleInputPermission"), invisible: _("askForInvisibleInputPermission"),
nocanvas: _("askForInputPermission") nocanvas: _("askForInputPermission"),
audio: _("askForAudioInputPermission")
}, },
askStatus: { askStatus: {
alreadyAsked: {}, alreadyAsked: {},
@ -107,7 +109,8 @@
askText: { askText: {
visible: _("askForVisibleReadoutPermission"), visible: _("askForVisibleReadoutPermission"),
invisible: _("askForInvisibleReadoutPermission"), invisible: _("askForInvisibleReadoutPermission"),
nocanvas: _("askForReadoutPermission") nocanvas: _("askForReadoutPermission"),
audio: _("askForAudioReadoutPermission")
}, },
askStatus: { askStatus: {
alreadyAsked: {}, alreadyAsked: {},
@ -120,15 +123,16 @@
} }
} }
scope.ask = function({window, type, canvas, errorStack}, {_, prefs}){ scope.ask = function({window, type, api, canvas, errorStack}, {_, prefs}){
var answer; var answer;
var askMode = getAskMode(window, type, _); var askMode = getAskMode(window, type, _);
var askStatus = askMode.askStatus; var askStatus = askMode.askStatus;
var appearance = canvasAppearance(window, canvas); var appearance = canvasAppearance(window, api, canvas);
if (prefs("askOnlyOnce") !== "no" && askStatus.alreadyAsked[appearance.askCategory]){ var category = appearance.askCategory;
if (prefs("askOnlyOnce") !== "no" && askStatus.alreadyAsked[category]){
// already asked // already asked
appearance.reset(); appearance.reset();
return askStatus.answer[appearance.askCategory]; return askStatus.answer[category];
} }
else { else {
let imgContainer = null; let imgContainer = null;
@ -171,6 +175,9 @@
} }
// asking // asking
var msg = askMode.askText[appearance.text]; var msg = askMode.askText[appearance.text];
// visible vs invisible is only calculated here correctly
category = appearance.text;
if (prefs("showCallingFile")){ if (prefs("showCallingFile")){
msg += parseErrorStack(errorStack).toString(_); msg += parseErrorStack(errorStack).toString(_);
} }
@ -183,13 +190,13 @@
["context", "readout", "input"].forEach(function(type){ ["context", "readout", "input"].forEach(function(type){
var askMode = getAskMode(window, type, _); var askMode = getAskMode(window, type, _);
var askStatus = askMode.askStatus; var askStatus = askMode.askStatus;
askStatus.alreadyAsked[appearance.text] = true; askStatus.alreadyAsked[category] = true;
askStatus.answer[appearance.text] = answer; askStatus.answer[category] = answer;
}); });
} }
else { else {
askStatus.alreadyAsked[appearance.text] = true; askStatus.alreadyAsked[category] = true;
askStatus.answer[appearance.text] = answer; askStatus.answer[category] = answer;
} }
appearance.reset(); appearance.reset();
return answer; return answer;

View File

@ -232,10 +232,12 @@
funcStatus.mode = ask({ funcStatus.mode = ask({
window: window, window: window,
type: changedFunction.type, type: changedFunction.type,
api: changedFunction.api,
canvas: this instanceof HTMLCanvasElement? canvas: this instanceof HTMLCanvasElement?
this: this:
( (
this.canvas instanceof HTMLCanvasElement? this &&
(this.canvas instanceof HTMLCanvasElement)?
this.canvas: this.canvas:
false false
), ),