-
Notifications
You must be signed in to change notification settings - Fork 0
/
content-script.js
32 lines (28 loc) · 1020 Bytes
/
content-script.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
const bookkeepingElementId = 'passwordIsCurrentlyRevealed632757'
chrome.runtime.onMessage.addListener((request, sender, sendResponse)=> {
if(request.msg === 'revealPassword'){
reveal()
}
})
chrome.runtime.onMessage.addListener((request, sender, sendResponse)=> {
if(request.msg === 'checkIfRevealed'){
if(document.getElementById(bookkeepingElementId)){
sendResponse({revealed: true})
}
else{
sendResponse({revealed: false})
}
}
})
function reveal(){
let passwordFields = document.querySelectorAll('input[type="password"]')
for(let i=0; i<passwordFields.length; i++){
passwordFields[i].setAttribute("type", "text")
}
//Create dummy element with unique ID & add to page if it hasn't been added. Used to "remember" icon states when switching between pages
if(!document.getElementById(bookkeepingElementId)){
let bookkeepingElement = document.createElement('span')
bookkeepingElement.id = bookkeepingElementId
document.getElementsByTagName('body')[0].appendChild(bookkeepingElement)
}
}