-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added localisation script. removed obsolete overlay for filter list
- Loading branch information
1 parent
cec4ceb
commit 750ab33
Showing
6 changed files
with
54 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
98 | ||
100 |