From 750ab33f3619cf7c710410cf1a673a79f3492bfb Mon Sep 17 00:00:00 2001 From: RealRaven2000 Date: Tue, 13 Oct 2020 10:30:43 +0100 Subject: [PATCH] Added localisation script. removed obsolete overlay for filter list --- chrome/content/i18n.js | 49 +++++++++++++++++++++++++ chrome/content/scripts/qf-filterlist.js | 44 +--------------------- manifest.json | 4 +- qf-background.js | 2 - release-notes.html | 1 - revision.txt | 2 +- 6 files changed, 54 insertions(+), 48 deletions(-) create mode 100644 chrome/content/i18n.js diff --git a/chrome/content/i18n.js b/chrome/content/i18n.js new file mode 100644 index 000000000..7eb641496 --- /dev/null +++ b/chrome/content/i18n.js @@ -0,0 +1,49 @@ +var i18n = { + updateString(string) { + let re = new RegExp(this.keyPrefix + "(.+?)__", "g"); + return string.replace(re, matched => { + const key = matched.slice(this.keyPrefix.length, -2); + let rv = this.extension + ? this.extension.localeData.localizeMessage(key) + : messenger.i18n.getMessage(key); + return rv || matched; + }); + }, + + updateSubtree(node) { + const texts = document.evaluate( + 'descendant::text()[contains(self::text(), "' + this.keyPrefix + '")]', + node, + null, + XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, + null + ); + for (let i = 0, maxi = texts.snapshotLength; i < maxi; i++) { + const text = texts.snapshotItem(i); + if (text.nodeValue.includes(this.keyPrefix)) text.nodeValue = this.updateString(text.nodeValue); + } + + const attributes = document.evaluate( + 'descendant::*/attribute::*[contains(., "' + this.keyPrefix + '")]', + node, + null, + XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, + null + ); + for (let i = 0, maxi = attributes.snapshotLength; i < maxi; i++) { + const attribute = attributes.snapshotItem(i); + if (attribute.value.includes(this.keyPrefix)) attribute.value = this.updateString(attribute.value); + } + }, + + updateDocument(options = {}) { + this.extension = null; + this.keyPrefix = "__MSG_"; + if (options) { + if (options.extension) this.extension = options.extension; + if (options.keyPrefix) this.keyPrefix = options.keyPrefix; + } + this.updateSubtree(document); + } +}; + diff --git a/chrome/content/scripts/qf-filterlist.js b/chrome/content/scripts/qf-filterlist.js index 457d93322..36e133939 100644 --- a/chrome/content/scripts/qf-filterlist.js +++ b/chrome/content/scripts/qf-filterlist.js @@ -1,3 +1,4 @@ +/* this module is obsolete */ var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); Services.scriptloader.loadSubScript("chrome://quickfolders/content/quickfolders.js", window, "UTF-8"); @@ -8,56 +9,15 @@ Services.scriptloader.loadSubScript("chrome://quickfolders/content/quickfolders- Services.scriptloader.loadSubScript("chrome://quickfolders/content/quickfolders-filterList.js", window, "UTF-8"); Services.scriptloader.loadSubScript("chrome://quickfolders/content/overlayFilterList.js", window, "UTF-8"); + function onLoad(activatedWhileWindowOpen) { let layout = WL.injectCSS("chrome://quickfolders/content/filterList.css"); WL.injectElements(` - -