mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 04:26:35 +02:00
Changed library functions that may work in both types.
Added helper scripts for webExtension.
This commit is contained in:
parent
6c3b27e7e4
commit
4ea073132d
6 changed files with 190 additions and 97 deletions
|
@ -4,6 +4,15 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
(function(){
|
(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
var scope;
|
||||||
|
if ((typeof exports) !== "undefined"){
|
||||||
|
scope = exports;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.scope.askForPermission = {};
|
||||||
|
scope = window.scope.askForPermission;
|
||||||
|
}
|
||||||
|
|
||||||
const {parseErrorStack} = require("./callingStack");
|
const {parseErrorStack} = require("./callingStack");
|
||||||
|
|
||||||
// Check canvas appearance
|
// Check canvas appearance
|
||||||
|
@ -107,7 +116,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.ask = function({window, type, canvas, errorStack}, {_, prefs}){
|
scope.ask = function({window, type, 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;
|
||||||
|
|
|
@ -3,101 +3,113 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
(function(){
|
||||||
const preferences = require("sdk/simple-prefs");
|
|
||||||
const prefs = preferences.prefs;
|
|
||||||
|
|
||||||
// Translation
|
|
||||||
var translate = require("sdk/l10n").get;
|
|
||||||
var _ = function(name, replace, translateAPI){
|
|
||||||
"use strict";
|
|
||||||
if (!translateAPI){
|
|
||||||
translateAPI = translate;
|
|
||||||
}
|
|
||||||
|
|
||||||
var str = translateAPI(name) || name;
|
|
||||||
if (replace){
|
|
||||||
// replace generic content in the transation by given parameter
|
|
||||||
Object.keys(replace).forEach(function(name){
|
|
||||||
str = str.replace(new RegExp("{" + name + "}", "g"), replace[name]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Stack parsing
|
|
||||||
function parseStackEntry(entry){
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var m = /@(.*):(\d*):(\d*)$/.exec(entry) || ["", entry, "--", "--"];
|
var scope;
|
||||||
return {
|
if ((typeof exports) !== "undefined"){
|
||||||
url: m[1],
|
scope = exports;
|
||||||
line: parseInt(m[2], 10),
|
|
||||||
column: parseInt(m[3], 10),
|
|
||||||
raw: entry
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function stackRuleMatch(stackEntry, stackRule){
|
|
||||||
if (!stackEntry){
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (stackEntry.url !== stackRule.url){
|
else {
|
||||||
return false;
|
window.scope.callingStack = {};
|
||||||
|
scope = window.scope.callingStack;
|
||||||
}
|
}
|
||||||
if ((typeof stackRule.line) !== "undefined" && stackEntry.line !== stackRule.line){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ((typeof stackRule.column) !== "undefined" && stackEntry.column !== stackRule.column){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse calling stack
|
|
||||||
function parseErrorStack(errorStack){
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var callers = errorStack.trim().split("\n");
|
const preferences = require("sdk/simple-prefs");
|
||||||
var findme = callers.shift(); // Remove us from the stack
|
const prefs = preferences.prefs;
|
||||||
findme = findme.replace(/(:[0-9]+){1,2}$/, ""); // rm line & column
|
|
||||||
// Eliminate squashed stack. stack may contain 2+ stacks, but why...
|
// Translation
|
||||||
var inDoubleStack = false;
|
var translate = require("sdk/l10n").get;
|
||||||
callers = callers.filter(function(caller){
|
var _ = function(name, replace, translateAPI){
|
||||||
var doubleStackStart = caller.search(findme) !== -1;
|
"use strict";
|
||||||
inDoubleStack = inDoubleStack || doubleStackStart;
|
if (!translateAPI){
|
||||||
return !inDoubleStack;
|
translateAPI = translate;
|
||||||
}).map(parseStackEntry);
|
|
||||||
return {
|
|
||||||
toString: function(translateAPI){
|
|
||||||
var msg = "";
|
|
||||||
msg += "\n\n" + _("sourceOutput", undefined, translateAPI) + ": ";
|
|
||||||
if (prefs.showCompleteCallingStack){
|
|
||||||
msg += callers.reduce(function(stack, c){
|
|
||||||
return stack + "\n\t" + _("stackEntryOutput", c, translateAPI);
|
|
||||||
}, "");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
msg += _("stackEntryOutput", callers[0], translateAPI);
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg;
|
|
||||||
},
|
|
||||||
match: function(stackRule){
|
|
||||||
if (typeof stackRule.stackPosition !== "undefined"){
|
|
||||||
var pos = stackRule.stackPosition;
|
|
||||||
if (pos < 0){
|
|
||||||
pos += callers.length;
|
|
||||||
}
|
|
||||||
return stackRuleMatch(callers[pos], stackRule);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return callers.some(function(stackEntry){
|
|
||||||
return stackRuleMatch(stackEntry, stackRule);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var str = translateAPI(name) || name;
|
||||||
|
if (replace){
|
||||||
|
// replace generic content in the transation by given parameter
|
||||||
|
Object.keys(replace).forEach(function(name){
|
||||||
|
str = str.replace(new RegExp("{" + name + "}", "g"), replace[name]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return str;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
// Stack parsing
|
||||||
|
function parseStackEntry(entry){
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var m = /@(.*):(\d*):(\d*)$/.exec(entry) || ["", entry, "--", "--"];
|
||||||
|
return {
|
||||||
|
url: m[1],
|
||||||
|
line: parseInt(m[2], 10),
|
||||||
|
column: parseInt(m[3], 10),
|
||||||
|
raw: entry
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function stackRuleMatch(stackEntry, stackRule){
|
||||||
|
if (!stackEntry){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (stackEntry.url !== stackRule.url){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((typeof stackRule.line) !== "undefined" && stackEntry.line !== stackRule.line){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((typeof stackRule.column) !== "undefined" && stackEntry.column !== stackRule.column){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
exports.parseErrorStack = parseErrorStack;
|
// parse calling stack
|
||||||
|
function parseErrorStack(errorStack){
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var callers = errorStack.trim().split("\n");
|
||||||
|
var findme = callers.shift(); // Remove us from the stack
|
||||||
|
findme = findme.replace(/(:[0-9]+){1,2}$/, ""); // rm line & column
|
||||||
|
// Eliminate squashed stack. stack may contain 2+ stacks, but why...
|
||||||
|
var inDoubleStack = false;
|
||||||
|
callers = callers.filter(function(caller){
|
||||||
|
var doubleStackStart = caller.search(findme) !== -1;
|
||||||
|
inDoubleStack = inDoubleStack || doubleStackStart;
|
||||||
|
return !inDoubleStack;
|
||||||
|
}).map(parseStackEntry);
|
||||||
|
return {
|
||||||
|
toString: function(translateAPI){
|
||||||
|
var msg = "";
|
||||||
|
msg += "\n\n" + _("sourceOutput", undefined, translateAPI) + ": ";
|
||||||
|
if (prefs.showCompleteCallingStack){
|
||||||
|
msg += callers.reduce(function(stack, c){
|
||||||
|
return stack + "\n\t" + _("stackEntryOutput", c, translateAPI);
|
||||||
|
}, "");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
msg += _("stackEntryOutput", callers[0], translateAPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
return msg;
|
||||||
|
},
|
||||||
|
match: function(stackRule){
|
||||||
|
if (typeof stackRule.stackPosition !== "undefined"){
|
||||||
|
var pos = stackRule.stackPosition;
|
||||||
|
if (pos < 0){
|
||||||
|
pos += callers.length;
|
||||||
|
}
|
||||||
|
return stackRuleMatch(callers[pos], stackRule);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return callers.some(function(stackEntry){
|
||||||
|
return stackRuleMatch(stackEntry, stackRule);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
scope.parseErrorStack = parseErrorStack;
|
||||||
|
}());
|
13
lib/check.js
13
lib/check.js
|
@ -6,13 +6,22 @@
|
||||||
(function(){
|
(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var scope;
|
||||||
|
if ((typeof exports) !== "undefined"){
|
||||||
|
scope = exports;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.scope.check = {};
|
||||||
|
scope = window.scope.check;
|
||||||
|
}
|
||||||
|
|
||||||
const lists = require("./lists");
|
const lists = require("./lists");
|
||||||
const preferences = require("sdk/simple-prefs");
|
const preferences = require("sdk/simple-prefs");
|
||||||
const prefs = preferences.prefs;
|
const prefs = preferences.prefs;
|
||||||
const {parseErrorStack} = require("./callingStack");
|
const {parseErrorStack} = require("./callingStack");
|
||||||
const {URL} = require("sdk/url");
|
const {URL} = require("sdk/url");
|
||||||
|
|
||||||
exports.check = function check({url, errorStack}){
|
scope.check = function check({url, errorStack}){
|
||||||
var match = checkBoth(errorStack, url, prefs.blockMode).match(/^(block|allow|fake|ask)(|Readout|Everything|Context|Input|Internal)$/);
|
var match = checkBoth(errorStack, url, prefs.blockMode).match(/^(block|allow|fake|ask)(|Readout|Everything|Context|Input|Internal)$/);
|
||||||
if (match){
|
if (match){
|
||||||
return {
|
return {
|
||||||
|
@ -96,5 +105,5 @@
|
||||||
var callingStack = parseErrorStack(errorStack);
|
var callingStack = parseErrorStack(errorStack);
|
||||||
return lists.get("stack").match(callingStack);
|
return lists.get("stack").match(callingStack);
|
||||||
}
|
}
|
||||||
exports.checkStack = checkStack;
|
scope.checkStack = checkStack;
|
||||||
}());
|
}());
|
14
lib/defaultSettings.js
Normal file
14
lib/defaultSettings.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var settings = {
whiteList: "",
blackList: "",
blockMode: "fakeReadout",
maxFakeSize: 0,
rng: "nonPersistent",
persistentRndStorage: "",
storePersistentRnd: false,
askOnlyOnce: true,
showNotifications: true,
notificationDisplayTime: 30,
ignoreList: "",
showCallingFile: false,
showCompleteCallingStack: false,
enableStackList: false,
stackList: ""
|
||||||
|
};
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
browser.storage.onChanged.addListener(function(change, area){
|
||||||
|
if (area === "local"){
|
||||||
|
Object.keys(change).forEach(function(key){
|
||||||
|
settings[key] = change[key].newValue;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}());
|
|
@ -5,6 +5,15 @@
|
||||||
(function(){
|
(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var scope;
|
||||||
|
if ((typeof exports) !== "undefined"){
|
||||||
|
scope = exports;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.scope.intercept = {};
|
||||||
|
scope = window.scope.intercept;
|
||||||
|
}
|
||||||
|
|
||||||
const {changedFunctions, setRandomSupply} = require("./modifiedAPI");
|
const {changedFunctions, setRandomSupply} = require("./modifiedAPI");
|
||||||
const randomSupplies = require("./randomSupplies");
|
const randomSupplies = require("./randomSupplies");
|
||||||
setRandomSupply(randomSupplies.nonPersistent);
|
setRandomSupply(randomSupplies.nonPersistent);
|
||||||
|
@ -20,7 +29,7 @@
|
||||||
setRandomSupply(randomSupplies.nonPersistent);
|
setRandomSupply(randomSupplies.nonPersistent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.setRandomSupplyByType = setRandomSupplyByType;
|
scope.setRandomSupplyByType = setRandomSupplyByType;
|
||||||
|
|
||||||
function getURL(window){
|
function getURL(window){
|
||||||
if (!window.location.href || window.location.href === "about:blank"){
|
if (!window.location.href || window.location.href === "about:blank"){
|
||||||
|
@ -34,7 +43,7 @@
|
||||||
return window.location.href;
|
return window.location.href;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.intercept = function intercept({subject: window}, {check, checkStack, ask, notify, prefs}){
|
scope.intercept = function intercept({subject: window}, {check, checkStack, ask, notify, prefs}){
|
||||||
var siteStatus = check({url: getURL(window)});
|
var siteStatus = check({url: getURL(window)});
|
||||||
if (siteStatus.mode !== "allow"){
|
if (siteStatus.mode !== "allow"){
|
||||||
apiNames.forEach(function(name){
|
apiNames.forEach(function(name){
|
||||||
|
@ -51,7 +60,7 @@
|
||||||
{
|
{
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
configureable: false,
|
configureable: false,
|
||||||
get: function(){
|
get: exportFunction(function()
|
||||||
var url = getURL(window);
|
var url = getURL(window);
|
||||||
if (!url){
|
if (!url){
|
||||||
return undef;
|
return undef;
|
||||||
|
@ -90,7 +99,7 @@
|
||||||
else {
|
else {
|
||||||
return original;
|
return original;
|
||||||
}
|
}
|
||||||
}
|
}, window)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
40
lib/require.js
Normal file
40
lib/require.js
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
window.scope = {};
|
||||||
|
function require(module){
|
||||||
|
if (module.startsWith("./")){
|
||||||
|
var scopeName = module.substr(2).replace(/\..+/, "");
|
||||||
|
return window.scope[scopeName];
|
||||||
|
}
|
||||||
|
else if (module === "chrome"){
|
||||||
|
return {
|
||||||
|
Cu: {exportFunction}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (module === "sdk/simple-prefs"){
|
||||||
|
return {
|
||||||
|
prefs: settings,
|
||||||
|
on: function(key, callback){
|
||||||
|
browser.storage.onChanged.addListener(function(changes, area){
|
||||||
|
if (area === "local"){
|
||||||
|
if (changes[key]){
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (module === "sdk/l10n"){
|
||||||
|
return {
|
||||||
|
get: function(key){console.log(key);
|
||||||
|
return browser.i18n.getMessage(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (module === "sdk/url"){
|
||||||
|
return {
|
||||||
|
URL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.error("Not able to get non relative modules!", module);
|
||||||
|
return undefined;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue