-
Notifications
You must be signed in to change notification settings - Fork 5
/
popup.js
37 lines (30 loc) · 1.32 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
// popup.js: browser popup
'use strict';
const switchElement = document.getElementById('enableSwitch'),
windowMaxCheck = document.getElementById('windowMaxCheck'),
windowFocusCheck = document.getElementById('windowFocusCheck'),
newPaperBtn = document.getElementById('newPaper');
chrome.runtime.sendMessage({message: 'getStatus'}, response => {
switchElement.checked = JSON.parse(response);
});
chrome.storage.local.get(['windowMaxCheck', 'windowFocusCheck']).then(storage => {
windowMaxCheck.checked = !!storage.windowMaxCheck;
windowFocusCheck.checked = !!storage.windowFocusCheck;
});
switchElement.onchange = () => {
console.log('[debug]', 'telling background.js about the changes...')
if (switchElement.checked) {
chrome.runtime.sendMessage({ message: 'startLiveWallpaper' });
} else {
chrome.runtime.sendMessage({ message: 'stopLiveWallpaper' });
}
}
windowMaxCheck.onchange = windowFocusCheck.onchange = () => {
console.log('[debug]', 'saving changes...');
chrome.storage.local.set({ windowMaxCheck: windowMaxCheck.checked, windowFocusCheck: windowFocusCheck.checked });
console.log('[debug]', 'restart engine...');
chrome.runtime.sendMessage({ message: 'restartEngine' });
}
newPaperBtn.onclick = () => {
chrome.windows.create({ url: 'change_wallpaper.html', type: 'popup' });
}