2017-07-27 19:14:04 +02:00
|
|
|
/* 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/. */
|
2017-10-03 15:35:31 +02:00
|
|
|
(function(){
|
|
|
|
"use strict";
|
2019-04-09 08:29:52 +02:00
|
|
|
|
|
|
|
const extension = require("../lib/extension");
|
2019-04-08 00:02:29 +02:00
|
|
|
const logging = require("../lib/logging");
|
2017-11-07 00:36:44 +01:00
|
|
|
logging.setPrefix("options page");
|
|
|
|
|
|
|
|
const optionsGui = require("./optionsGui");
|
2019-04-08 00:02:29 +02:00
|
|
|
const settings = require("../lib/settings");
|
|
|
|
const settingsDisplay = require("../lib/settingsDisplay");
|
|
|
|
const search = require("../lib/search");
|
|
|
|
const settingStrings = require("../lib/settingStrings");
|
2018-10-09 12:59:53 +02:00
|
|
|
const searchParameters = new URLSearchParams(window.location.search);
|
2019-04-08 00:02:29 +02:00
|
|
|
const settingsMigration = require("../lib/settingsMigration");
|
2019-05-02 00:30:30 +02:00
|
|
|
require("./theme").init("options");
|
2019-05-31 01:10:13 +02:00
|
|
|
const modal = require("../lib/modal");
|
2019-12-02 19:16:32 +01:00
|
|
|
const mobile = require("../lib/mobile");
|
2018-10-09 12:59:53 +02:00
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
const callbacks = {
|
2021-01-26 21:45:15 +01:00
|
|
|
reloadExtension: function(){
|
|
|
|
browser.runtime.reload();
|
|
|
|
},
|
2019-02-27 23:49:00 +01:00
|
|
|
openNavigatorSettings: function(){
|
|
|
|
logging.verbose("open navigator settings");
|
|
|
|
window.open("navigator.html", "_blank");
|
|
|
|
},
|
2017-11-07 00:36:44 +01:00
|
|
|
showReleaseNotes: function(){
|
|
|
|
logging.verbose("open release notes");
|
|
|
|
window.open("../releaseNotes.txt", "_blank");
|
|
|
|
},
|
|
|
|
clearPersistentRnd: function(){
|
|
|
|
logging.message("clear persistent rnd storage");
|
|
|
|
logging.notice("empty storage");
|
|
|
|
settings.persistentRndStorage = "";
|
|
|
|
logging.notice("send message to main script");
|
2021-02-21 11:49:29 +01:00
|
|
|
extension.message.send({"canvasBlocker-clear-domain-rnd": "force"});
|
2017-11-14 01:07:27 +01:00
|
|
|
},
|
2019-12-28 23:23:55 +01:00
|
|
|
clearPersistentRndForContainer: async function(){
|
|
|
|
const identities = await browser.contextualIdentities.query({});
|
|
|
|
const identity = await modal.select(
|
|
|
|
extension.getTranslation("clearPersistentRndForContainer_title"),
|
|
|
|
identities.map(function(identity){
|
|
|
|
return {
|
|
|
|
name: `${identity.name} (${identity.cookieStoreId})`,
|
|
|
|
object: identity
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
|
|
|
extension.message.send({"canvasBlocker-clear-container-rnd": identity.cookieStoreId});
|
2019-06-14 10:45:34 +02:00
|
|
|
},
|
2018-09-02 13:34:20 +02:00
|
|
|
inspectSettings: function(){
|
|
|
|
logging.verbose("open settings inspection");
|
2017-11-14 01:07:27 +01:00
|
|
|
window.open("export.html", "_blank");
|
2017-11-22 14:14:33 +01:00
|
|
|
},
|
2018-10-09 08:14:50 +02:00
|
|
|
openSettingSanitation: function(){
|
|
|
|
logging.verbose("open settings sanitation");
|
|
|
|
window.open("sanitize.html", "_blank");
|
|
|
|
},
|
2019-07-16 18:25:30 +02:00
|
|
|
openSettingPresets: function(){
|
|
|
|
logging.verbose("open setting presets");
|
|
|
|
window.open("presets.html", "_blank");
|
|
|
|
},
|
2018-09-02 13:34:20 +02:00
|
|
|
saveSettings: function(){
|
|
|
|
logging.verbose("save settings");
|
|
|
|
const data = {};
|
|
|
|
settings.forEach(function(def){
|
|
|
|
data[def.name] = def.get();
|
|
|
|
});
|
|
|
|
const blob = new Blob([JSON.stringify(data, null, "\t")], {type: "application/json"});
|
|
|
|
const link = document.createElement("a");
|
|
|
|
link.href = window.URL.createObjectURL(blob);
|
|
|
|
link.target = "_blank";
|
2019-05-28 23:59:43 +02:00
|
|
|
const now = new Date();
|
|
|
|
function format(number, digits){
|
2019-11-28 01:26:35 +01:00
|
|
|
const str = number.toFixed(0);
|
2019-05-28 23:59:43 +02:00
|
|
|
return "0".repeat(digits - str.length) + str;
|
|
|
|
}
|
|
|
|
link.download = "CanvasBlocker-settings_" +
|
|
|
|
format(now.getFullYear(), 4) + "-" +
|
|
|
|
format(now.getMonth() + 1, 2) + "-" +
|
|
|
|
format(now.getDate(), 2) + "_" +
|
|
|
|
format(now.getHours(), 2) + "-" +
|
|
|
|
format(now.getMinutes(), 2) + "-" +
|
|
|
|
format(now.getSeconds(), 2) +
|
|
|
|
".json";
|
2018-09-02 13:34:20 +02:00
|
|
|
document.body.appendChild(link);
|
|
|
|
link.click();
|
|
|
|
document.body.removeChild(link);
|
|
|
|
},
|
2019-05-04 01:12:45 +02:00
|
|
|
inspectWhitelist: function(){
|
|
|
|
logging.verbose("open whitelist inspection");
|
|
|
|
window.open("whitelist.html", "_blank");
|
|
|
|
},
|
2019-12-28 23:23:55 +01:00
|
|
|
loadSettings: async function(){
|
2018-09-02 13:34:20 +02:00
|
|
|
logging.verbose("load settings");
|
2019-12-28 23:23:55 +01:00
|
|
|
const text = await new Promise(function(resolve, reject){
|
2018-09-02 13:34:20 +02:00
|
|
|
const input = document.createElement("input");
|
|
|
|
input.type = "file";
|
2020-10-14 16:29:36 +02:00
|
|
|
input.accept = "application/json";
|
2018-09-02 13:34:20 +02:00
|
|
|
input.addEventListener("change", function(){
|
|
|
|
if (this.files.length){
|
2019-11-28 01:26:35 +01:00
|
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = function(){
|
2018-09-02 13:34:20 +02:00
|
|
|
resolve(this.result);
|
|
|
|
};
|
2019-11-28 01:26:35 +01:00
|
|
|
reader.onerror = function(error){
|
|
|
|
reject(error);
|
2018-09-02 13:34:20 +02:00
|
|
|
};
|
|
|
|
reader.readAsText(this.files[0]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
input.click();
|
2019-12-28 23:23:55 +01:00
|
|
|
});
|
2020-01-01 16:04:44 +01:00
|
|
|
const json = JSON.parse(text);
|
2019-12-28 23:23:55 +01:00
|
|
|
while (settingsMigration.transitions.hasOwnProperty(json.storageVersion)){
|
2020-01-01 16:04:44 +01:00
|
|
|
const oldVersion = json.storageVersion;
|
|
|
|
const modifiedData = settingsMigration.transitions[json.storageVersion](json);
|
|
|
|
Object.keys(modifiedData).forEach(function(key){
|
|
|
|
json[key] = modifiedData[key];
|
|
|
|
});
|
2019-12-28 23:23:55 +01:00
|
|
|
if (oldVersion === json.storageVersion){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-01-02 11:41:13 +01:00
|
|
|
delete json.storageVersion;
|
2020-01-26 00:51:18 +01:00
|
|
|
const keys = Object.keys(json).filter(function(key){
|
2019-12-28 23:23:55 +01:00
|
|
|
const setting = settings.getDefinition(key);
|
2020-01-26 00:51:18 +01:00
|
|
|
if (!setting){
|
|
|
|
logging.error("Unknown setting " + key + ".");
|
|
|
|
return false;
|
2019-12-28 23:23:55 +01:00
|
|
|
}
|
|
|
|
if (!setting.fixed && setting.invalid(json[key])){
|
2020-01-26 00:51:18 +01:00
|
|
|
logging.error("Invalid value " + json[key] + " for " + key + ".");
|
|
|
|
return false;
|
2019-03-11 22:10:34 +01:00
|
|
|
}
|
2020-01-26 00:51:18 +01:00
|
|
|
return true;
|
2019-12-28 23:23:55 +01:00
|
|
|
});
|
|
|
|
keys.forEach(function(key){
|
2020-01-02 11:41:13 +01:00
|
|
|
settings[key] = json[key];
|
2018-09-02 13:34:20 +02:00
|
|
|
});
|
|
|
|
},
|
2019-12-02 19:13:38 +01:00
|
|
|
resetSettings: async function(){
|
|
|
|
try {
|
|
|
|
const clear = await modal.confirm(
|
|
|
|
extension.getTranslation("resetSettings_confirm"),
|
|
|
|
{
|
|
|
|
node: this,
|
|
|
|
selector: ".settingRow .content"
|
|
|
|
}
|
|
|
|
);
|
2019-05-31 01:10:13 +02:00
|
|
|
if (clear){
|
2019-12-02 19:13:38 +01:00
|
|
|
await browser.storage.local.clear();
|
|
|
|
await browser.storage.local.set({storageVersion: settings.storageVersion});
|
2019-12-02 19:16:32 +01:00
|
|
|
if (await mobile.isMobile()){
|
|
|
|
await mobile.applyMobileDefaults();
|
|
|
|
}
|
2019-05-31 01:10:13 +02:00
|
|
|
}
|
2019-12-02 19:13:38 +01:00
|
|
|
}
|
|
|
|
catch (error){
|
2019-11-28 01:26:35 +01:00
|
|
|
logging.warning("Unable to reset settings:", error);
|
2019-12-02 19:13:38 +01:00
|
|
|
}
|
2017-06-25 22:11:28 +02:00
|
|
|
}
|
2017-11-07 00:36:44 +01:00
|
|
|
};
|
|
|
|
|
2019-12-28 23:23:55 +01:00
|
|
|
browser.tabs.getCurrent().then(function(tab){
|
2019-04-09 08:29:52 +02:00
|
|
|
document.querySelector("head title").textContent = extension.getTranslation("options_title");
|
2017-12-24 21:53:26 +01:00
|
|
|
let head = document.createElement("header");
|
2018-08-18 22:35:52 +02:00
|
|
|
document.body.insertBefore(head, document.body.firstChild);
|
2017-12-24 21:53:26 +01:00
|
|
|
|
2018-08-18 22:35:52 +02:00
|
|
|
if (tab.url === window.location.href){
|
|
|
|
let heading = document.createElement("h1");
|
2019-04-09 08:29:52 +02:00
|
|
|
heading.textContent = extension.getTranslation("options");
|
2018-08-18 22:35:52 +02:00
|
|
|
head.appendChild(heading);
|
|
|
|
|
|
|
|
let introduction = document.createElement("div");
|
2019-04-09 08:29:52 +02:00
|
|
|
introduction.textContent = extension.getTranslation("optionsIntroduction");
|
2018-08-18 22:35:52 +02:00
|
|
|
head.appendChild(introduction);
|
|
|
|
|
2018-10-09 12:59:53 +02:00
|
|
|
if (searchParameters.has("notice")){
|
|
|
|
let noticeName = searchParameters.get("notice") + "Notice";
|
2019-04-09 08:29:52 +02:00
|
|
|
let notice = extension.getTranslation(noticeName);
|
2018-08-18 22:35:52 +02:00
|
|
|
if (notice){
|
|
|
|
let bookmarkingNotice = document.createElement("div");
|
|
|
|
bookmarkingNotice.className = noticeName + " bookmarkNotice";
|
|
|
|
bookmarkingNotice.textContent = notice;
|
2018-08-19 00:13:43 +02:00
|
|
|
|
|
|
|
const dontShowAgain = document.createElement("label");
|
|
|
|
dontShowAgain.className = "dontShowOptionsOnUpdate";
|
|
|
|
const dontShowAgainInput = document.createElement("input");
|
|
|
|
dontShowAgainInput.type = "checkbox";
|
|
|
|
settings.onloaded(function(){
|
|
|
|
dontShowAgainInput.checked = settings.dontShowOptionsOnUpdate;
|
|
|
|
});
|
|
|
|
dontShowAgainInput.addEventListener("change", function(){
|
|
|
|
settings.dontShowOptionsOnUpdate = this.checked;
|
|
|
|
});
|
|
|
|
dontShowAgain.appendChild(dontShowAgainInput);
|
|
|
|
dontShowAgain.appendChild(
|
|
|
|
document.createTextNode(
|
2019-05-02 23:46:20 +02:00
|
|
|
" " + extension.getTranslation("dontShowOptionsOnUpdate")
|
2018-08-19 00:13:43 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
bookmarkingNotice.appendChild(dontShowAgain);
|
|
|
|
|
2018-08-18 22:35:52 +02:00
|
|
|
head.appendChild(bookmarkingNotice);
|
2018-08-19 00:13:43 +02:00
|
|
|
|
|
|
|
const newUrl = new URL(window.location.href);
|
|
|
|
newUrl.search = "";
|
|
|
|
window.history.pushState({}, "", newUrl.href);
|
2018-08-18 22:35:52 +02:00
|
|
|
}
|
2018-01-08 17:07:46 +01:00
|
|
|
}
|
2018-08-18 22:35:52 +02:00
|
|
|
|
|
|
|
document.body.classList.add("standalone");
|
2017-12-24 21:53:26 +01:00
|
|
|
}
|
2018-08-18 22:41:34 +02:00
|
|
|
else {
|
|
|
|
const linkDiv = document.createElement("div");
|
|
|
|
linkDiv.className = "optionsLink";
|
|
|
|
const link = document.createElement("a");
|
|
|
|
link.href = window.location.href;
|
|
|
|
link.target = "_blank";
|
2019-04-09 08:29:52 +02:00
|
|
|
link.textContent = extension.getTranslation("openInTab");
|
2018-08-18 22:41:34 +02:00
|
|
|
linkDiv.appendChild(link);
|
|
|
|
head.appendChild(linkDiv);
|
|
|
|
}
|
2019-12-28 23:23:55 +01:00
|
|
|
return undefined;
|
2019-11-28 01:26:35 +01:00
|
|
|
}).catch(function(error){
|
|
|
|
logging.warning("Unable to identify tab:", error);
|
2018-08-18 22:35:52 +02:00
|
|
|
});
|
2017-12-24 21:53:26 +01:00
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
const groupTabs = document.createElement("div");
|
2019-06-29 16:55:26 +02:00
|
|
|
groupTabs.classList = "groupTabs";
|
|
|
|
document.body.appendChild(groupTabs);
|
|
|
|
|
2022-01-30 17:50:59 +01:00
|
|
|
[
|
|
|
|
{
|
|
|
|
check: async function(){
|
|
|
|
if (
|
|
|
|
browser.privacy &&
|
|
|
|
browser.privacy.websites &&
|
|
|
|
browser.privacy.websites.resistFingerprinting &&
|
|
|
|
browser.privacy.websites.resistFingerprinting.get
|
|
|
|
){
|
|
|
|
return (await browser.privacy.websites.resistFingerprinting.get({})).value;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
className: "resistFingerprintingNotice",
|
|
|
|
text: "resistFingerprintingNotice"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
check: () => !window.AudioContext,
|
|
|
|
text: "settingsNotice.dom.webAudio.enabled"
|
|
|
|
},
|
|
|
|
].forEach(async function(settingsCheck){
|
|
|
|
if (await settingsCheck.check()){
|
|
|
|
const settingsNotice = document.createElement("div");
|
|
|
|
settingsNotice.className = settingsCheck.className || "settingsNotice";
|
|
|
|
settingsNotice.appendChild(
|
|
|
|
extension.parseTranslation(
|
|
|
|
extension.getTranslation(settingsCheck.text)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
document.body.insertBefore(settingsNotice, groupTabs);
|
|
|
|
}
|
|
|
|
});
|
2020-01-23 15:23:56 +01:00
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
const groups = document.createElement("ul");
|
2019-06-29 16:55:26 +02:00
|
|
|
groups.className = "groups";
|
|
|
|
groupTabs.appendChild(groups);
|
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
const table = document.createElement("table");
|
2017-11-11 23:34:59 +01:00
|
|
|
table.className = "settings " + (settings.displayDescriptions? "display": "hide") + "Descriptions";
|
|
|
|
settings.on("displayDescriptions", function(){
|
|
|
|
table.className = "settings " + (settings.displayDescriptions? "display": "hide") + "Descriptions";
|
|
|
|
});
|
2019-11-28 01:26:35 +01:00
|
|
|
const tableContainer = document.createElement("div");
|
2019-06-29 16:55:26 +02:00
|
|
|
tableContainer.classList = "tabContents";
|
|
|
|
groupTabs.appendChild(tableContainer);
|
|
|
|
|
|
|
|
tableContainer.appendChild(table);
|
2017-12-24 21:52:44 +01:00
|
|
|
|
2018-07-02 00:29:41 +02:00
|
|
|
const displayHidden = settings.getDefinition(settingsDisplay.displayHidden);
|
2018-10-09 12:59:53 +02:00
|
|
|
const searchInput = search.init();
|
2018-09-18 13:14:39 +02:00
|
|
|
table.appendChild(
|
|
|
|
optionsGui.createThead(
|
|
|
|
displayHidden,
|
2018-10-09 12:59:53 +02:00
|
|
|
searchInput
|
2018-09-18 13:14:39 +02:00
|
|
|
)
|
|
|
|
);
|
2018-10-09 12:59:53 +02:00
|
|
|
const searchOnly = searchParameters.has("searchOnly");
|
2018-09-19 09:15:19 +02:00
|
|
|
if (searchOnly){
|
|
|
|
document.body.classList.add("searching");
|
|
|
|
}
|
2018-10-09 12:59:53 +02:00
|
|
|
if (searchParameters.has("search")){
|
|
|
|
searchInput.value = searchParameters.get("search");
|
|
|
|
}
|
2018-09-18 13:14:39 +02:00
|
|
|
search.on(function({search, results, lastResults}){
|
|
|
|
lastResults.forEach(function(node){
|
|
|
|
node.classList.remove("found");
|
|
|
|
});
|
2018-09-19 09:15:19 +02:00
|
|
|
if (search || searchOnly){
|
2018-09-18 13:14:39 +02:00
|
|
|
document.body.classList.add("searching");
|
|
|
|
results.forEach(function(node){
|
|
|
|
node.classList.add("found");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.body.classList.remove("searching");
|
|
|
|
}
|
|
|
|
});
|
2018-07-02 00:29:41 +02:00
|
|
|
|
2019-06-11 13:54:15 +02:00
|
|
|
const {hide: hideContainer, expand: expandContainer} = settings.getContainers();
|
|
|
|
|
|
|
|
const addSection = function addSection(name){
|
|
|
|
const body = document.createElement("tbody");
|
2019-07-14 10:53:23 +02:00
|
|
|
body.className = "sectionBody";
|
2017-12-24 21:52:44 +01:00
|
|
|
if (name){
|
2019-06-11 13:54:15 +02:00
|
|
|
const row = document.createElement("tr");
|
2017-12-24 21:52:44 +01:00
|
|
|
row.className = "section";
|
2019-06-11 13:54:15 +02:00
|
|
|
|
|
|
|
const cell = document.createElement("td");
|
2018-07-02 00:29:41 +02:00
|
|
|
cell.colSpan = 3;
|
2017-12-24 21:52:44 +01:00
|
|
|
row.appendChild(cell);
|
2019-06-11 13:54:15 +02:00
|
|
|
|
|
|
|
const id = "section_" + name;
|
|
|
|
|
|
|
|
const heading = document.createElement("h2");
|
|
|
|
heading.textContent = extension.getTranslation(id);
|
2017-12-24 21:52:44 +01:00
|
|
|
cell.appendChild(heading);
|
2019-06-11 13:54:15 +02:00
|
|
|
|
|
|
|
if (expandContainer){
|
|
|
|
const collapser = document.createElement("span");
|
|
|
|
collapser.className = "collapser";
|
|
|
|
collapser.addEventListener("click", function(){
|
|
|
|
expandContainer.setExpandByName(id, !expandContainer.getExpandByName(id, true));
|
|
|
|
});
|
|
|
|
expandContainer.onExpandChange(id, function(value){
|
|
|
|
body.classList[value? "remove": "add"]("collapsed");
|
|
|
|
});
|
|
|
|
if (!expandContainer.getExpandByName(id, true)){
|
|
|
|
body.classList.add("collapsed");
|
|
|
|
}
|
|
|
|
heading.appendChild(collapser);
|
|
|
|
}
|
|
|
|
|
2017-12-24 21:52:44 +01:00
|
|
|
body.appendChild(row);
|
|
|
|
}
|
|
|
|
table.appendChild(body);
|
2019-06-29 16:55:26 +02:00
|
|
|
const rows = [];
|
|
|
|
const section = {
|
|
|
|
node: body,
|
2017-12-24 21:52:44 +01:00
|
|
|
addRow: function(row){
|
|
|
|
rows.push(row);
|
|
|
|
body.appendChild(row);
|
|
|
|
},
|
|
|
|
updateDisplay: function(){
|
2018-09-18 13:14:39 +02:00
|
|
|
const searchMode = document.body.classList.contains("searching");
|
2019-11-28 01:26:35 +01:00
|
|
|
let anyVisible = false;
|
2018-01-08 17:08:36 +01:00
|
|
|
rows.forEach(function(row){
|
2019-11-28 01:26:35 +01:00
|
|
|
const isHidden = row.classList.contains("hidden");
|
2018-01-08 17:08:36 +01:00
|
|
|
if (!isHidden){
|
2018-09-18 13:14:39 +02:00
|
|
|
if (searchMode){
|
|
|
|
if (!row.classList.contains("found")){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-01-08 17:08:36 +01:00
|
|
|
if (anyVisible){
|
|
|
|
row.classList.remove("firstVisible");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
anyVisible = true;
|
|
|
|
row.classList.add("firstVisible");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
body.classList[anyVisible? "remove": "add"]("hidden");
|
2017-10-03 15:35:31 +02:00
|
|
|
}
|
2017-12-24 21:52:44 +01:00
|
|
|
};
|
2018-09-18 13:14:39 +02:00
|
|
|
|
|
|
|
search.on(function(){section.updateDisplay();});
|
2019-06-29 16:55:26 +02:00
|
|
|
return section;
|
2017-12-24 21:52:44 +01:00
|
|
|
};
|
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
const addGroup = function addGroup(groupDefinition){
|
|
|
|
const sections = [];
|
|
|
|
|
|
|
|
const groupIndex = groups.childNodes.length;
|
|
|
|
const name = document.createElement("li");
|
|
|
|
name.textContent = extension.getTranslation("group_" + groupDefinition.name);
|
|
|
|
name.className = "groupName group" + groupIndex;
|
|
|
|
|
|
|
|
const group = {
|
|
|
|
select: function(){
|
|
|
|
groups.querySelectorAll(".selected").forEach(function(group){
|
|
|
|
group.classList.remove("selected");
|
|
|
|
});
|
|
|
|
table.querySelectorAll("tbody").forEach(function(section){
|
|
|
|
section.classList.remove("selectedGroup");
|
|
|
|
});
|
|
|
|
sections.forEach(function(section){
|
|
|
|
section.node.classList.add("selectedGroup");
|
|
|
|
});
|
|
|
|
name.classList.add("selected");
|
|
|
|
},
|
|
|
|
addSection: function(sectionDefinition){
|
|
|
|
const section = addSection(sectionDefinition.name);
|
|
|
|
sections.push(section);
|
|
|
|
return section;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
name.addEventListener("click", group.select);
|
|
|
|
|
|
|
|
groups.appendChild(name);
|
|
|
|
|
|
|
|
return group;
|
|
|
|
};
|
|
|
|
|
2018-10-25 13:42:18 +02:00
|
|
|
const beforeChangeEventListeners = {};
|
2019-11-28 01:26:35 +01:00
|
|
|
function setupSetterForDisplay(setting){
|
|
|
|
let originalSet = setting.set;
|
|
|
|
setting.originalSet = originalSet;
|
|
|
|
if (originalSet){
|
|
|
|
const eventListeners = [];
|
|
|
|
beforeChangeEventListeners[setting.name] = eventListeners;
|
|
|
|
setting.set = function(...args){
|
|
|
|
if (eventListeners.every(function(listener){
|
|
|
|
return listener.call(setting, ...args);
|
|
|
|
})){
|
|
|
|
return originalSet.apply(this, args);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupHideForDisplay(setting){
|
|
|
|
const display = setting.display;
|
|
|
|
const hideChangeListeners = [];
|
|
|
|
setting.setHide = function setHide(value){
|
|
|
|
if (hideContainer){
|
|
|
|
hideContainer.setHideByName(display.name, value);
|
|
|
|
if (setting.computeDependencies){
|
|
|
|
setting.computeDependencies();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
setting.onHideChange = function(listener){
|
|
|
|
hideChangeListeners.push(listener);
|
|
|
|
};
|
|
|
|
setting.getHide = function getHide(){
|
|
|
|
if (hideContainer){
|
|
|
|
return hideContainer.getHideByName(display.name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (hideContainer){
|
|
|
|
hideContainer.onHideChange(display.name, function(value){
|
|
|
|
if (setting.computeDependencies){
|
|
|
|
setting.computeDependencies();
|
|
|
|
}
|
|
|
|
hideChangeListeners.forEach(function(listener){
|
|
|
|
listener(value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function setupExpandForDisplay(setting){
|
|
|
|
const display = setting.display;
|
|
|
|
const expandChangeListeners = [];
|
|
|
|
setting.setExpand = function setExpand(value){
|
|
|
|
if (expandContainer){
|
|
|
|
expandContainer.setExpandByName(display.name, value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
setting.onExpandChange = function(listener){
|
|
|
|
expandChangeListeners.push(listener);
|
|
|
|
};
|
|
|
|
setting.getExpand = function getExpand(){
|
|
|
|
if (expandContainer){
|
|
|
|
return expandContainer.getExpandByName(display.name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (expandContainer){
|
|
|
|
expandContainer.onExpandChange(display.name, function(value){
|
|
|
|
expandChangeListeners.forEach(function(listener){
|
|
|
|
listener(value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupComputeDependenciesForDisplay(setting, section, row){
|
|
|
|
let displayDependencies = setting.display.displayDependencies || [{}];
|
|
|
|
displayDependencies = Array.isArray(displayDependencies)?
|
|
|
|
displayDependencies:
|
|
|
|
[displayDependencies];
|
|
|
|
setting.computeDependencies = function computeDependencies(){
|
|
|
|
logging.verbose("evaluate display dependencies for", setting);
|
|
|
|
row.classList[(
|
|
|
|
(
|
|
|
|
displayHidden.get() ||
|
|
|
|
!setting.getHide()
|
|
|
|
) &&
|
|
|
|
displayDependencies.some(function(displayDependency){
|
|
|
|
return Object.keys(displayDependency).every(function(key){
|
|
|
|
return displayDependency[key].indexOf(settings[key]) !== -1;
|
|
|
|
});
|
|
|
|
})
|
|
|
|
)? "remove": "add"]("hidden");
|
|
|
|
section.updateDisplay();
|
|
|
|
};
|
|
|
|
|
|
|
|
displayDependencies.forEach(function(displayDependency){
|
|
|
|
Object.keys(displayDependency).forEach(function(name){
|
|
|
|
settings.on(name, setting.computeDependencies);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
setting.computeDependencies();
|
|
|
|
displayHidden.on(setting.computeDependencies);
|
|
|
|
}
|
|
|
|
|
2019-06-29 16:55:26 +02:00
|
|
|
settingsDisplay.map(function(groupDefinition){
|
|
|
|
const group = addGroup(groupDefinition);
|
|
|
|
groupDefinition.sections.forEach(function(sectionDefinition){
|
|
|
|
const section = group.addSection(sectionDefinition);
|
|
|
|
sectionDefinition.settings.forEach(function(display){
|
2019-11-28 01:26:35 +01:00
|
|
|
let setting = settings.getDefinition(display.name);
|
2019-06-29 16:55:26 +02:00
|
|
|
if (!setting){
|
|
|
|
if (display.inputs){
|
|
|
|
setting = {
|
|
|
|
name: display.name,
|
|
|
|
inputs: display.inputs.map(settings.getDefinition)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else if (display.actions){
|
|
|
|
setting = {
|
|
|
|
name: display.name,
|
|
|
|
actions: display.actions.map(function(action){
|
|
|
|
return {
|
|
|
|
name: action,
|
|
|
|
action: callbacks[action]
|
|
|
|
};
|
|
|
|
}).filter(function(action){
|
|
|
|
return action.action;
|
|
|
|
})
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else if (callbacks[display.name]){
|
|
|
|
setting = {
|
|
|
|
name: display.name,
|
|
|
|
action: callbacks[display.name]
|
|
|
|
};
|
|
|
|
}
|
2018-09-02 13:34:20 +02:00
|
|
|
}
|
2019-06-29 16:55:26 +02:00
|
|
|
if (setting){
|
|
|
|
setting.display = display;
|
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
setupSetterForDisplay(setting);
|
|
|
|
setupHideForDisplay(setting);
|
|
|
|
setupExpandForDisplay(setting);
|
2019-06-29 16:55:26 +02:00
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
const row = optionsGui.createSettingRow(setting);
|
2019-06-29 16:55:26 +02:00
|
|
|
settingStrings.getStrings(setting).forEach(function(string){
|
|
|
|
search.register(string, row);
|
|
|
|
});
|
|
|
|
section.addRow(row);
|
2019-11-28 01:26:35 +01:00
|
|
|
|
|
|
|
setupComputeDependenciesForDisplay(setting, section, row);
|
2018-09-12 23:43:48 +02:00
|
|
|
}
|
2019-06-29 16:55:26 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return group;
|
|
|
|
})[0].select();
|
2018-08-18 21:50:04 +02:00
|
|
|
|
|
|
|
const version = document.createElement("div");
|
|
|
|
version.className = "version";
|
2021-11-01 13:18:38 +01:00
|
|
|
fetch(extension.getURL("manifest.json")).then(function(response){
|
2018-08-18 21:50:04 +02:00
|
|
|
return response.json();
|
|
|
|
}).then(function(manifest){
|
|
|
|
version.textContent = "Version " + manifest.version;
|
2019-12-28 23:23:55 +01:00
|
|
|
return manifest.version;
|
2019-11-28 01:26:35 +01:00
|
|
|
}).catch(function(error){
|
|
|
|
version.textContent = "Unable to get version: " + error;
|
2018-08-18 21:50:04 +02:00
|
|
|
});
|
|
|
|
document.body.appendChild(version);
|
2018-08-31 16:41:36 +02:00
|
|
|
|
|
|
|
settings.onloaded(function(){
|
2019-12-28 23:23:55 +01:00
|
|
|
settings.on("protectWindow", async function({newValue}){
|
2020-01-02 11:41:13 +01:00
|
|
|
if (newValue && !settings.allowWindowNameInFrames){
|
|
|
|
const addException = await modal.confirm(
|
|
|
|
extension.getTranslation("protectWindow_askReCaptchaException"),
|
|
|
|
{
|
|
|
|
node: document.querySelector("[data-storage-name=protectWindow]"),
|
|
|
|
selector: ".settingRow .content"
|
2019-12-28 23:23:55 +01:00
|
|
|
}
|
2020-01-02 11:41:13 +01:00
|
|
|
);
|
|
|
|
if (addException){
|
|
|
|
settings.set("allowWindowNameInFrames", true);
|
2018-08-31 19:37:57 +02:00
|
|
|
}
|
2018-08-31 16:41:36 +02:00
|
|
|
}
|
|
|
|
});
|
2019-05-31 01:10:13 +02:00
|
|
|
beforeChangeEventListeners.sharePersistentRndBetweenDomains.push(function(value, ...args){
|
2018-10-25 13:42:18 +02:00
|
|
|
if (value){
|
2019-05-31 01:10:13 +02:00
|
|
|
modal.confirm(
|
|
|
|
extension.getTranslation("sharePersistentRndBetweenDomains_confirmMessage"),
|
|
|
|
{
|
|
|
|
node: document.querySelector("[data-storage-name=sharePersistentRndBetweenDomains]"),
|
|
|
|
selector: ".settingRow .content"
|
|
|
|
}
|
|
|
|
).then((reallyShare) => {
|
|
|
|
if (reallyShare){
|
2019-11-28 01:26:35 +01:00
|
|
|
return this.originalSet(value, ...args);
|
2019-05-31 01:10:13 +02:00
|
|
|
}
|
2019-12-01 01:25:39 +01:00
|
|
|
return false;
|
2019-11-28 01:26:35 +01:00
|
|
|
}).catch(function(error){
|
|
|
|
logging.warning("Unable to set sharePersistentRndBetweenDomains:", error);
|
2019-05-31 01:10:13 +02:00
|
|
|
});
|
|
|
|
return false;
|
2018-10-25 13:42:18 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2018-08-31 16:41:36 +02:00
|
|
|
});
|
2018-10-09 12:59:53 +02:00
|
|
|
|
|
|
|
searchInput.search();
|
2017-10-03 19:51:03 +02:00
|
|
|
}());
|