-
Notifications
You must be signed in to change notification settings - Fork 8
/
global.js
61 lines (57 loc) · 1.43 KB
/
global.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
50
51
52
53
54
55
56
57
58
59
60
61
const LOG_PREFIX = "[Right Links WE] ";
var prefs = { // Defaults
updateNotice: true,
debug: false,
enabled: true,
enabledLeft: true,
enabledRight: true,
loadInBackgroundLeft: false,
loadInBackgroundRight: true,
loadInDiscardedLeft: false,
loadInDiscardedRight: false,
loadInLeft: 0,
loadInRight: 0,
blacklistLeft: "",
blacklistRight: "",
enabledOnImages: true,
enabledOnCanvasImages: true,
canvasImagesSizeLimit: 0,
canvasImagesUseBlob: true,
showContextMenuTimeout: 500,
longLeftClickTimeout: 500,
disallowMousemoveDist: 14,
toggleKey: "F2"
};
function readPrefs(callback) {
browser.storage.local.get().then(function(o) {
browser.storage.onChanged.addListener(function(changes, area) {
if(area == "local") for(var key in changes)
_onPrefChanged(key, changes[key].newValue);
});
Object.assign(prefs, o);
callback();
for(var key in o)
return; // Prefs already saved
setTimeout(function() { // Pseudo async
browser.storage.local.set(prefs);
}, 5000);
}, _err);
}
function _onPrefChanged(key, newVal) {
prefs[key] = newVal;
onPrefChanged(key, newVal);
}
function onPrefChanged(key, newVal) {
}
function ts() {
var d = new Date();
var ms = d.getMilliseconds();
return d.toTimeString().replace(/^.*\d+:(\d+:\d+).*$/, "$1") + ":" + "000".substr(("" + ms).length) + ms + " ";
}
function _log(s) {
if(prefs.debug)
console.log(LOG_PREFIX + ts() + s);
}
function _err(s) {
console.error(LOG_PREFIX + ts() + s);
}