-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
69 lines (55 loc) · 1.79 KB
/
popup.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
69
const cb = document.getElementById('js-switcher')
chrome.runtime.sendMessage({action : 'getJSState'}, (response) => {
cb.checked = response.JSGlobalState
})
cb.addEventListener('change', () => {
chrome.runtime.sendMessage({action : 'updateJSState', JSState : cb.checked})
})
chrome.action.setIcon({ path: '/icons/popup-default.svg' })
const updatePopupState = (opt) => {
console.log('OK', opt)
for(div of document.querySelectorAll('#status > div')) {
if(div.getAttribute('id') != opt.status)
div.hidden = true;
else
div.hidden = false;
console.log(div, div.getAttribute('id') != opt.status)
}
const modeDiv = document.querySelector('#modes #'+opt.mode)
if(modeDiv) {
document.querySelector('#modes').hidden = false;
modeDiv.classList.add('current')
}
document.querySelector('#mode').innerHTML = opt.mode;
document.querySelector('#version').innerHTML = opt.version;
chrome.action.setIcon({ path: '/icons/popup-' + opt.mode + '.svg' })
}
function sendToCurrenTab(options, callback) {
chrome.tabs.query({active: true, currentWindow: true},function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, options, callback);
});
}
sendToCurrenTab({action: "getDDEPageInfo", enabledJS : cb.checked}, function(status) {
if(status)
updatePopupState(status)
})
/*
const STSwitsher = document.getElementById('style-theme-switcher');
sendToCurrenTab({action: "getStyleThemes"}, function(themes) {
if(themes.length) {
for(t of themes.all) {
console.log(t)
o = document.createElement('option');
o.value = t.name;
o.textContent = t.name;
if(t.isCurrent)
o.selected = true;
STSwitsher.append(o)
}
document.getElementById('themes').hidden = false
}
})
STSwitsher.addEventListener('change', (e) => {
sendToCurrenTab({action: "setStyleTheme", themeName : STSwitsher.value})
})
*/