-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
49 lines (46 loc) · 1.41 KB
/
common.js
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
40
41
42
43
44
45
46
47
48
49
async function getOpenUrl(){
var url =(await browser.storage.sync.get('open_tab_url'))['open_tab_url'];
if(!url){
url =browser.i18n.getMessage('openTabDefaultUrl');
};
return url;
};
async function getSensitivity(){
var value =(await browser.storage.local.get('sensitivity'))['sensitivity'];
if(!value){
value =screen.width*0.2;
};
return value;
};
async function setOpenUrl(url){
return browser.storage.sync.set({
'open_tab_url' :url,
});
};
async function setSensitivity(value){
return browser.storage.local.set({
'sensitivity' :value,
});
};
function renderI18N(rootElt,mark='i18n:'){
rootElt =rootElt instanceof Element?rootElt:document.querySelector(rootElt);
for(let elt of Array.from(rootElt.getElementsByTagName('*'))){
for(let {name:attrName} of Array.from(elt.attributes)){
if(!attrName.startsWith(mark))continue;
let realAttr =attrName.replace(mark,'');
if(realAttr==='text'){
elt.textContent =browser.i18n.getMessage(
elt.getAttribute(attrName)
);
}else{
elt.setAttribute(
realAttr,
browser.i18n.getMessage(
elt.getAttribute(attrName)
)
);
};
elt.removeAttribute(attrName);
}
};
}