-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs.js
57 lines (45 loc) · 1.84 KB
/
prefs.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
window.onload = function() {
//Localisation
document.getElementById("prefsNonBCCLimit").textContent = browser.i18n.getMessage("prefsNonBCCLimit");
document.getElementById("prefsStrictLimit").textContent = browser.i18n.getMessage("prefsStrictLimit");
// Retrieve the stored prefs
// Prefs are set up in background.js which always seems to run first
var prefs = new Object() ;
let gettingItem = browser.storage.local.get('prefs');
gettingItem.then(onGot, onError);
function onGot(item) {
prefs = item['prefs'] ;
// Populate prefs on page
var maxNonBCCParam = document.querySelector('#maxNonBCC');
maxNonBCCParam.value = prefs['maxNonBCC'] ;
var strictLimit = document.querySelector('#strictLimit');
strictLimit.checked = prefs['strictLimit'] ;
}
function onError(error) {
console.log("Limit non-BCC recipients: "+ error)
}
// Listen for change to a pref
const inputMaxNonBCC = document.getElementById('maxNonBCC');
inputMaxNonBCC.addEventListener('change', updateValue);
const inputStrictLimit = document.getElementById('strictLimit');
inputStrictLimit.addEventListener('change', updateStrict);
// Update to max non-BCC number
function updateValue(e) {
prefs['maxNonBCC'] = e.srcElement.value;
browser.storage.local.set({'prefs': prefs}, onCompletion ) ;
// Send new prefs to background
browser.runtime.sendMessage(prefs).catch();
}
// Update to strict limit checkbox
function updateStrict(e) {
prefs['strictLimit'] = e.srcElement.checked;
browser.storage.local.set({'prefs': prefs}, onCompletion ) ;
// Send new prefs to background
browser.runtime.sendMessage(prefs).catch();
}
function onCompletion() { /* log error is there is one */
if (chrome.runtime.lastError) {
console.error("Limit non-BCC recipients: "+ chrome.runtime.lastError);
}
}
};