mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
parent
fa3111a3ea
commit
f5699a1bf3
10 changed files with 601 additions and 65 deletions
|
@ -29,6 +29,10 @@
|
|||
logging.verbose("open settings inspection");
|
||||
window.open("export.html", "_blank");
|
||||
},
|
||||
openSettingSanitation: function(){
|
||||
logging.verbose("open settings sanitation");
|
||||
window.open("sanitize.html", "_blank");
|
||||
},
|
||||
saveSettings: function(){
|
||||
logging.verbose("save settings");
|
||||
const data = {};
|
||||
|
|
268
options/sanitationRules.js
Normal file
268
options/sanitationRules.js
Normal file
|
@ -0,0 +1,268 @@
|
|||
/* 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 {
|
||||
scope = {};
|
||||
window.scope.sanitationRules = scope;
|
||||
}
|
||||
|
||||
const settings = require("./settings");
|
||||
|
||||
scope.ruleset = [
|
||||
{
|
||||
name: "unnecessaryURLValue",
|
||||
check: function(errorCallback){
|
||||
const {url: urlContainer} = settings.getContainers();
|
||||
const containerValue = urlContainer.get();
|
||||
const errorMessage = browser.i18n.getMessage("sanitation_error.unnecessaryURLValue");
|
||||
function createErrorMessage(setting, urlValue){
|
||||
return errorMessage
|
||||
.replace(/{setting-technical}/g, setting.name)
|
||||
.replace(/{setting-title}/g, browser.i18n.getMessage(setting.name + "_title"))
|
||||
.replace(/{url}/g, urlValue.url);
|
||||
}
|
||||
containerValue.forEach(function(urlValues){
|
||||
Object.keys(urlValues).filter(function(key){
|
||||
return key !== "url";
|
||||
}).forEach(function(key){
|
||||
const setting = settings.getDefinition(key);
|
||||
if (setting && setting.urlSpecific){
|
||||
const globalValue = setting.get();
|
||||
if (urlValues[key] === globalValue){
|
||||
errorCallback({
|
||||
message: createErrorMessage(setting, urlValues),
|
||||
severity: "low",
|
||||
resolutions: [{
|
||||
label: browser.i18n.getMessage("sanitation_resolution.removeURLValue"),
|
||||
callback: function(){
|
||||
setting.reset(urlValues.url);
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "disabledFeatures",
|
||||
check: function(errorCallback){
|
||||
const errorMessage = browser.i18n.getMessage("sanitation_error.disabledFeatures");
|
||||
function createErrorMessage(api){
|
||||
return errorMessage.replace(/{api}/g, browser.i18n.getMessage("section_" + api.section));
|
||||
}
|
||||
const protectedFeatures = settings.getDefinition("protectedAPIFeatures");
|
||||
const protectedFeaturesValue = protectedFeatures.get();
|
||||
function getSectionKeys(section){
|
||||
let inSection = false;
|
||||
return protectedFeatures.keys.filter(function(key){
|
||||
if (typeof key === "string"){
|
||||
return inSection;
|
||||
}
|
||||
else {
|
||||
if (key.level === 1){
|
||||
inSection = key.name === section;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
[
|
||||
{mainFlag: "protectAudio", section: "Audio-API"},
|
||||
{mainFlag: "protectWindow", section: "Window-API"},
|
||||
{mainFlag: "protectDOMRect", section: "DOMRect-API"},
|
||||
].forEach(function(api){
|
||||
if (settings.get(api.mainFlag)){
|
||||
let inSection = false;
|
||||
let anyActive = false;
|
||||
if (getSectionKeys(api.section).every(function(key){
|
||||
return protectedFeaturesValue.hasOwnProperty(key) &&
|
||||
!protectedFeaturesValue[key];
|
||||
})){
|
||||
errorCallback({
|
||||
message: createErrorMessage(api),
|
||||
severity: "high",
|
||||
resolutions: [
|
||||
{
|
||||
label: browser.i18n.getMessage("sanitation_resolution.enableFeatures"),
|
||||
callback: function(){
|
||||
const protectedFeaturesValue = protectedFeatures.get();
|
||||
getSectionKeys(api.section).forEach(function(key){
|
||||
protectedFeaturesValue[key] = true;
|
||||
});
|
||||
protectedFeatures.set(protectedFeaturesValue);
|
||||
}
|
||||
},
|
||||
{
|
||||
label: browser.i18n.getMessage("sanitation_resolution.disableMainFlag"),
|
||||
callback: function(){
|
||||
settings.set(api.mainFlag, false);
|
||||
}
|
||||
},
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "blockMode",
|
||||
check: function(errorCallback){
|
||||
const switchMode = {
|
||||
label: browser.i18n.getMessage("sanitation_resolution.switchToFakeReadout"),
|
||||
callback: function(){
|
||||
settings.blockMode = "fakeReadout";
|
||||
}
|
||||
};
|
||||
const blockMode = settings.blockMode;
|
||||
const blockModeName = browser.i18n.getMessage("blockMode_options." + blockMode);
|
||||
if (!blockMode.match("^fake|^ask")){
|
||||
errorCallback({
|
||||
message: browser.i18n.getMessage("sanitation_error.badBlockMode"),
|
||||
severity: "medium",
|
||||
resolutions: [switchMode]
|
||||
});
|
||||
}
|
||||
["Audio", "Window", "DOMRect"].forEach(function(api){
|
||||
const mainFlag = "protect" + api;
|
||||
if (settings[mainFlag]){
|
||||
if (["fakeInput"].indexOf(blockMode) !== -1){
|
||||
const blockModeName = browser.i18n.getMessage("blockMode_options." + blockMode);
|
||||
errorCallback({
|
||||
message: browser.i18n.getMessage("sanitation_error.blockModeVsProtection")
|
||||
.replace(/{blockMode}/g, blockModeName)
|
||||
.replace(/{api}/g, browser.i18n.getMessage("section_" + api + "-api")),
|
||||
severity: "high",
|
||||
resolutions: [switchMode, {
|
||||
label: browser.i18n.getMessage("sanitation_resolution.disableFlag")
|
||||
.replace(/{flag}/g, browser.i18n.getMessage(mainFlag + "_title")),
|
||||
callback: function(){
|
||||
settings[mainFlag] = false;
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
if (blockMode === "fakeInput" && settings.rng === "white"){
|
||||
errorCallback({
|
||||
message: browser.i18n.getMessage("sanitation_error.fakeInputWithWhiteRng")
|
||||
.replace(/{blockMode}/g, blockModeName),
|
||||
severity: "low",
|
||||
resolutions: [switchMode, {
|
||||
label: browser.i18n.getMessage("sanitation_resolution.switchToNonPersistendRng"),
|
||||
callback: function(){
|
||||
settings.rng = "nonPersistent";
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "thresholds",
|
||||
check: function(errorCallback){
|
||||
const setToLabel = browser.i18n.getMessage("sanitation_resolution.setTo");
|
||||
const tooLowLabel = browser.i18n.getMessage("sanitation_error.valueTooLow");
|
||||
const tooHighLabel = browser.i18n.getMessage("sanitation_error.valueTooHigh");
|
||||
if (settings.minFakeSize > 1e2){
|
||||
errorCallback({
|
||||
message: tooHighLabel
|
||||
.replace(/{setting}/g, browser.i18n.getMessage("minFakeSize_title"))
|
||||
.replace(/{value}/g, "100"),
|
||||
severity: "high",
|
||||
resolutions: [{
|
||||
label: setToLabel.replace(/{value}/g, "100"),
|
||||
callback: function(){
|
||||
settings.minFakeSize = 1e2;
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
if (settings.maxFakeSize !== 0 && settings.maxFakeSize < 1e6){
|
||||
errorCallback({
|
||||
message: tooLowLabel
|
||||
.replace(/{setting}/g, browser.i18n.getMessage("maxFakeSize_title"))
|
||||
.replace(/{value}/g, "1 000 000"),
|
||||
severity: "high",
|
||||
resolutions: [{
|
||||
label: setToLabel.replace(/{value}/g, "1 000 000"),
|
||||
callback: function(){
|
||||
settings.maxFakeSize = 1e6;
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
if (settings.ignoreFrequentColors > 3){
|
||||
errorCallback({
|
||||
message: tooHighLabel
|
||||
.replace(/{setting}/g, browser.i18n.getMessage("ignoreFrequentColors_title"))
|
||||
.replace(/{value}/g, "3"),
|
||||
severity: "high",
|
||||
resolutions: [{
|
||||
label: setToLabel.replace(/{value}/g, "3"),
|
||||
callback: function(){
|
||||
settings.ignoreFrequentColors = 3;
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
if (settings.minColors > 10){
|
||||
errorCallback({
|
||||
message: tooHighLabel
|
||||
.replace(/{setting}/g, browser.i18n.getMessage("minColors_title"))
|
||||
.replace(/{value}/g, "10"),
|
||||
severity: "high",
|
||||
resolutions: [{
|
||||
label: setToLabel.replace(/{value}/g, "10"),
|
||||
callback: function(){
|
||||
settings.ignoreFrequentColors = 10;
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "performance",
|
||||
check: function(errorCallback){
|
||||
const disableLabel = browser.i18n.getMessage("sanitation_resolution.disableFlag");
|
||||
if (settings.storeNotificationData){
|
||||
errorCallback({
|
||||
message: browser.i18n.getMessage("sanitation_error.storeNotificationData"),
|
||||
severity: "low",
|
||||
resolutions: [{
|
||||
label: disableLabel
|
||||
.replace(/{flag}/g, browser.i18n.getMessage("storeNotificationData_title")),
|
||||
callback: function(){
|
||||
settings.storeNotificationData = false;
|
||||
}
|
||||
}]
|
||||
});
|
||||
if (settings.storeImageForInspection){
|
||||
errorCallback({
|
||||
message: browser.i18n.getMessage("sanitation_error.storeImage"),
|
||||
severity: "low",
|
||||
resolutions: [{
|
||||
label: disableLabel
|
||||
.replace(/{flag}/g, browser.i18n.getMessage("storeImageForInspection_title")),
|
||||
callback: function(){
|
||||
settings.storeImageForInspection = false;
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
];
|
||||
}());
|
15
options/sanitize.css
Normal file
15
options/sanitize.css
Normal file
|
@ -0,0 +1,15 @@
|
|||
.resolutions {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.complaint.high {
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
.complaint.medium {
|
||||
background-color: orange;
|
||||
}
|
||||
|
||||
.complaint.low {
|
||||
background-color: yellow;
|
||||
}
|
17
options/sanitize.html
Normal file
17
options/sanitize.html
Normal file
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CanvasBlocker Settings Sanitation</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<link rel="stylesheet" type="text/css" media="screen" href="sanitize.css" />
|
||||
</head>
|
||||
<body>
|
||||
<script src="../lib/require.js"></script>
|
||||
<script src="../lib/logging.js"></script>
|
||||
<script src="../lib/settingDefinitions.js"></script>
|
||||
<script src="../lib/settingContainers.js"></script>
|
||||
<script src="../lib/settings.js"></script>
|
||||
<script src="sanitationRules.js"></script>
|
||||
<script src="sanitize.js"></script>
|
||||
</body>
|
||||
</html>
|
59
options/sanitize.js
Normal file
59
options/sanitize.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
/* 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 settings = require("./settings");
|
||||
|
||||
var title = document.createElement("h1");
|
||||
title.className = "title";
|
||||
title.textContent = browser.i18n.getMessage("sanitation_title");
|
||||
document.body.appendChild(title);
|
||||
|
||||
var description = document.createElement("div");
|
||||
description.className = "description";
|
||||
description.textContent = browser.i18n.getMessage("sanitation_description");
|
||||
document.body.appendChild(description);
|
||||
|
||||
settings.onloaded(function(){
|
||||
const list = document.createElement("ul");
|
||||
const sanitationRules = require("./sanitationRules");
|
||||
sanitationRules.ruleset.forEach(function(ruleset){
|
||||
const rulesetContainer = document.createElement("li");
|
||||
rulesetContainer.textContent = browser.i18n.getMessage("sanitation_ruleset." + ruleset.name);
|
||||
|
||||
const rulesetErrors = document.createElement("ul");
|
||||
let anyComplaint = false;
|
||||
ruleset.check(function({message, severity, resolutions}){
|
||||
anyComplaint = true;
|
||||
const li = document.createElement("li");
|
||||
li.className = "complaint " + severity;
|
||||
li.textContent = message;
|
||||
|
||||
const buttons = document.createElement("span");
|
||||
buttons.className = "resolutions";
|
||||
resolutions.forEach(function(resolution){
|
||||
const button = document.createElement("button");
|
||||
button.textContent = resolution.label;
|
||||
button.addEventListener("click", function(){
|
||||
resolution.callback();
|
||||
window.location.reload();
|
||||
});
|
||||
buttons.appendChild(button);
|
||||
});
|
||||
li.appendChild(buttons);
|
||||
rulesetErrors.appendChild(li);
|
||||
});
|
||||
if (!anyComplaint){
|
||||
const noComplaints = document.createElement("li");
|
||||
noComplaints.className = "noComplaints";
|
||||
noComplaints.textContent = browser.i18n.getMessage("sanitation_nothingToComplain");
|
||||
rulesetErrors.appendChild(noComplaints);
|
||||
}
|
||||
rulesetContainer.appendChild(rulesetErrors);
|
||||
list.appendChild(rulesetContainer);
|
||||
});
|
||||
document.body.appendChild(list);
|
||||
});
|
||||
}());
|
|
@ -483,6 +483,9 @@
|
|||
}
|
||||
},
|
||||
"settings",
|
||||
{
|
||||
"name": "openSettingSanitation"
|
||||
},
|
||||
{
|
||||
"name": "exportSettings",
|
||||
"actions": ["inspectSettings", "saveSettings", "loadSettings"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue