forked from imightbeamy/gcal-multical-event-merge
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
67 lines (56 loc) · 2.3 KB
/
index.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
window.onload = function () {
const getDisabled = () => new Promise(res => chrome.storage.local.get('disabled', (s) => res(s.disabled)));
const getStyle = () => new Promise(res => chrome.storage.local.get('style', (s) => res(s.style)));
const getWildcard = () => new Promise(res => chrome.storage.local.get('wildcard', (s) => res(s.wildcard)));
const setIcon = (disabled) => chrome.action.setIcon({
path: disabled ? "icon-disabled.png" : "icon.png"
});
const setDropdown = (id, value) => {
let element = document.getElementById(id);
element.value = value;
}
const setToggle = (id, value) => {
let element = document.getElementById(id);
element.checked = value
}
const setText = (id, value) => {
let element = document.getElementById(id);
element.value = value
}
getDisabled().then(disabled => {
if (disabled == null) {
disabled = false
chrome.storage.local.set({ 'disabled': disabled });
}
setToggle('toggle_enabled',!disabled)
});
getStyle().then(value => {
if (value == null) {
value = 'vertical_bands'
chrome.storage.local.set({ 'style': value });
}
setDropdown('select_style',value)
});
getWildcard().then(value => {
if (value == null) {
value = 'busy'
chrome.storage.local.set({ 'wildcard': value });
}
setText('wildcard_value',value)
});
const manifest_data = chrome.runtime.getManifest();
document.getElementById('version').innerHTML=`V${manifest_data.version}`
document.getElementById('toggle_enabled').onclick = function () {
getDisabled().then(disabled => {
chrome.storage.local.set({ 'disabled': !disabled });
setIcon(!disabled);
})
};
document.getElementById('select_style').onchange = function (e) {
chrome.storage.local.set({ 'style': e.target.value });
};
document.getElementById('wildcard_value').onchange = function (e) {
if (e.target.value.length < 3 && e.target.value !== '') return alert('wildcard too short, you are going to get problems. If you do not want wildcard matching make this textbox blank')
chrome.storage.local.set({ 'wildcard': e.target.value });
};
}