-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
68 lines (52 loc) · 1.79 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
61
62
63
64
65
66
67
68
"use strict";
(function() {
let altLogoEl = document.querySelector('#alt-logo');
let contextMenuEl = document.querySelector('#context-menu');
let delayEl = document.querySelector('#delay');
let menuLinksEl = document.querySelector('#menu-links');
menuLinksEl.addEventListener('blur', () => {
let value = menuLinksEl.value.trim();
if (value === '') {
value = '[]';
menuLinksEl.value = value;
}
if (helpers.isJson(value)) {
menuLinksEl.setCustomValidity('');
} else {
menuLinksEl.setCustomValidity('This text must be valid JSON.');
}
});
let onSubmit = (e) => {
e.preventDefault();
if (!e.target.checkValidity()) {
notify("Please check input fields are valid.");
}
settings.useAltLogo.save(altLogoEl.checked);
settings.createContextMenu.save(contextMenuEl.checked);
settings.delayTime.save(delayEl.value);
settings.menuLinks.save(menuLinksEl.value.trim());
notify("Saved!");
shared.setIcon();
shared.contextMenus.setup();
};
let restoreOptions = () => {
settings.useAltLogo.get()
.then(value => {
altLogoEl.checked = value;
});
settings.createContextMenu.get()
.then(value => {
contextMenuEl.checked = value;
});
settings.delayTime.get()
.then(value => {
delayEl.value = value;
});
settings.menuLinks.get()
.then(value => {
menuLinksEl.value = value;
});
};
document.addEventListener('DOMContentLoaded', restoreOptions);
document.querySelector('form').addEventListener('submit', onSubmit);
})();