-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
45 lines (38 loc) · 1.33 KB
/
Copy pathbackground.js
File metadata and controls
45 lines (38 loc) · 1.33 KB
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
const browserAPI = chrome;
const css = "body { border: 10px solid red; transition: border; }";
const enableContentEditable = () => {
document.body.setAttribute("contenteditable", true);
};
const disableContentEditable = () => {
document.body.removeAttribute("contenteditable");
};
const toggleEditable = async (tab) => {
const tabId = tab.id;
const badgeColor = await browserAPI.action.getBadgeBackgroundColor({
tabId,
});
if (badgeColor && badgeColor[1] === 128) {
browserAPI.action.setIcon({
tabId: tab.id,
path: 'icon.png'
});
chrome.action.setBadgeBackgroundColor({
tabId: tab.id,
color: 'red',
});
chrome.scripting.executeScript({ target: { tabId }, function: disableContentEditable });
browserAPI.scripting.removeCSS({ target: { tabId }, css });
} else {
browserAPI.action.setIcon({
tabId: tab.id,
path: 'icon-active.png'
});
chrome.scripting.executeScript({ target: { tabId }, function: enableContentEditable });
browserAPI.action.setBadgeBackgroundColor({
tabId: tab.id,
color: 'green',
});
chrome.scripting.insertCSS({ target: { tabId: tab.id }, css });
}
};
chrome.action.onClicked.addListener(toggleEditable);