-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
55 lines (48 loc) · 1.16 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const defaultIconPath = 'assets/icons/icon16.png'
const revealedIconPath = 'assets/icons/icon-revealed.png'
//Reveal password when extension icon clicked
chrome.browserAction.onClicked.addListener(function(tab) {
revealPassword()
})
chrome.commands.onCommand.addListener(function(command) {
if(command === 'revealPassword'){
revealPassword()
}
})
//on tab switch
chrome.tabs.onActivated.addListener(()=>{
checkIfRevealedAndChangeIcon()
})
//on page refresh
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab)=>{
checkIfRevealedAndChangeIcon()
})
function revealPassword(){
revealed = true
chrome.tabs.query({active: true, currentWindow: true}, (tabs)=>{
chrome.tabs.sendMessage(
tabs[0].id,
{msg: 'revealPassword'}
)
})
setIcon(revealedIconPath)
}
function checkIfRevealedAndChangeIcon(){
chrome.tabs.query({active: true, currentWindow: true}, (tabs)=>{
chrome.tabs.sendMessage(
tabs[0].id,
{msg: 'checkIfRevealed'},
(response)=>{
if(response && response.revealed){
setIcon(revealedIconPath)
}
else{
setIcon(defaultIconPath)
}
}
)
})
}
function setIcon(path){
chrome.browserAction.setIcon({path: path})
}