-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent_script.js
53 lines (46 loc) · 1.9 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// listen for access code from popup
chrome.runtime.onMessage.addListener(async (recdMessage) => {
if (recdMessage.messageType === "ACCESS_CODE_FROM_POPUP") {
console.log(recdMessage.messageType)
accessCodeText = recdMessage.accessCodeText
// ask background script to retrieve credentials
let message = {
messageType: "GET_CREDENTIALS_FROM_BG",
accessCodeText: accessCodeText
}
chrome.runtime.sendMessage(message, (response) => {
if (chrome.runtime.lastError) {
// TODO: error handling
// console.error("Error communicating from content_script to background!")
} else {
console.log("Sent message from content_script to background!")
console.log(response)
}
})
}
})
// listen for credentials from background script
chrome.runtime.onMessage.addListener(async (recdMessage) => {
if (recdMessage.messageType === 'WITH_CREDENTIALS_FROM_BG') {
console.log(recdMessage.messageType)
const credentials = recdMessage.credentials
const username = credentials.username
const passwd = credentials.passwd
// TODO: still a bit buggy?
// fill username
let usernameField = document.getElementById("id_userLoginId")
usernameField.value = username
usernameField.setAttribute("value", username)
usernameField.classList.add("hasText");
usernameField.dir = 'ltr'
// disable show password button
let showPasswdButton = document.getElementById("id_password_toggle")
showPasswdButton.disabled = true
// fill password
let passwdField = document.getElementById("id_password");
passwdField.value = passwd
passwdField.setAttribute("value", passwd)
passwdField.classList.add("hasText")
passwdField.dir = 'ltr'
}
});