forked from sorenlouv/github-widescreen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent-scripts.js
More file actions
31 lines (26 loc) · 730 Bytes
/
content-scripts.js
File metadata and controls
31 lines (26 loc) · 730 Bytes
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
/*globals chrome */
function getState(callback){
chrome.storage.sync.get('state', function(data) {
callback(data.state);
});
}
function toggleCssClass(state){
var WIDE_CSS_CLASS = 'wide';
var body = document.querySelector('body');
var toggle = state ? body.classList.add : body.classList.remove;
toggle.call(body.classList, WIDE_CSS_CLASS);
}
chrome.storage.onChanged.addListener(function (data) {
var state = data.state.newValue;
toggleCssClass(state);
});
getState(function(state) {
toggleCssClass(state);
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "checkState") {
getState(function(state) {
toggleCssClass(state);
});
}
});