1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-06-03 03:48:04 +02:00

Changed library functions that may work in both types.

Added helper scripts for webExtension.
This commit is contained in:
kkapsner 2017-06-25 22:22:17 +02:00
parent 6c3b27e7e4
commit 4ea073132d
6 changed files with 190 additions and 97 deletions

View File

@ -4,6 +4,15 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
(function(){
"use strict";
var scope;
if ((typeof exports) !== "undefined"){
scope = exports;
}
else {
window.scope.askForPermission = {};
scope = window.scope.askForPermission;
}
const {parseErrorStack} = require("./callingStack");
// 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 askMode = getAskMode(window, type, _);
var askStatus = askMode.askStatus;

View File

@ -3,13 +3,24 @@
/* 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
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
(function(){
"use strict";
const preferences = require("sdk/simple-prefs");
const prefs = preferences.prefs;
var scope;
if ((typeof exports) !== "undefined"){
scope = exports;
}
else {
window.scope.callingStack = {};
scope = window.scope.callingStack;
}
// Translation
var translate = require("sdk/l10n").get;
var _ = function(name, replace, translateAPI){
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;
@ -23,10 +34,10 @@ var _ = function(name, replace, translateAPI){
});
}
return str;
};
};
// Stack parsing
function parseStackEntry(entry){
// Stack parsing
function parseStackEntry(entry){
"use strict";
var m = /@(.*):(\d*):(\d*)$/.exec(entry) || ["", entry, "--", "--"];
@ -36,9 +47,9 @@ function parseStackEntry(entry){
column: parseInt(m[3], 10),
raw: entry
};
}
}
function stackRuleMatch(stackEntry, stackRule){
function stackRuleMatch(stackEntry, stackRule){
if (!stackEntry){
return false;
}
@ -52,10 +63,10 @@ function stackRuleMatch(stackEntry, stackRule){
return false;
}
return true;
}
}
// parse calling stack
function parseErrorStack(errorStack){
// parse calling stack
function parseErrorStack(errorStack){
"use strict";
var callers = errorStack.trim().split("\n");
@ -98,6 +109,7 @@ function parseErrorStack(errorStack){
}
}
};
}
}
exports.parseErrorStack = parseErrorStack;
scope.parseErrorStack = parseErrorStack;
}());

View File

@ -6,13 +6,22 @@
(function(){
"use strict";
var scope;
if ((typeof exports) !== "undefined"){
scope = exports;
}
else {
window.scope.check = {};
scope = window.scope.check;
}
const lists = require("./lists");
const preferences = require("sdk/simple-prefs");
const prefs = preferences.prefs;
const {parseErrorStack} = require("./callingStack");
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)$/);
if (match){
return {
@ -96,5 +105,5 @@
var callingStack = parseErrorStack(errorStack);
return lists.get("stack").match(callingStack);
}
exports.checkStack = checkStack;
scope.checkStack = checkStack;
}());

14
lib/defaultSettings.js Normal file
View 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;
});
}
});
}());

View File

@ -5,6 +5,15 @@
(function(){
"use strict";
var scope;
if ((typeof exports) !== "undefined"){
scope = exports;
}
else {
window.scope.intercept = {};
scope = window.scope.intercept;
}
const {changedFunctions, setRandomSupply} = require("./modifiedAPI");
const randomSupplies = require("./randomSupplies");
setRandomSupply(randomSupplies.nonPersistent);
@ -20,7 +29,7 @@
setRandomSupply(randomSupplies.nonPersistent);
}
}
exports.setRandomSupplyByType = setRandomSupplyByType;
scope.setRandomSupplyByType = setRandomSupplyByType;
function getURL(window){
if (!window.location.href || window.location.href === "about:blank"){
@ -34,7 +43,7 @@
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)});
if (siteStatus.mode !== "allow"){
apiNames.forEach(function(name){
@ -51,7 +60,7 @@
{
enumerable: true,
configureable: false,
get: function(){
get: exportFunction(function()
var url = getURL(window);
if (!url){
return undef;
@ -90,7 +99,7 @@
else {
return original;
}
}
}, window)
}
);
}

40
lib/require.js Normal file
View 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;
}