-
Notifications
You must be signed in to change notification settings - Fork 3
/
options.js
51 lines (41 loc) · 1.69 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
const visiblityClass = 'is-visible';
async function saveOptions(e) {
e.preventDefault();
hideMessages();
let saved = browser.storage.sync.set({
xdebug_session: document.querySelector(".xdebug_session").value,
xdebug_session_on_color: document.querySelector(".xdebug-session-on-color:checked").value,
xdebug_session_off_color: document.querySelector(".xdebug-session-off-color:checked").value
});
saved.then(showSuccess, showError);
}
async function restoreOptions() {
const items = [
'xdebug_session',
'xdebug_session_on_color',
'xdebug_session_off_color'
];
let sessionKey = await browser.storage.sync.get(items);
document.querySelector(".xdebug_session").value = sessionKey.xdebug_session || 'phpstorm';
let onColor = sessionKey.xdebug_session_on_color || 'red';
let offColor = sessionKey.xdebug_session_off_color || 'light';
document.querySelector(".xdebug-session-on-color[value="+ onColor +"]").checked = true;
document.querySelector(".xdebug-session-off-color[value="+ offColor +"]").checked = true;
}
function showSuccess() {
let messageClass = document.querySelector(".saved-successfully").classList;
messageClass.add(visiblityClass);
setTimeout(function() {
hideMessages();
}, 2000);
}
function showError() {
let messageClass = document.querySelector(".saved-error").classList;
messageClass.add('is-visible');
}
function hideMessages() {
let messages = document.querySelector(".message").classList;
messages.remove(visiblityClass);
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);