mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 12:36:37 +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,13 +3,24 @@
|
||||||
/* 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(){
|
||||||
|
"use strict";
|
||||||
|
|
||||||
const preferences = require("sdk/simple-prefs");
|
var scope;
|
||||||
const prefs = preferences.prefs;
|
if ((typeof exports) !== "undefined"){
|
||||||
|
scope = exports;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.scope.callingStack = {};
|
||||||
|
scope = window.scope.callingStack;
|
||||||
|
}
|
||||||
|
|
||||||
// Translation
|
const preferences = require("sdk/simple-prefs");
|
||||||
var translate = require("sdk/l10n").get;
|
const prefs = preferences.prefs;
|
||||||
var _ = function(name, replace, translateAPI){
|
|
||||||
|
// Translation
|
||||||
|
var translate = require("sdk/l10n").get;
|
||||||
|
var _ = function(name, replace, translateAPI){
|
||||||
"use strict";
|
"use strict";
|
||||||
if (!translateAPI){
|
if (!translateAPI){
|
||||||
translateAPI = translate;
|
translateAPI = translate;
|
||||||
|
@ -23,10 +34,10 @@ var _ = function(name, replace, translateAPI){
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Stack parsing
|
// Stack parsing
|
||||||
function parseStackEntry(entry){
|
function parseStackEntry(entry){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var m = /@(.*):(\d*):(\d*)$/.exec(entry) || ["", entry, "--", "--"];
|
var m = /@(.*):(\d*):(\d*)$/.exec(entry) || ["", entry, "--", "--"];
|
||||||
|
@ -36,9 +47,9 @@ function parseStackEntry(entry){
|
||||||
column: parseInt(m[3], 10),
|
column: parseInt(m[3], 10),
|
||||||
raw: entry
|
raw: entry
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function stackRuleMatch(stackEntry, stackRule){
|
function stackRuleMatch(stackEntry, stackRule){
|
||||||
if (!stackEntry){
|
if (!stackEntry){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -52,10 +63,10 @@ function stackRuleMatch(stackEntry, stackRule){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse calling stack
|
// parse calling stack
|
||||||
function parseErrorStack(errorStack){
|
function parseErrorStack(errorStack){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var callers = errorStack.trim().split("\n");
|
var callers = errorStack.trim().split("\n");
|
||||||
|
@ -98,6 +109,7 @@ function parseErrorStack(errorStack){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.parseErrorStack = parseErrorStack;
|
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