1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +01:00

Moved i18n to extension module

This commit is contained in:
kkapsner 2019-04-09 08:29:52 +02:00
parent d89bfe4cb0
commit bab7d1496f
17 changed files with 101 additions and 85 deletions

View File

@ -7,8 +7,8 @@ const util = require("util");
function getMessagesInContent(content){ function getMessagesInContent(content){
const foundMessages = []; const foundMessages = [];
[ [
/\b(?:_|browser.i18n.getMessage|notify)\(["']([^"']+)["']\s*(?:\)|,)/g, /\b(?:_|browser.i18n.getMessage|notify|extension)\(["']([^"']+)["']\s*(?:\)|,)/g,
/\b(?:messageId|name)\s*:\s*["']([^"']+)["']/g, /\b(?:messageId|name|getTranslation)\s*:\s*["']([^"']+)["']/g,
].forEach(function(re){ ].forEach(function(re){
let match; let match;
while ((match = re.exec(content)) !== null){ while ((match = re.exec(content)) !== null){

View File

@ -8,6 +8,7 @@
<body> <body>
<div id="actions"></div> <div id="actions"></div>
<script src="../lib/require.js"></script> <script src="../lib/require.js"></script>
<script src="../lib/extension.js"></script>
<script src="../lib/logging.js"></script> <script src="../lib/logging.js"></script>
<script src="../lib/settingDefinitions.js"></script> <script src="../lib/settingDefinitions.js"></script>
<script src="../lib/settingContainers.js"></script> <script src="../lib/settingContainers.js"></script>

View File

@ -4,6 +4,7 @@
(function(){ (function(){
"use strict"; "use strict";
const extension = require("../lib/extension");
const logging = require("../lib/logging"); const logging = require("../lib/logging");
const settings = require("../lib/settings"); const settings = require("../lib/settings");
logging.message("Opened browser action"); logging.message("Opened browser action");
@ -73,7 +74,7 @@
actionButton.appendChild( actionButton.appendChild(
document.createTextNode( document.createTextNode(
browser.i18n.getMessage("browserAction_" + action.label) || action.label extension.getTranslation("browserAction_" + action.label) || action.label
) )
); );
actionButton.addEventListener("click", action.action); actionButton.addEventListener("click", action.action);
@ -81,7 +82,7 @@
}); });
var search = document.createElement("input"); var search = document.createElement("input");
search.placeholder = browser.i18n.getMessage("search"); search.placeholder = extension.getTranslation("search");
search.className = "search action"; search.className = "search action";
actions.appendChild(search); actions.appendChild(search);
search.focus(); search.focus();

View File

@ -12,6 +12,7 @@
scope = require.register("./notification", {}); scope = require.register("./notification", {});
} }
const extension = require("./extension");
const settings = require("./settings"); const settings = require("./settings");
const lists = require("./lists"); const lists = require("./lists");
const logging = require("./logging"); const logging = require("./logging");
@ -109,15 +110,15 @@
let apiList = ""; let apiList = "";
apis.forEach(function(api){ apis.forEach(function(api){
apiList += browser.i18n.getMessage("browserAction_title_protectedAPIs").replace(/{api}/g, api); apiList += extension.getTranslation("browserAction_title_protectedAPIs").replace(/{api}/g, api);
}); });
let browserActionTitle = browser.i18n.getMessage("browserAction_title_default"); let browserActionTitle = extension.getTranslation("browserAction_title_default");
if (tabData.whitelisted){ if (tabData.whitelisted){
browserActionTitle += browser.i18n.getMessage("browserAction_title_whitelisted") browserActionTitle += extension.getTranslation("browserAction_title_whitelisted")
.replace(/{url}/g, tabData.url); .replace(/{url}/g, tabData.url);
} }
browserActionTitle += browser.i18n.getMessage("browserAction_title_notified"); browserActionTitle += extension.getTranslation("browserAction_title_notified");
browserActionTitle += apiList; browserActionTitle += apiList;
browser.browserAction.setTitle({ browser.browserAction.setTitle({
tabId: tabId, tabId: tabId,
@ -152,9 +153,9 @@
text: "" text: ""
}); });
} }
let browserActionTitle = browser.i18n.getMessage("browserAction_title_default"); let browserActionTitle = extension.getTranslation("browserAction_title_default");
if (tabData.whitelisted){ if (tabData.whitelisted){
browserActionTitle += browser.i18n.getMessage("browserAction_title_whitelisted").replace(/{url}/g, url); browserActionTitle += extension.getTranslation("browserAction_title_whitelisted").replace(/{url}/g, url);
} }
browser.browserAction.setTitle({ browser.browserAction.setTitle({
tabId: tabId, tabId: tabId,

View File

@ -12,6 +12,7 @@
scope = require.register("./search", {}); scope = require.register("./search", {});
} }
const extension = require("./extension");
const texts = []; const texts = [];
scope.register = function(text, content){ scope.register = function(text, content){
@ -52,7 +53,7 @@
scope.init = function(){ scope.init = function(){
const node = document.createElement("input"); const node = document.createElement("input");
node.id = "search"; node.id = "search";
node.placeholder = browser.i18n.getMessage("search"); node.placeholder = extension.getTranslation("search");
window.setTimeout(() => node.focus(), 1); window.setTimeout(() => node.focus(), 1);
let lastResults = []; let lastResults = [];
node.addEventListener("input", function(){ node.addEventListener("input", function(){

View File

@ -12,6 +12,8 @@
scope = require.register("./settingStrings", {}); scope = require.register("./settingStrings", {});
} }
const extension = require("./extension");
scope.getMessages = function(settingDefinition){ scope.getMessages = function(settingDefinition){
const messages = []; const messages = [];
if (settingDefinition){ if (settingDefinition){
@ -68,7 +70,7 @@
} }
scope.getMessages(settingDefinition).forEach(function(message){ scope.getMessages(settingDefinition).forEach(function(message){
addString(browser.i18n.getMessage(message)); addString(extension.getTranslation(message));
}); });
return strings; return strings;

View File

@ -8,6 +8,7 @@
<body> <body>
<textarea id="settings"></textarea> <textarea id="settings"></textarea>
<script src="../lib/require.js"></script> <script src="../lib/require.js"></script>
<script src="../lib/extension.js"></script>
<script src="../lib/logging.js"></script> <script src="../lib/logging.js"></script>
<script src="../lib/settingDefinitions.js"></script> <script src="../lib/settingDefinitions.js"></script>
<script src="../lib/settingContainers.js"></script> <script src="../lib/settingContainers.js"></script>

View File

@ -7,6 +7,7 @@
</head> </head>
<body> <body>
<script src="../lib/require.js"></script> <script src="../lib/require.js"></script>
<script src="../lib/extension.js"></script>
<script src="../lib/logging.js"></script> <script src="../lib/logging.js"></script>
<script src="../lib/settingDefinitions.js"></script> <script src="../lib/settingDefinitions.js"></script>
<script src="../lib/settingContainers.js"></script> <script src="../lib/settingContainers.js"></script>

View File

@ -4,19 +4,20 @@
(function(){ (function(){
"use strict"; "use strict";
const extension = require("../lib/extension");
const settings = require("../lib/settings"); const settings = require("../lib/settings");
const navigator = require("../lib/navigator"); const navigator = require("../lib/navigator");
const title = document.createElement("h1"); const title = document.createElement("h1");
title.className = "title"; title.className = "title";
title.textContent = browser.i18n.getMessage("navigatorSettings_title"); title.textContent = extension.getTranslation("navigatorSettings_title");
document.body.appendChild(title); document.body.appendChild(title);
document.querySelector("head title").textContent = title.textContent; document.querySelector("head title").textContent = title.textContent;
const description = document.createElement("div"); const description = document.createElement("div");
description.className = "description"; description.className = "description";
description.textContent = browser.i18n.getMessage("navigatorSettings_description"); description.textContent = extension.getTranslation("navigatorSettings_description");
document.body.appendChild(description); document.body.appendChild(description);
function presetSection(title, presets){ function presetSection(title, presets){
@ -25,7 +26,7 @@
const titleNode = document.createElement("h2"); const titleNode = document.createElement("h2");
titleNode.className = "title"; titleNode.className = "title";
titleNode.textContent = browser.i18n.getMessage("navigatorSettings_presetSection." + title); titleNode.textContent = extension.getTranslation("navigatorSettings_presetSection." + title);
container.appendChild(titleNode); container.appendChild(titleNode);
const presetsList = document.createElement("ul"); const presetsList = document.createElement("ul");
@ -171,7 +172,7 @@
document.body.appendChild(presetSection("browser", browserPresets)); document.body.appendChild(presetSection("browser", browserPresets));
const valueTitle = document.createElement("h2"); const valueTitle = document.createElement("h2");
valueTitle.textContent = browser.i18n.getMessage("navigatorSettings_values"); valueTitle.textContent = extension.getTranslation("navigatorSettings_values");
document.body.appendChild(valueTitle); document.body.appendChild(valueTitle);
const valueSection = document.createElement("table"); const valueSection = document.createElement("table");
@ -229,7 +230,7 @@
const resetButton = document.createElement("button"); const resetButton = document.createElement("button");
resetButton.className = "button"; resetButton.className = "button";
resetButton.textContent = browser.i18n.getMessage("navigatorSettings_reset"); resetButton.textContent = extension.getTranslation("navigatorSettings_reset");
resetButton.addEventListener("click", function(){ resetButton.addEventListener("click", function(){
settings.navigatorDetails = {}; settings.navigatorDetails = {};
}); });

View File

@ -7,6 +7,7 @@
</head> </head>
<body> <body>
<script src="../lib/require.js"></script> <script src="../lib/require.js"></script>
<script src="../lib/extension.js"></script>
<script src="../lib/logging.js"></script> <script src="../lib/logging.js"></script>
<script src="../lib/settingDefinitions.js"></script> <script src="../lib/settingDefinitions.js"></script>
<script src="../lib/settingContainers.js"></script> <script src="../lib/settingContainers.js"></script>

View File

@ -3,7 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
(function(){ (function(){
"use strict"; "use strict";
const extension = require("../lib/extension");
const logging = require("../lib/logging"); const logging = require("../lib/logging");
logging.setPrefix("options page"); logging.setPrefix("options page");
@ -101,7 +102,7 @@
}); });
}, },
resetSettings: function(){ resetSettings: function(){
if (window.confirm(browser.i18n.getMessage("resetSettings_confirm"))){ if (window.confirm(extension.getTranslation("resetSettings_confirm"))){
browser.storage.local.clear(); browser.storage.local.clear();
} }
} }
@ -119,22 +120,22 @@
}).then(function(tabId){ }).then(function(tabId){
return browser.tabs.get(tabId); return browser.tabs.get(tabId);
}).then(function(tab){ }).then(function(tab){
document.querySelector("head title").textContent = browser.i18n.getMessage("options_title"); document.querySelector("head title").textContent = extension.getTranslation("options_title");
let head = document.createElement("header"); let head = document.createElement("header");
document.body.insertBefore(head, document.body.firstChild); document.body.insertBefore(head, document.body.firstChild);
if (tab.url === window.location.href){ if (tab.url === window.location.href){
let heading = document.createElement("h1"); let heading = document.createElement("h1");
heading.textContent = browser.i18n.getMessage("options"); heading.textContent = extension.getTranslation("options");
head.appendChild(heading); head.appendChild(heading);
let introduction = document.createElement("div"); let introduction = document.createElement("div");
introduction.textContent = browser.i18n.getMessage("optionsIntroduction"); introduction.textContent = extension.getTranslation("optionsIntroduction");
head.appendChild(introduction); head.appendChild(introduction);
if (searchParameters.has("notice")){ if (searchParameters.has("notice")){
let noticeName = searchParameters.get("notice") + "Notice"; let noticeName = searchParameters.get("notice") + "Notice";
let notice = browser.i18n.getMessage(noticeName); let notice = extension.getTranslation(noticeName);
if (notice){ if (notice){
let bookmarkingNotice = document.createElement("div"); let bookmarkingNotice = document.createElement("div");
bookmarkingNotice.className = noticeName + " bookmarkNotice"; bookmarkingNotice.className = noticeName + " bookmarkNotice";
@ -153,7 +154,7 @@
dontShowAgain.appendChild(dontShowAgainInput); dontShowAgain.appendChild(dontShowAgainInput);
dontShowAgain.appendChild( dontShowAgain.appendChild(
document.createTextNode( document.createTextNode(
browser.i18n.getMessage("dontShowOptionsOnUpdate") extension.getTranslation("dontShowOptionsOnUpdate")
) )
); );
bookmarkingNotice.appendChild(dontShowAgain); bookmarkingNotice.appendChild(dontShowAgain);
@ -174,7 +175,7 @@
const link = document.createElement("a"); const link = document.createElement("a");
link.href = window.location.href; link.href = window.location.href;
link.target = "_blank"; link.target = "_blank";
link.textContent = browser.i18n.getMessage("openInTab"); link.textContent = extension.getTranslation("openInTab");
linkDiv.appendChild(link); linkDiv.appendChild(link);
head.appendChild(linkDiv); head.appendChild(linkDiv);
} }
@ -227,7 +228,7 @@
cell.colSpan = 3; cell.colSpan = 3;
row.appendChild(cell); row.appendChild(cell);
let heading = document.createElement("h2"); let heading = document.createElement("h2");
heading.textContent = browser.i18n.getMessage("section_" + name); heading.textContent = extension.getTranslation("section_" + name);
cell.appendChild(heading); cell.appendChild(heading);
body.appendChild(row); body.appendChild(row);
} }
@ -441,7 +442,7 @@
matching.length === 0 || matching.length === 0 ||
matching[0].protectWindow matching[0].protectWindow
) && ) &&
window.confirm(browser.i18n.getMessage("protectWindow_askReCaptchaException")) window.confirm(extension.getTranslation("protectWindow_askReCaptchaException"))
){ ){
settings.set("protectWindow", false, reCaptchaEntry); settings.set("protectWindow", false, reCaptchaEntry);
} }
@ -449,7 +450,7 @@
}); });
beforeChangeEventListeners.sharePersistentRndBetweenDomains.push(function(value){ beforeChangeEventListeners.sharePersistentRndBetweenDomains.push(function(value){
if (value){ if (value){
if (!confirm(browser.i18n.getMessage("sharePersistentRndBetweenDomains_confirmMessage"))){ if (!confirm(extension.getTranslation("sharePersistentRndBetweenDomains_confirmMessage"))){
return false; return false;
} }
} }

View File

@ -11,7 +11,8 @@
else { else {
scope = require.register("./optionsGui", {}); scope = require.register("./optionsGui", {});
} }
const extension = require("../lib/extension");
const logging = require("../lib/logging"); const logging = require("../lib/logging");
function createDescription(setting){ function createDescription(setting){
@ -20,12 +21,12 @@
var title = document.createElement("span"); var title = document.createElement("span");
title.className = "title"; title.className = "title";
title.textContent = browser.i18n.getMessage(setting.name + "_title"); title.textContent = extension.getTranslation(setting.name + "_title");
c.appendChild(title); c.appendChild(title);
var descriptionText = browser.i18n.getMessage(setting.name + "_description"); var descriptionText = extension.getTranslation(setting.name + "_description");
if (setting.urlSpecific){ if (setting.urlSpecific){
const urlSpecificDescription = browser.i18n.getMessage(setting.name + "_urlSpecific"); const urlSpecificDescription = extension.getTranslation(setting.name + "_urlSpecific");
if (urlSpecificDescription){ if (urlSpecificDescription){
descriptionText += (descriptionText? "\n\n": "") + urlSpecificDescription; descriptionText += (descriptionText? "\n\n": "") + urlSpecificDescription;
} }
@ -53,7 +54,7 @@
if (setting.defaultValue === value){ if (setting.defaultValue === value){
option.selected = true; option.selected = true;
} }
option.text = browser.i18n.getMessage(setting.name + "_options." + value) || value; option.text = extension.getTranslation(setting.name + "_options." + value) || value;
} }
else { else {
option.disabled = true; option.disabled = true;
@ -156,7 +157,7 @@
let cell = document.createElement("td"); let cell = document.createElement("td");
cell.colSpan = 2; cell.colSpan = 2;
let h = document.createElement("h" + (2 + (key.level || 1))); let h = document.createElement("h" + (2 + (key.level || 1)));
h.textContent = key.message? browser.i18n.getMessage(key.message): key.name; h.textContent = key.message? extension.getTranslation(key.message): key.name;
cell.appendChild(h); cell.appendChild(h);
row.appendChild(cell); row.appendChild(cell);
input.appendChild(row); input.appendChild(row);
@ -227,7 +228,7 @@
}); });
let urlTable = document.createElement("table"); let urlTable = document.createElement("table");
let caption = document.createElement("caption"); let caption = document.createElement("caption");
caption.textContent = browser.i18n.getMessage(setting.urlContainer.name + "_title"); caption.textContent = extension.getTranslation(setting.urlContainer.name + "_title");
urlTable.appendChild(caption); urlTable.appendChild(caption);
let body = document.createElement("tbody"); let body = document.createElement("tbody");
urlTable.appendChild(body); urlTable.appendChild(body);
@ -236,7 +237,7 @@
let footCell = document.createElement("td"); let footCell = document.createElement("td");
footCell.colSpan = 3; footCell.colSpan = 3;
let newInput = document.createElement("input"); let newInput = document.createElement("input");
newInput.title = browser.i18n.getMessage("inputURL"); newInput.title = extension.getTranslation("inputURL");
const addURLSetting = function(){ const addURLSetting = function(){
var url = newInput.value.trim(); var url = newInput.value.trim();
if (url){ if (url){
@ -274,7 +275,7 @@
input.style.height = urlCell.clientHeight + "px"; input.style.height = urlCell.clientHeight + "px";
urlCell.innerHTML = ""; urlCell.innerHTML = "";
urlCell.appendChild(input); urlCell.appendChild(input);
input.title = browser.i18n.getMessage("inputURL"); input.title = extension.getTranslation("inputURL");
input.value = entry.url; input.value = entry.url;
input.focus(); input.focus();
input.addEventListener("blur", function(){ input.addEventListener("blur", function(){
@ -316,7 +317,7 @@
function createButton(setting){ function createButton(setting){
var button = document.createElement("button"); var button = document.createElement("button");
button.textContent = browser.i18n.getMessage(setting.name + "_label"); button.textContent = extension.getTranslation(setting.name + "_label");
button.addEventListener("click", setting.action); button.addEventListener("click", setting.action);
return button; return button;
} }
@ -359,7 +360,7 @@
function createHide(setting){ function createHide(setting){
var label = document.createElement("label"); var label = document.createElement("label");
label.className = "content hideContent"; label.className = "content hideContent";
label.title = browser.i18n.getMessage("hideSetting"); label.title = extension.getTranslation("hideSetting");
var input = document.createElement("input"); var input = document.createElement("input");
input.type = "checkbox"; input.type = "checkbox";
input.className = "hide"; input.className = "hide";
@ -405,7 +406,7 @@
const headRow = document.createElement("tr"); const headRow = document.createElement("tr");
const hideHeadCell = document.createElement("td"); const hideHeadCell = document.createElement("td");
hideHeadCell.className = "hideColumn"; hideHeadCell.className = "hideColumn";
hideHeadCell.title = browser.i18n.getMessage(displayHidden.name + "_description"); hideHeadCell.title = extension.getTranslation(displayHidden.name + "_description");
const label = document.createElement("label"); const label = document.createElement("label");
label.className = "hideContent"; label.className = "hideContent";
const input = createInput(displayHidden); const input = createInput(displayHidden);

View File

@ -12,6 +12,7 @@
scope = require.register("./sanitationRules", {}); scope = require.register("./sanitationRules", {});
} }
const extension = require("../lib/extension");
const settings = require("../lib/settings"); const settings = require("../lib/settings");
scope.ruleset = [ scope.ruleset = [
@ -20,11 +21,11 @@
check: function(errorCallback){ check: function(errorCallback){
const {url: urlContainer} = settings.getContainers(); const {url: urlContainer} = settings.getContainers();
const containerValue = urlContainer.get(); const containerValue = urlContainer.get();
const errorMessage = browser.i18n.getMessage("sanitation_error.unnecessaryURLValue"); const errorMessage = extension.getTranslation("sanitation_error.unnecessaryURLValue");
function createErrorMessage(setting, urlValue){ function createErrorMessage(setting, urlValue){
return errorMessage return errorMessage
.replace(/{setting-technical}/g, setting.name) .replace(/{setting-technical}/g, setting.name)
.replace(/{setting-title}/g, browser.i18n.getMessage(setting.name + "_title")) .replace(/{setting-title}/g, extension.getTranslation(setting.name + "_title"))
.replace(/{url}/g, urlValue.url); .replace(/{url}/g, urlValue.url);
} }
containerValue.forEach(function(urlValues){ containerValue.forEach(function(urlValues){
@ -39,7 +40,7 @@
message: createErrorMessage(setting, urlValues), message: createErrorMessage(setting, urlValues),
severity: "low", severity: "low",
resolutions: [{ resolutions: [{
label: browser.i18n.getMessage("sanitation_resolution.removeURLValue"), label: extension.getTranslation("sanitation_resolution.removeURLValue"),
callback: function(){ callback: function(){
setting.reset(urlValues.url); setting.reset(urlValues.url);
} }
@ -54,9 +55,9 @@
{ {
name: "disabledFeatures", name: "disabledFeatures",
check: function(errorCallback){ check: function(errorCallback){
const errorMessage = browser.i18n.getMessage("sanitation_error.disabledFeatures"); const errorMessage = extension.getTranslation("sanitation_error.disabledFeatures");
function createErrorMessage(api){ function createErrorMessage(api){
return errorMessage.replace(/{api}/g, browser.i18n.getMessage("section_" + api.section)); return errorMessage.replace(/{api}/g, extension.getTranslation("section_" + api.section));
} }
const protectedFeatures = settings.getDefinition("protectedAPIFeatures"); const protectedFeatures = settings.getDefinition("protectedAPIFeatures");
const protectedFeaturesValue = protectedFeatures.get(); const protectedFeaturesValue = protectedFeatures.get();
@ -91,7 +92,7 @@
severity: "high", severity: "high",
resolutions: [ resolutions: [
{ {
label: browser.i18n.getMessage("sanitation_resolution.enableFeatures"), label: extension.getTranslation("sanitation_resolution.enableFeatures"),
callback: function(){ callback: function(){
const protectedFeaturesValue = protectedFeatures.get(); const protectedFeaturesValue = protectedFeatures.get();
getSectionKeys(api.section).forEach(function(key){ getSectionKeys(api.section).forEach(function(key){
@ -101,7 +102,7 @@
} }
}, },
{ {
label: browser.i18n.getMessage("sanitation_resolution.disableMainFlag"), label: extension.getTranslation("sanitation_resolution.disableMainFlag"),
callback: function(){ callback: function(){
settings.set(api.mainFlag, false); settings.set(api.mainFlag, false);
} }
@ -120,10 +121,10 @@
const protectedCanvasPart = settings.protectedCanvasPart; const protectedCanvasPart = settings.protectedCanvasPart;
if (!blockMode.match("^fake|^ask")){ if (!blockMode.match("^fake|^ask")){
errorCallback({ errorCallback({
message: browser.i18n.getMessage("sanitation_error.badBlockMode"), message: extension.getTranslation("sanitation_error.badBlockMode"),
severity: "medium", severity: "medium",
resolutions: [{ resolutions: [{
label: browser.i18n.getMessage("sanitation_resolution.switchToFake"), label: extension.getTranslation("sanitation_resolution.switchToFake"),
callback: function(){ callback: function(){
settings.blockMode = "fake"; settings.blockMode = "fake";
} }
@ -132,22 +133,22 @@
} }
if (blockMode === "fake" && protectedCanvasPart === "input" && settings.rng === "white"){ if (blockMode === "fake" && protectedCanvasPart === "input" && settings.rng === "white"){
errorCallback({ errorCallback({
message: browser.i18n.getMessage("sanitation_error.fakeInputWithWhiteRng") message: extension.getTranslation("sanitation_error.fakeInputWithWhiteRng")
.replace(/{blockMode}/g, browser.i18n.getMessage("blockMode_options." + blockMode)) .replace(/{blockMode}/g, extension.getTranslation("blockMode_options." + blockMode))
.replace( .replace(
/{protectedCanvasPart}/g, /{protectedCanvasPart}/g,
browser.i18n.getMessage("protectedCanvasPart_options." + settings.protectedCanvasPart) extension.getTranslation("protectedCanvasPart_options." + settings.protectedCanvasPart)
), ),
severity: "low", severity: "low",
resolutions: [ resolutions: [
{ {
label: browser.i18n.getMessage("sanitation_resolution.switchToProtectReadout"), label: extension.getTranslation("sanitation_resolution.switchToProtectReadout"),
callback: function(){ callback: function(){
settings.protectedCanvasPart = "readout"; settings.protectedCanvasPart = "readout";
} }
}, },
{ {
label: browser.i18n.getMessage("sanitation_resolution.switchToNonPersistentRng"), label: extension.getTranslation("sanitation_resolution.switchToNonPersistentRng"),
callback: function(){ callback: function(){
settings.rng = "nonPersistent"; settings.rng = "nonPersistent";
} }
@ -157,22 +158,22 @@
} }
if (blockMode === "fake" && protectedCanvasPart === "everything"){ if (blockMode === "fake" && protectedCanvasPart === "everything"){
errorCallback({ errorCallback({
message: browser.i18n.getMessage("sanitation_error.fakeEverythingInCanvas") message: extension.getTranslation("sanitation_error.fakeEverythingInCanvas")
.replace(/{blockMode}/g, browser.i18n.getMessage("blockMode_options." + blockMode)) .replace(/{blockMode}/g, extension.getTranslation("blockMode_options." + blockMode))
.replace( .replace(
/{protectedCanvasPart}/g, /{protectedCanvasPart}/g,
browser.i18n.getMessage("protectedCanvasPart_options." + settings.protectedCanvasPart) extension.getTranslation("protectedCanvasPart_options." + settings.protectedCanvasPart)
), ),
severity: "low", severity: "low",
resolutions: [ resolutions: [
{ {
label: browser.i18n.getMessage("sanitation_resolution.switchToProtectReadout"), label: extension.getTranslation("sanitation_resolution.switchToProtectReadout"),
callback: function(){ callback: function(){
settings.protectedCanvasPart = "readout"; settings.protectedCanvasPart = "readout";
} }
}, },
{ {
label: browser.i18n.getMessage("sanitation_resolution.switchToProtectInput"), label: extension.getTranslation("sanitation_resolution.switchToProtectInput"),
callback: function(){ callback: function(){
settings.protectedCanvasPart = "input"; settings.protectedCanvasPart = "input";
} }
@ -185,13 +186,13 @@
{ {
name: "thresholds", name: "thresholds",
check: function(errorCallback){ check: function(errorCallback){
const setToLabel = browser.i18n.getMessage("sanitation_resolution.setTo"); const setToLabel = extension.getTranslation("sanitation_resolution.setTo");
const tooLowLabel = browser.i18n.getMessage("sanitation_error.valueTooLow"); const tooLowLabel = extension.getTranslation("sanitation_error.valueTooLow");
const tooHighLabel = browser.i18n.getMessage("sanitation_error.valueTooHigh"); const tooHighLabel = extension.getTranslation("sanitation_error.valueTooHigh");
if (settings.minFakeSize > 1e2){ if (settings.minFakeSize > 1e2){
errorCallback({ errorCallback({
message: tooHighLabel message: tooHighLabel
.replace(/{setting}/g, browser.i18n.getMessage("minFakeSize_title")) .replace(/{setting}/g, extension.getTranslation("minFakeSize_title"))
.replace(/{value}/g, "100"), .replace(/{value}/g, "100"),
severity: "high", severity: "high",
resolutions: [{ resolutions: [{
@ -205,7 +206,7 @@
if (settings.maxFakeSize !== 0 && settings.maxFakeSize < 1e6){ if (settings.maxFakeSize !== 0 && settings.maxFakeSize < 1e6){
errorCallback({ errorCallback({
message: tooLowLabel message: tooLowLabel
.replace(/{setting}/g, browser.i18n.getMessage("maxFakeSize_title")) .replace(/{setting}/g, extension.getTranslation("maxFakeSize_title"))
.replace(/{value}/g, "1 000 000"), .replace(/{value}/g, "1 000 000"),
severity: "high", severity: "high",
resolutions: [{ resolutions: [{
@ -219,7 +220,7 @@
if (settings.ignoreFrequentColors > 3){ if (settings.ignoreFrequentColors > 3){
errorCallback({ errorCallback({
message: tooHighLabel message: tooHighLabel
.replace(/{setting}/g, browser.i18n.getMessage("ignoreFrequentColors_title")) .replace(/{setting}/g, extension.getTranslation("ignoreFrequentColors_title"))
.replace(/{value}/g, "3"), .replace(/{value}/g, "3"),
severity: "high", severity: "high",
resolutions: [{ resolutions: [{
@ -233,7 +234,7 @@
if (settings.minColors > 10){ if (settings.minColors > 10){
errorCallback({ errorCallback({
message: tooHighLabel message: tooHighLabel
.replace(/{setting}/g, browser.i18n.getMessage("minColors_title")) .replace(/{setting}/g, extension.getTranslation("minColors_title"))
.replace(/{value}/g, "10"), .replace(/{value}/g, "10"),
severity: "high", severity: "high",
resolutions: [{ resolutions: [{
@ -249,14 +250,14 @@
{ {
name: "performance", name: "performance",
check: function(errorCallback){ check: function(errorCallback){
const disableLabel = browser.i18n.getMessage("sanitation_resolution.disableFlag"); const disableLabel = extension.getTranslation("sanitation_resolution.disableFlag");
if (settings.storeNotificationData){ if (settings.storeNotificationData){
errorCallback({ errorCallback({
message: browser.i18n.getMessage("sanitation_error.storeNotificationData"), message: extension.getTranslation("sanitation_error.storeNotificationData"),
severity: "low", severity: "low",
resolutions: [{ resolutions: [{
label: disableLabel label: disableLabel
.replace(/{flag}/g, browser.i18n.getMessage("storeNotificationData_title")), .replace(/{flag}/g, extension.getTranslation("storeNotificationData_title")),
callback: function(){ callback: function(){
settings.storeNotificationData = false; settings.storeNotificationData = false;
} }
@ -264,11 +265,11 @@
}); });
if (settings.storeImageForInspection){ if (settings.storeImageForInspection){
errorCallback({ errorCallback({
message: browser.i18n.getMessage("sanitation_error.storeImage"), message: extension.getTranslation("sanitation_error.storeImage"),
severity: "low", severity: "low",
resolutions: [{ resolutions: [{
label: disableLabel label: disableLabel
.replace(/{flag}/g, browser.i18n.getMessage("storeImageForInspection_title")), .replace(/{flag}/g, extension.getTranslation("storeImageForInspection_title")),
callback: function(){ callback: function(){
settings.storeImageForInspection = false; settings.storeImageForInspection = false;
} }
@ -283,11 +284,11 @@
check: function(errorCallback){ check: function(errorCallback){
if (settings.sharePersistentRndBetweenDomains){ if (settings.sharePersistentRndBetweenDomains){
errorCallback({ errorCallback({
message: browser.i18n.getMessage("sanitation_error.doNotSharePersistentRndBetweenDomains"), message: extension.getTranslation("sanitation_error.doNotSharePersistentRndBetweenDomains"),
severity: "high", severity: "high",
resolutions: [{ resolutions: [{
label: browser.i18n.getMessage("sanitation_resolution.disableFlag") label: extension.getTranslation("sanitation_resolution.disableFlag")
.replace(/{flag}/g, browser.i18n.getMessage("sharePersistentRndBetweenDomains_title")), .replace(/{flag}/g, extension.getTranslation("sharePersistentRndBetweenDomains_title")),
callback: function(){ callback: function(){
settings.sharePersistentRndBetweenDomains = false; settings.sharePersistentRndBetweenDomains = false;
} }

View File

@ -7,6 +7,7 @@
</head> </head>
<body> <body>
<script src="../lib/require.js"></script> <script src="../lib/require.js"></script>
<script src="../lib/extension.js"></script>
<script src="../lib/logging.js"></script> <script src="../lib/logging.js"></script>
<script src="../lib/settingDefinitions.js"></script> <script src="../lib/settingDefinitions.js"></script>
<script src="../lib/settingContainers.js"></script> <script src="../lib/settingContainers.js"></script>

View File

@ -4,24 +4,25 @@
(function(){ (function(){
"use strict"; "use strict";
const extension = require("../lib/extension");
const settings = require("../lib/settings"); const settings = require("../lib/settings");
const sanitationRules = require("./sanitationRules"); const sanitationRules = require("./sanitationRules");
var title = document.createElement("h1"); var title = document.createElement("h1");
title.className = "title"; title.className = "title";
title.textContent = browser.i18n.getMessage("sanitation_title"); title.textContent = extension.getTranslation("sanitation_title");
document.body.appendChild(title); document.body.appendChild(title);
var description = document.createElement("div"); var description = document.createElement("div");
description.className = "description"; description.className = "description";
description.textContent = browser.i18n.getMessage("sanitation_description"); description.textContent = extension.getTranslation("sanitation_description");
document.body.appendChild(description); document.body.appendChild(description);
settings.onloaded(function(){ settings.onloaded(function(){
const list = document.createElement("ul"); const list = document.createElement("ul");
sanitationRules.ruleset.forEach(function(ruleset){ sanitationRules.ruleset.forEach(function(ruleset){
const rulesetContainer = document.createElement("li"); const rulesetContainer = document.createElement("li");
rulesetContainer.textContent = browser.i18n.getMessage("sanitation_ruleset." + ruleset.name); rulesetContainer.textContent = extension.getTranslation("sanitation_ruleset." + ruleset.name);
const rulesetErrors = document.createElement("ul"); const rulesetErrors = document.createElement("ul");
let anyComplaint = false; let anyComplaint = false;
@ -48,7 +49,7 @@
if (!anyComplaint){ if (!anyComplaint){
const noComplaints = document.createElement("li"); const noComplaints = document.createElement("li");
noComplaints.className = "noComplaints"; noComplaints.className = "noComplaints";
noComplaints.textContent = browser.i18n.getMessage("sanitation_nothingToComplain"); noComplaints.textContent = extension.getTranslation("sanitation_nothingToComplain");
rulesetErrors.appendChild(noComplaints); rulesetErrors.appendChild(noComplaints);
} }
rulesetContainer.appendChild(rulesetErrors); rulesetContainer.appendChild(rulesetErrors);

View File

@ -47,7 +47,7 @@
actions.forEach(function(action, i){ actions.forEach(function(action, i){
var button = document.createElement("button"); var button = document.createElement("button");
button.className = action.name + " action"; button.className = action.name + " action";
button.title = browser.i18n.getMessage(action.name); button.title = extension.getTranslation(action.name);
if (action.isIcon || action.icon){ if (action.isIcon || action.icon){
button.classList.add("isIcon"); button.classList.add("isIcon");
var img = document.createElement("img"); var img = document.createElement("img");

View File

@ -4,6 +4,7 @@
(function(){ (function(){
"use strict"; "use strict";
const extension = require("../lib/extension");
const settings = require("../lib/settings"); const settings = require("../lib/settings");
const {parseErrorStack} = require("../lib/callingStack"); const {parseErrorStack} = require("../lib/callingStack");
const {error, warning, message, notice, verbose, setPrefix: setLogPrefix} = require("../lib/logging"); const {error, warning, message, notice, verbose, setPrefix: setLogPrefix} = require("../lib/logging");
@ -102,8 +103,8 @@
domainOrUrlPicker( domainOrUrlPicker(
domain, domain,
urls, urls,
browser.i18n.getMessage("selectIgnore"), extension.getTranslation("selectIgnore"),
browser.i18n.getMessage("inputIgnoreURL") extension.getTranslation("inputIgnoreURL")
).then(function(choice){ ).then(function(choice){
if (choice){ if (choice){
settings.set("showNotifications", false, choice).then(function(){ settings.set("showNotifications", false, choice).then(function(){
@ -123,8 +124,8 @@
domainOrUrlPicker( domainOrUrlPicker(
domain, domain,
urls, urls,
browser.i18n.getMessage("selectWhitelist"), extension.getTranslation("selectWhitelist"),
browser.i18n.getMessage("inputWhitelistURL") extension.getTranslation("inputWhitelistURL")
).then(function(choice){ ).then(function(choice){
if (choice){ if (choice){
settings.set("blockMode", "allow", choice).then(function(){ settings.set("blockMode", "allow", choice).then(function(){
@ -144,8 +145,8 @@
domainOrUrlPicker( domainOrUrlPicker(
domain, domain,
urls, urls,
browser.i18n.getMessage("selectSessionWhitelist"), extension.getTranslation("selectSessionWhitelist"),
browser.i18n.getMessage("inputSessionWhitelistURL") extension.getTranslation("inputSessionWhitelistURL")
).then(function(choice){ ).then(function(choice){
if (choice){ if (choice){
lists.appendTo("sessionWhite", choice).then(function(){ lists.appendTo("sessionWhite", choice).then(function(){