-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
38 lines (34 loc) · 935 Bytes
/
background.js
File metadata and controls
38 lines (34 loc) · 935 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
32
33
34
35
36
37
38
console.log('Background script running!!');
chrome.browserAction.onClicked.addListener(buttonClicked);
let extensionRun1 = 0;
function changeMode(tab) {
let swtch = {
turn: "on"
};
if (extensionRun1 % 2 === 1) {
swtch.turn = "off";
} else {
swtch.turn = "on";
}
chrome.tabs.sendMessage(tab.id, swtch);
if(swtch.turn === "on")
{
chrome.browserAction.setIcon({ path:'icons/icons8-eye-16.png'});
}else
{
chrome.browserAction.setIcon({path:'icons/16.png'});
}
extensionRun1 += 1;
}
function buttonClicked(tab){
console.log('icon clicked');
changeMode(tab);
}
chrome.commands.onCommand.addListener(function (command) {
if (command === 'toggle') {
console.log(command,' command entered');
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
changeMode(tabs[0]);
});
}
});