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

Removed unused messages

allowPDFCanvas_description
allowPDFCanvas_title
url_title
url_description
inspectImage
This commit is contained in:
kkapsner 2018-09-23 12:56:16 +02:00
parent 18bbab50a5
commit d52f107f00
7 changed files with 146 additions and 120 deletions

View File

@ -0,0 +1,146 @@
const fs = require("fs");
const path = require("path");
const util = require("util");
function getMessagesInContent(content){
const foundMessages = [];
[
/\b(?:_|browser.i18n.getMessage|notify)\(["']([^"']+)["']\s*(?:\)|,)/g,
/\b(?:messageId|name)\s*:\s*["']([^"']+)["']/g,
].forEach(function(re){
let match;
while ((match = re.exec(content)) !== null){
foundMessages.push(match[1].toLowerCase());
}
});
return foundMessages;
}
async function getMessagesInFile(path){
return await util.promisify(fs.exists)(path)
.then(function(exists){
if (exists){
return util.promisify(fs.readFile)(path, {encoding: "UTF-8"})
.then(function(content){
return getMessagesInContent(content);
});
}
else {
console.log("file does not exist:", path);
return [];
}
});
}
async function getMessagesInFolder(folder){
return await util.promisify(fs.readdir)(folder, {encoding: "UTF-8"})
.then(function(files){
return Promise.all(
files.filter(function(file){
return !file.startsWith(".");
}).map(function(file){
return path.join(folder, file);
}).map(function(path){
return util.promisify(fs.stat)(path).then(function(stat){
if (stat.isDirectory()){
return getMessagesInFolder(path);
}
else {
if (path.endsWith(".js")){
return getMessagesInFile(path);
}
else {
return [];
}
}
});
})
).then(function(messages){
const flat = [];
messages.forEach(function(messages){
messages.forEach(function(message){
flat.push(message);
});
});
return flat;
});
})
}
async function getSettingMessages(){
const settingStrings = require("../lib/settingStrings");
const settingDefinitions = require("../lib/settingDefinitions");
function getDefinition(name){
return settingDefinitions.filter(function(settingDefinition){
return settingDefinition.name === name;
})[0];
}
const settingsDisplay = require("../options/settingsDisplay");
const foundMessages = [];
settingsDisplay.forEach(function(display){
if ((typeof display) === "string"){
foundMessages.push("section_" + display.toLowerCase());
}
else {
let settingDefinition = getDefinition(display.name);
if (!settingDefinition){
settingDefinition = display;
display.action = true;
}
if (settingDefinition){
if (display.inputs){
settingDefinition.inputs = display.inputs.map(function(input){
return getDefinition(input);
});
}
else if (display.actions){
settingDefinition.actions = display.actions.map(function(action){
return {name: action};
});
}
settingStrings.getMessages(settingDefinition).forEach(function(message){
foundMessages.push(message.toLowerCase());
});
}
}
});
return foundMessages.map(function(message){return message.toLowerCase();});
}
async function getKnownMessages(){
return [
"addon_title",
"addon_description",
"urlsettings_title",
"installnotice",
"updatenotice",
"disablenotifications",
"showoptions",
"displayhiddensettings_title",
"displayhiddensettings_description",
"browseraction_settings",
"browseraction_test",
"browseraction_review",
"browseraction_reportissue",
];
}
const en = require("../_locales/en/messages.json");
const declaredMessages = Object.keys(en)
// .filter(function(key){return en[key].message;})
.map(function(key){return key.toLowerCase();});
Promise.all([getSettingMessages(), getMessagesInFolder(path.join(__dirname, "..")), getKnownMessages()]).then(function([settingMessages, fileMessages, knownMessages]){
declaredMessages.forEach(function(message){
if (
fileMessages.indexOf(message) === -1 &&
settingMessages.indexOf(message) === -1 &&
knownMessages.indexOf(message) === -1
){
console.log(`${message} not used`);
}
});
});

View File

@ -154,14 +154,6 @@
"description": ""
},
"allowPDFCanvas_description": {
"message": "Die native pdf.js verwendet <canvas> um den Inhalt von PDFs anzuzeigen. Wenn viele Nachfragedialoge erscheinen oder die PDF-Ansicht nicht funktioniert, müssen diese erlaubt werden.",
"description": ""
},
"allowPDFCanvas_title": {
"message": "<canvas> in PDFs erlauben",
"description": ""
},
"askForInvisiblePermission": {
"message": "Wollen Sie unsichtbare <canvas> erlauben?",
"description": ""
@ -363,14 +355,6 @@
"description": ""
},
"url_title": {
"message": "URL",
"description": ""
},
"url_description": {
"message": "",
"description": ""
},
"inputURL": {
"message": "Domain oder URL \"RegExp\" eingeben:",
"description": ""
@ -824,10 +808,6 @@
"description": ""
},
"inspectImage": {
"message": "Bild betrachten",
"description": ""
},
"storeImageForInspection_title": {
"message": "Bild für Betrachtung speichern",
"description": ""

View File

@ -355,14 +355,6 @@
"description": ""
},
"url_title": {
"message": "URL",
"description": ""
},
"url_description": {
"message": "",
"description": ""
},
"inputURL": {
"message": "Input domain or URL \"RegExp\":",
"description": ""
@ -743,14 +735,6 @@
"message": "blink",
"description": ""
},
"notificationDisplayTime_description": {
"message": "Number of seconds the notifications are shown. (Enter zero to disable automatic closing.)",
"description": ""
},
"notificationDisplayTime_title": {
"message": "Notification display time",
"description": ""
},
"sourceOutput": {
"message": "Calling file",
"description": ""
@ -823,10 +807,6 @@
"description": ""
},
"inspectImage": {
"message": "inspect image",
"description": ""
},
"storeImageForInspection_title": {
"message": "Store image for inspection",
"description": ""

View File

@ -121,14 +121,6 @@
"description": ""
},
"allowPDFCanvas_description": {
"message": "El lector de PDF integrado de Firefox usa la API para mostrar el contenido de los PDF. Si aparecen demasiados cuadros de diálogo o si no funciona el lector de PDF en absoluto, tiene que permitir esto.",
"description": ""
},
"allowPDFCanvas_title": {
"message": "Permitir canvas en los PDF",
"description": ""
},
"askForInvisiblePermission": {
"message": "¿Quiere permitir los <canvas> invisibles?",
"description": ""
@ -290,14 +282,6 @@
"description": ""
},
"url_title": {
"message": "URL",
"description": ""
},
"url_description": {
"message": "",
"description": ""
},
"inputURL": {
"message": "Introduzca un dominio o RegExp de URL:",
"description": ""
@ -681,10 +665,6 @@
"description": ""
},
"inspectImage": {
"message": "inspeccionar la imagen",
"description": ""
},
"storeImageForInspection_title": {
"message": "Guardar la imagen para inspeccionarla",
"description": ""

View File

@ -100,14 +100,6 @@
"description": ""
},
"allowPDFCanvas_description": {
"message": "Le fichier pdf.js (JavaScript) utilise <canvas> pour afficher le contenu des PDF. Si de nombreuses boîtes de dialogue apparaissent ou si la vue de PDF ne fonctionne pas, canvas doit être autorisé.",
"description": ""
},
"allowPDFCanvas_title": {
"message": "Autoriser Canvas dans les fichiers PDF",
"description": ""
},
"askForInvisiblePermission": {
"message": "Voulez-vous autoriser l'utilisation de <canvas> invisible ?",
"description": ""
@ -269,14 +261,6 @@
"description": ""
},
"url_title": {
"message": "URL",
"description": ""
},
"url_description": {
"message": "",
"description": ""
},
"inputURL": {
"message": "Input domain or URL RegExp:",
"description": ""
@ -577,10 +561,6 @@
"description": ""
},
"inspectImage": {
"message": "Visionner l'image",
"description": ""
},
"storeImageForInspection_title": {
"message": "Enregistrer l'image pour la visualiser",
"description": ""

View File

@ -35,14 +35,6 @@
"description": ""
},
"allowPDFCanvas_description": {
"message": "Il lettore PDF nativo di Firefox usa le API per visualizzare i PDF. Se compaiono troppe finestre di interazione o il lettore PDF non funziona proprio, allora devono essere permesse.",
"description": ""
},
"allowPDFCanvas_title": {
"message": "Permetti canvas nei PDF",
"description": ""
},
"askForInvisiblePermission": {
"message": "Vuoi permettere i <canvas> invisibili?",
"description": ""
@ -178,14 +170,6 @@
"description": ""
},
"url_title": {
"message": "URL",
"description": ""
},
"url_description": {
"message": "",
"description": ""
},
"inputURL": {
"message": "Inserisci dominio o RegExp URL:",
"description": ""
@ -465,10 +449,6 @@
"description": ""
},
"inspectImage": {
"message": "ispeziona immagine",
"description": ""
},
"storeImageForInspection_title": {
"message": "Memorizza immagine per ispezione",
"description": ""

View File

@ -100,14 +100,6 @@
"description": ""
},
"allowPDFCanvas_description": {
"message": "Firefox 自带的 PDF 阅读器pdf.js使用该 API 显示 PDF 内容。如果出现了太多的询问对话框,或者 PDF 阅读器功能失效,则您需要在对话框中允许。",
"description": ""
},
"allowPDFCanvas_title": {
"message": "允许 PDF 文件中的 Canvas",
"description": ""
},
"askForInvisiblePermission": {
"message": "是否允许不可见的 <canvas>",
"description": ""
@ -269,14 +261,6 @@
"description": ""
},
"url_title": {
"message": "URL",
"description": ""
},
"url_description": {
"message": "",
"description": ""
},
"inputURL": {
"message": "输入域名或网址URL的正则表达式",
"description": ""
@ -603,10 +587,6 @@
"description": ""
},
"inspectImage": {
"message": "察看图像",
"description": ""
},
"storeImageForInspection_title": {
"message": "存储图像以备察看",
"description": ""