-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
60 lines (44 loc) · 3.09 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
50
51
52
53
54
55
56
57
58
59
60
// from here: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Implement_a_settings_page
// duplication of constants is annoying...
let DEFAULT_INITIAL_PAUSE = "5";
let DEFAULT_STUTTER_PAUSE = "6";
let DEFAULT_STUTTER_CLASS = "stutter_scroll_stop_here";
// let DEFAULT_URL_LIST = "https://ontheday.net/\nhttps://google.com/";
// let DEFAULT_URL_LIST = 'http://127.0.0.1:8000/2018/bay_climb/tournament/open_men/\nhttp://127.0.0.1:8000/2018/bay_climb/otd_ftw/\nhttp://127.0.0.1:8000/2018/bay_climb/tournament/men_fixed/\nhttp://127.0.0.1:8000/2018/bay_climb/otd_ftw/\nhttp://127.0.0.1:8000/2018/bay_climb/tournament/open_women/\nhttp://127.0.0.1:8000/2018/bay_climb/otd_ftw/\nhttp://127.0.0.1:8000/2018/bay_climb/tournament/women_fixed/\nhttp://127.0.0.1:8000/2018/bay_climb/otd_ftw/';
let DEFAULT_URL_LIST = 'https://ontheday.net/2018/bay_climb/\nhttps://ontheday.net/2018/bay_climb/otd_ftw/\nhttps://ontheday.net/2018/bay_climb/tournament/open_men/\nhttps://ontheday.net/2018/bay_climb/otd_ftw/\nhttps://ontheday.net/2018/bay_climb/tournament/open_women/\nhttps://ontheday.net/2018/bay_climb/otd_ftw/\nhttps://ontheday.net/2018/bay_climb/tournament/men_fixed/\nhttps://ontheday.net/2018/bay_climb/otd_ftw/\nhttps://ontheday.net/2018/bay_climb/tournament/women_fixed/\nhttps://ontheday.net/2018/bay_climb/otd_ftw/'
function saveOptions(e) {
e.preventDefault();
browser.storage.sync.set({
initial_pause: document.querySelector("#initial_pause").value,
stutter_pause: document.querySelector("#stutter_pause").value,
stutter_class: document.querySelector("#stutter_class").value,
url_list: document.querySelector("#url_list").value
});
}
function restoreOptions() {
function setCurrentChoice_initial_pause(result) {
document.querySelector("#initial_pause").value = result.initial_pause || DEFAULT_INITIAL_PAUSE;
}
function setCurrentChoice_stutter_pause(result) {
document.querySelector("#stutter_pause").value = result.stutter_pause || DEFAULT_STUTTER_PAUSE;
}
function setCurrentChoice_stutter_class(result) {
document.querySelector("#stutter_class").value = result.stutter_class || DEFAULT_STUTTER_CLASS;
}
function setCurrentChoice_url_list(result) {
document.querySelector("#url_list").value = result.url_list || DEFAULT_URL_LIST;
}
function onError(error) {
console.log(`Error: ${error}`);
}
let getting_initial_pause = browser.storage.sync.get("initial_pause");
getting_initial_pause.then(setCurrentChoice_initial_pause, onError);
let getting_stutter_pause = browser.storage.sync.get("stutter_pause");
getting_stutter_pause.then(setCurrentChoice_stutter_pause, onError);
let getting_stutter_class = browser.storage.sync.get("stutter_class");
getting_stutter_class.then(setCurrentChoice_stutter_class, onError);
let getting_url_list = browser.storage.sync.get("url_list");
getting_url_list.then(setCurrentChoice_url_list, onError);
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);