-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdark.js
More file actions
23 lines (20 loc) · 708 Bytes
/
dark.js
File metadata and controls
23 lines (20 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// init button
const btn = document.querySelector('.btn-toggle');
// set state to saved state if it exists
chrome.storage.local.get(['SavedState'], function(result) {
if(typeof(result.SavedState) == undefined)
document.body.className = '';
else
document.body.className = result.SavedState;
});
// Listen for a click on the button
btn.addEventListener('click', function() {
// Then toggle (add/remove) the .dark-theme class to the body
document.body.classList.toggle('dark-theme');
// save state
const state = document.body.className;
chrome.storage.local.set({'SavedState': state}, function() {
// Notify that we saved.
console.log('Settings saved');
})
})