mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Simplified require and further linting.
This commit is contained in:
parent
01c1145e28
commit
dcb878392e
@ -21,8 +21,9 @@
|
||||
"comma-spacing": ["error", { "before": false, "after": true }],
|
||||
"constructor-super": "warn",
|
||||
"eqeqeq": "error",
|
||||
"max-len": ["warn", 120],
|
||||
"max-lines": ["warn", 200],
|
||||
"max-len": ["warn", {"code": 120, "tabWidth": 4}],
|
||||
"max-lines": ["warn", {"max": 400, "skipBlankLines": true, "skipComments": true}],
|
||||
"max-params": ["warn", 4],
|
||||
"no-const-assign": "warn",
|
||||
"no-this-before-super": "warn",
|
||||
"no-undef": "error",
|
||||
|
@ -56,7 +56,10 @@
|
||||
if (inDOM){
|
||||
canvas.scrollIntoView();
|
||||
var rect = canvas.getBoundingClientRect();
|
||||
var foundEl = window.document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2);
|
||||
var foundEl = window.document.elementFromPoint(
|
||||
rect.left + rect.width / 2,
|
||||
rect.top + rect.height / 2
|
||||
);
|
||||
visible = (foundEl === canvas);
|
||||
}
|
||||
Object.defineProperty(this, "visible", {value: visible});
|
||||
|
@ -13,14 +13,10 @@
|
||||
scope = window.scope.callingStack;
|
||||
}
|
||||
|
||||
const preferences = require("sdk/simple-prefs");
|
||||
const prefs = preferences.prefs;
|
||||
|
||||
// Translation
|
||||
var translate = require("sdk/l10n").get;
|
||||
var _ = function(name, replace, translateAPI){
|
||||
if (!translateAPI){
|
||||
translateAPI = translate;
|
||||
translateAPI = browser.i18n.getMessage;
|
||||
}
|
||||
|
||||
var str = translateAPI(name) || name;
|
||||
@ -76,7 +72,7 @@
|
||||
toString: function(translateAPI){
|
||||
var msg = "";
|
||||
msg += "\n\n" + _("sourceOutput", undefined, translateAPI) + ": ";
|
||||
if (prefs.showCompleteCallingStack){
|
||||
if (settings.showCompleteCallingStack){
|
||||
msg += callers.reduce(function(stack, c){
|
||||
return stack + "\n\t" + _("stackEntryOutput", c, translateAPI);
|
||||
}, "");
|
||||
|
@ -14,13 +14,11 @@
|
||||
}
|
||||
|
||||
const lists = require("./lists");
|
||||
const preferences = require("sdk/simple-prefs");
|
||||
const prefs = preferences.prefs;
|
||||
const {parseErrorStack} = require("./callingStack");
|
||||
const logging = require("./logging");
|
||||
|
||||
scope.check = function check({url, errorStack}){
|
||||
var match = checkBoth(errorStack, url, prefs.blockMode).match(
|
||||
var match = checkBoth(errorStack, url, settings.blockMode).match(
|
||||
/^(block|allow|fake|ask)(|Readout|Everything|Context|Input|Internal)$/
|
||||
);
|
||||
if (match){
|
||||
@ -41,7 +39,7 @@
|
||||
};
|
||||
|
||||
function checkBoth(errorStack, url, blockMode){
|
||||
if (prefs.enableStackList && errorStack && checkStack(errorStack)){
|
||||
if (settings.enableStackList && errorStack && checkStack(errorStack)){
|
||||
return "allow";
|
||||
}
|
||||
else {
|
||||
|
@ -27,7 +27,13 @@
|
||||
var index = String.fromCharCode(r, g, b, a);
|
||||
var color = this.colors[index];
|
||||
if (!color){
|
||||
color = {index, color: [r, g, b, a], count: 0, previousColor: this.minBoundary, nextColor: this.minBoundary.nextColor};
|
||||
color = {
|
||||
index,
|
||||
color: [r, g, b, a],
|
||||
count: 0,
|
||||
previousColor: this.minBoundary,
|
||||
nextColor: this.minBoundary.nextColor
|
||||
};
|
||||
this.numberOfColors += 1;
|
||||
this.minBoundary.nextColor = color;
|
||||
color.nextColor.previousColor = color;
|
||||
|
@ -34,10 +34,9 @@
|
||||
return true;
|
||||
}
|
||||
}
|
||||
const _ = require("sdk/l10n").get;
|
||||
function askWrapper(data){
|
||||
return ask(data, {
|
||||
_,
|
||||
_: browser.i18n.getMessage,
|
||||
prefs
|
||||
});
|
||||
}
|
||||
@ -159,7 +158,10 @@
|
||||
if (data["canvasBlocker-unload"]){
|
||||
enabled = false;
|
||||
}
|
||||
if (data.hasOwnProperty("canvasBlocker-sendNotifications") && data["canvasBlocker-sendNotifications"] === tabId){
|
||||
if (
|
||||
data.hasOwnProperty("canvasBlocker-sendNotifications") &&
|
||||
data["canvasBlocker-sendNotifications"] === tabId
|
||||
){
|
||||
notice("sending notifications:", notifications);
|
||||
browser.runtime.sendMessage({
|
||||
sender: tabId,
|
||||
|
@ -18,7 +18,6 @@
|
||||
setRandomSupply(randomSupplies.nonPersistent);
|
||||
var apiNames = Object.keys(changedFunctions);
|
||||
var undef;
|
||||
var exportFunction = require("chrome").Cu.exportFunction;
|
||||
function setRandomSupplyByType(type){
|
||||
switch (type){
|
||||
case "persistent":
|
||||
@ -86,6 +85,29 @@
|
||||
}
|
||||
var funcStatus = changedFunction.getStatus(this, siteStatus);
|
||||
|
||||
function notifyCallback(messageId){
|
||||
notify({
|
||||
url,
|
||||
errorStack: error.stack,
|
||||
messageId,
|
||||
timestamp: new Date(),
|
||||
functionName: name,
|
||||
dataURL:
|
||||
prefs("storeImageForInspection") &&
|
||||
prefs("showNotifications")?
|
||||
(
|
||||
this instanceof HTMLCanvasElement?
|
||||
this.toDataURL():
|
||||
(
|
||||
this.canvas instanceof HTMLCanvasElement?
|
||||
this.canvas.toDataURL():
|
||||
false
|
||||
)
|
||||
):
|
||||
false
|
||||
});
|
||||
}
|
||||
|
||||
if (funcStatus.active){
|
||||
if (funcStatus.mode === "ask"){
|
||||
funcStatus.mode = ask({
|
||||
@ -100,28 +122,12 @@
|
||||
return original;
|
||||
case "fake":
|
||||
setRandomSupplyByType(prefs("rng"));
|
||||
var fake = changedFunction.fakeGenerator(prefs, function(messageId){
|
||||
notify({
|
||||
url,
|
||||
errorStack: error.stack,
|
||||
messageId,
|
||||
timestamp: new Date(),
|
||||
functionName: name,
|
||||
dataURL:
|
||||
prefs("storeImageForInspection") &&
|
||||
prefs("showNotifications")?
|
||||
(
|
||||
this instanceof HTMLCanvasElement?
|
||||
this.toDataURL():
|
||||
(
|
||||
this.canvas instanceof HTMLCanvasElement?
|
||||
this.canvas.toDataURL():
|
||||
false
|
||||
)
|
||||
):
|
||||
false
|
||||
});
|
||||
}, window, original);
|
||||
var fake = changedFunction.fakeGenerator(
|
||||
prefs,
|
||||
notifyCallback,
|
||||
window,
|
||||
original
|
||||
);
|
||||
switch (fake){
|
||||
case true:
|
||||
return original;
|
||||
|
@ -143,13 +143,6 @@
|
||||
});
|
||||
});
|
||||
|
||||
// warning("TODO: register unload events - do not know how - there seems to be no way with a WebExtension");
|
||||
// old code
|
||||
// const {when: unload} = require("sdk/system/unload");
|
||||
// unload(function(){
|
||||
// processes.port.emit("canvasBlocker-unload");
|
||||
// });
|
||||
|
||||
browser.runtime.onInstalled.addListener(function(){
|
||||
message("CanvasBlocker installed");
|
||||
browser.storage.local.get("storageVersion").then(function(data){
|
||||
|
@ -34,7 +34,11 @@
|
||||
source = new window.wrappedJSObject.ImageData(0, 0);
|
||||
}
|
||||
else if (context instanceof window.CanvasRenderingContext2D){
|
||||
imageData = window.CanvasRenderingContext2D.prototype.getImageData.call(context, 0, 0, context.canvas.width, context.canvas.height);
|
||||
imageData = window.CanvasRenderingContext2D.prototype.getImageData.call(
|
||||
context,
|
||||
0, 0,
|
||||
context.canvas.width, context.canvas.height
|
||||
);
|
||||
source = imageData.data;
|
||||
}
|
||||
else {
|
||||
@ -365,11 +369,15 @@
|
||||
},
|
||||
object: ["WebGLRenderingContext", "WebGL2RenderingContext"],
|
||||
fakeGenerator: function(prefs, notify, window, original){
|
||||
return function readPixels(x, y, width, height, format, type, pixels){
|
||||
return function readPixels(x, y, width, height, format, type, pixels){ // eslint-disable-line max-params
|
||||
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
|
||||
notify.call(this, "fakedReadout");
|
||||
var fakeCanvas = getFakeCanvas(window, this.canvas, prefs);
|
||||
var {context} = copyCanvasToWebgl(window, fakeCanvas, this instanceof window.WebGLRenderingContext? "webgl": "webgl2");
|
||||
var {context} = copyCanvasToWebgl(
|
||||
window,
|
||||
fakeCanvas,
|
||||
this instanceof window.WebGLRenderingContext? "webgl": "webgl2"
|
||||
);
|
||||
return original.apply(context, window.Array.from(arguments));
|
||||
}
|
||||
else {
|
||||
|
@ -44,7 +44,9 @@
|
||||
// create the (sub-)domains random numbers if not existing
|
||||
persistentRnd[domain] = new Uint8Array(128);
|
||||
window.crypto.getRandomValues(persistentRnd[domain]);
|
||||
browser.runtime.sendMessage({"canvasBlocker-new-domain-rnd": {domain, rnd: Array.from(persistentRnd[domain])}});
|
||||
browser.runtime.sendMessage({
|
||||
"canvasBlocker-new-domain-rnd": {domain, rnd: Array.from(persistentRnd[domain])}
|
||||
});
|
||||
}
|
||||
return persistentRnd[domain];
|
||||
};
|
||||
@ -75,7 +77,7 @@
|
||||
},
|
||||
getPixelRng: function(length, window, ignoredColors){
|
||||
var rng = this.getRng(length, window);
|
||||
return function(r, g, b, a, i){
|
||||
return function(r, g, b, a, i){ // eslint-disable-line max-params
|
||||
var index = String.fromCharCode(r, g, b, a);
|
||||
if (ignoredColors[index]){
|
||||
return [r, g, b, a];
|
||||
@ -101,7 +103,7 @@
|
||||
return function getConstantPixelRng(length, window, ignoredColors){
|
||||
var rng = scope.nonPersistent.getRng(1024, window);
|
||||
|
||||
return function(r, g, b, a, i){
|
||||
return function(r, g, b, a, i){ // eslint-disable-line max-params
|
||||
var index = String.fromCharCode(r, g, b, a);
|
||||
if (ignoredColors[index]){
|
||||
return [r, g, b, a];
|
||||
@ -147,7 +149,7 @@
|
||||
},
|
||||
getPixelRng: function(length, window, ignoredColors){
|
||||
var rng = this.getRng(length, window);
|
||||
return function(r, g, b, a, i){
|
||||
return function(r, g, b, a, i){ // eslint-disable-line max-params
|
||||
var index = String.fromCharCode(r, g, b, a);
|
||||
if (ignoredColors[index]){
|
||||
return [r, g, b, a];
|
||||
|
@ -1,4 +1,3 @@
|
||||
/* global settings exportFunction */
|
||||
/* 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/. */
|
||||
@ -10,11 +9,6 @@ function require(module){
|
||||
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,
|
||||
@ -29,18 +23,6 @@ function require(module){
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (module === "sdk/l10n"){
|
||||
return {
|
||||
get: function(key){
|
||||
return browser.i18n.getMessage(key);
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (module === "sdk/url"){
|
||||
return {
|
||||
URL
|
||||
};
|
||||
}
|
||||
throw new ReferenceError("Unable to get non relative module " + module + "!");
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,8 @@
|
||||
var program = context.createProgram();
|
||||
|
||||
var shader = context.createShader(context.VERTEX_SHADER);
|
||||
var vertex = "attribute vec4 a_position;\nattribute vec2 a_texCoord;\nvarying vec2 v_texCoord;\nvoid main(){\n\tgl_Position = a_position;\n\tv_texCoord = a_texCoord;\n}";
|
||||
var vertex = "attribute vec4 a_position;\nattribute vec2 a_texCoord;\nvarying vec2 v_texCoord;\n" +
|
||||
"void main(){\n\tgl_Position = a_position;\n\tv_texCoord = a_texCoord;\n}";
|
||||
context.shaderSource(shader, vertex);
|
||||
context.compileShader(shader);
|
||||
success = context.getShaderParameter(shader, context.COMPILE_STATUS);
|
||||
@ -44,7 +45,8 @@
|
||||
context.attachShader(program, shader);
|
||||
|
||||
shader = context.createShader(context.FRAGMENT_SHADER);
|
||||
var fragmenter = "precision mediump float;\nuniform sampler2D u_image;\nvarying vec2 v_texCoord;\nvoid main(){\n\tgl_FragColor = texture2D(u_image, v_texCoord);\n}";
|
||||
var fragmenter = "precision mediump float;\nuniform sampler2D u_image;\nvarying vec2 v_texCoord;\n" +
|
||||
"void main(){\n\tgl_FragColor = texture2D(u_image, v_texCoord);\n}";
|
||||
context.shaderSource(shader, fragmenter);
|
||||
context.compileShader(shader);
|
||||
success = context.getShaderParameter(shader, context.COMPILE_STATUS);
|
||||
|
@ -122,7 +122,10 @@ Promise.all([
|
||||
data["canvasBlocker-notifications"].forEach(function(notification){
|
||||
verbose(notification);
|
||||
notification.url = new URL(notification.url);
|
||||
domainNotification(notification.url.hostname, notification.messageId).addNotification(new Notification(notification));
|
||||
domainNotification(
|
||||
notification.url.hostname,
|
||||
notification.messageId
|
||||
).addNotification(new Notification(notification));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -53,7 +53,9 @@ addTest("function length", function(log){
|
||||
addTest("function code", function(log){
|
||||
"use strict";
|
||||
|
||||
if (!CanvasRenderingContext2D.prototype.getImageData.toString().match(/^\s*function getImageData\s*\(\)\s*\{\s*\[native code\]\s*\}\s*$/)){
|
||||
if (!CanvasRenderingContext2D.prototype.getImageData.toString().match(
|
||||
/^\s*function getImageData\s*\(\)\s*\{\s*\[native code\]\s*\}\s*$/
|
||||
)){
|
||||
log("unexpected function code:", CanvasRenderingContext2D.prototype.getImageData.toString());
|
||||
return true;
|
||||
}
|
||||
|
@ -20,8 +20,12 @@
|
||||
show(document.getElementById("top"), topTest());
|
||||
show(document.getElementById("iframe"), iframeTest());
|
||||
}
|
||||
document.querySelector("#top button").addEventListener("click", function(){show(document.getElementById("top"), topTest());});
|
||||
document.querySelector("#iframe button").addEventListener("click", function(){show(document.getElementById("iframe"), iframeTest());});
|
||||
document.querySelector("#top button").addEventListener("click", function(){
|
||||
show(document.getElementById("top"), topTest());
|
||||
});
|
||||
document.querySelector("#iframe button").addEventListener("click", function(){
|
||||
show(document.getElementById("iframe"), iframeTest());
|
||||
});
|
||||
}());
|
||||
|
||||
function draw(canvas){
|
||||
|
Loading…
x
Reference in New Issue
Block a user