-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.js
49 lines (38 loc) · 1.61 KB
/
options.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
const saveOptions = (e) => {
e.preventDefault();
const scihubMirrorValue = document.querySelector("input[name='scihub-mirror']:checked").value;
browser.storage.sync.set({ scihubMirror: scihubMirrorValue });
const libgenMirrorValue = document.querySelector("input[name='libgen-mirror']:checked").value;
browser.storage.sync.set({ libgenMirror: libgenMirrorValue });
const annasArchiveCheckbox = document.querySelector("input[name='annas-archive']");
const useAnnasArchiveValue = annasArchiveCheckbox.checked ? "true" : "false";
browser.storage.sync.set({ annasArchive: useAnnasArchiveValue });
}
const restoreOptions = async () => {
try {
const { scihubMirror } = await browser.storage.sync.get('scihubMirror');
if (scihubMirror) {
document.querySelector(`input[name='scihub-mirror'][value='${scihubMirror}']`).checked = true;
}
} catch (error) {
console.log(`Error: ${error}`);
}
try {
const { libgenMirror } = await browser.storage.sync.get('libgenMirror');
if (libgenMirror) {
document.querySelector(`input[name='libgen-mirror'][value='${libgenMirror}']`).checked = true;
}
} catch (error) {
console.log(`Error: ${error}`);
}
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);
document.getElementById('settingsForm').addEventListener('submit', function (event) {
event.preventDefault();
var notification = document.querySelector('.notification');
notification.style.display = 'block';
setTimeout(function () {
notification.style.display = 'none';
}, 2000);
});