forked from magicoflolis/Userscript-Plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi18n.js
More file actions
39 lines (32 loc) 路 1.09 KB
/
Copy pathi18n.js
File metadata and controls
39 lines (32 loc) 路 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
/******************************************************************************/
const i18n =
self.browser instanceof Object && self.browser instanceof Element === false
? self.browser.i18n
: self.chrome.i18n;
const i18n$ = (...args) => i18n.getMessage(...args);
/******************************************************************************/
const isBackgroundProcess = document.title === 'Magic UserJS+ Background Page';
if (isBackgroundProcess !== true) {
// Helper to deal with the i18n'ing of HTML files.
i18n.render = function (context) {
const docu = document;
const root = context || docu;
for (const elem of root.querySelectorAll('[data-i18n]')) {
const text = i18n$(elem.getAttribute('data-i18n'));
if (!text) {
continue;
}
elem.textContent = text;
}
for (const elem of root.querySelectorAll('[placeholder]')) {
const text = i18n$(elem.getAttribute('placeholder'));
if (text === '') {
continue;
}
elem.setAttribute('placeholder', text);
}
};
i18n.render();
}
export { i18n, i18n$ };