-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
34 lines (29 loc) · 942 Bytes
/
background.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
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
css: ["ol[class*='comment']"]
})
],
actions: [new chrome.declarativeContent.ShowPageAction() ]
}]);
});
});
var tabClicks = {};
chrome.pageAction.onClicked.addListener(function(tab) {
var tabUrl = encodeURIComponent(tab.url);
var clicks = tabClicks[tab.id] || 0;
if (clicks == 0) {
tabClicks[tab.id] = 1;
} else {
tabClicks[tab.id]++;
}
if (clicks % 2 == 1) {
chrome.pageAction.setIcon({tabId: tab.id, path: "handshake.png"});
chrome.tabs.executeScript(tab.id, {file: "deflame_delete_comments.js"});
} else {
chrome.pageAction.setIcon({tabId: tab.id, path: "next.png"});
chrome.tabs.executeScript(tab.id, {file: "deflame_add_buttons.js"});
}
});