mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 21:00:23 +01:00
Changed library functions that may work in both types.
Added helper scripts for webExtension.
This commit is contained in:
parent
6c3b27e7e4
commit
4ea073132d
@ -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;
|
||||
|
@ -3,6 +3,17 @@
|
||||
/* 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";
|
||||
|
||||
var scope;
|
||||
if ((typeof exports) !== "undefined"){
|
||||
scope = exports;
|
||||
}
|
||||
else {
|
||||
window.scope.callingStack = {};
|
||||
scope = window.scope.callingStack;
|
||||
}
|
||||
|
||||
const preferences = require("sdk/simple-prefs");
|
||||
const prefs = preferences.prefs;
|
||||
@ -100,4 +111,5 @@ function parseErrorStack(errorStack){
|
||||
};
|
||||
}
|
||||
|
||||
exports.parseErrorStack = parseErrorStack;
|
||||
scope.parseErrorStack = parseErrorStack;
|
||||
}());
|
13
lib/check.js
13
lib/check.js
@ -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
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(){
|
||||
"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
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…
x
Reference in New Issue
Block a user