-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
46 lines (41 loc) · 1.46 KB
/
options.js
File metadata and controls
46 lines (41 loc) · 1.46 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
40
41
42
43
44
45
46
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* @author Chris Willoughby
*/
"use strict";
function onError(error) {
console.error(`Error: ${error}`);
}
// Saves options to browser.storage
function save_options() {
// console.log("options save");
var citationFormat = document.getElementById("format").value;
var storageItem = browser.storage.sync.set({
troveFormat: citationFormat
});
storageItem.then(() => {
// Update status to let user know options were saved.
var status = document.getElementById("status");
status.textContent = "Options saved.";
setTimeout(function() {
status.textContent = "";
}, 750);
});
}
// Restores select box and checkbox state using the preferences
// stored in browser.storage.
function restore_options() {
// console.log("options restore");
// Use default value = "%A%n%C%n%T%n%I, page %P%n[Quote]%n%Q%n[Quote]%n".
var storageItem = browser.storage.sync.get({
troveFormat: "%A%n%C%n%T%n%I, page %P%n[Quote]%n%Q%n[Quote]%n"
});
storageItem.then((items) => {
document.getElementById("format").value = items.troveFormat;
}, onError);
}
document.addEventListener("DOMContentLoaded", restore_options);
document.getElementById("save").addEventListener("click", save_options);