-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpopup.js
100 lines (85 loc) · 3.12 KB
/
popup.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const button=document.getElementsByClassName("btn");
const checkboxes=document.querySelectorAll('input[type=checkbox]');
const inputs=document.querySelector('.inputs');
const inputCheckBox=document.getElementById('checkbox3');
const logsDiv=document.querySelector(".scroll");
let i;
let usr;
let psw;
let logs = [];
function loops() {
// for section +/-
for (i = 0; i < button.length; i++) {
button[i].addEventListener("click", function() {
this.classList.toggle("active");
const content = this.nextElementSibling;
if (content.style.display === "block") {
content.style.display = "none";
} else {
content.style.display = "block";
}
localStorage.setItem(content.id, JSON.stringify(content.style.display));
});
}
// for checkboxes
for (i = 0; i < checkboxes.length; i++) {
checkboxes[i].addEventListener('change', function() {
localStorage.setItem(this.id, JSON.stringify(this.checked));
if (this.id=="checkbox3" && this.checked) {
inputs.style.display = "block";
browser.runtime.sendMessage({msgType: "SETTING",
usr: JSON.parse(localStorage.getItem('usr')),
psw: JSON.parse(localStorage.getItem('psw'))
});
}
else if (this.id=="checkbox3"){inputs.style.display = "none";}
browser.runtime.sendMessage({msgType: "SETTING", id:this.id, checked:this.checked});
});
}
// for inputs
document.getElementById('usr').addEventListener('input', function() {
browser.runtime.sendMessage({msgType: "SETTING", usr: this.value});
localStorage.setItem("usr", JSON.stringify(this.value));
});
document.getElementById('psw').addEventListener('input', function() {
browser.runtime.sendMessage({msgType: "SETTING", psw: this.value});
localStorage.setItem("psw", JSON.stringify(this.value));
});
}
function setElements(){
for (i = 0; i < checkboxes.length; i++) {checkboxes[i].checked = JSON.parse(localStorage.getItem('checkbox' + i));}
button[0].nextElementSibling.style.display = JSON.parse(localStorage.getItem('menu0'));
button[1].nextElementSibling.style.display = JSON.parse(localStorage.getItem('menu1'));
if (inputCheckBox.checked) {inputs.style.display = "block";}
else {inputs.style.display = "none";}
JSON.parse(localStorage.getItem('checkbox' + i));
document.getElementById('psw').value = JSON.parse(localStorage.getItem('psw'));
document.getElementById('usr').value = JSON.parse(localStorage.getItem('usr'));
if (inputCheckBox.checked) {
browser.runtime.sendMessage({msgType: "SETTING",
usr: JSON.parse(localStorage.getItem('usr')),
psw: JSON.parse(localStorage.getItem('psw'))
});
}
}
function handleBS(m) {
logs = m.logs;
console.log("recived Logs");
if (logs.length > 0) {
for (i = 0; i < logs.length; i++) {
const log = document.createElement("p");
log.innerHTML = logs[i];
logsDiv.appendChild(log);
}
}
else {
logsDiv.innerText = "There are no logs present";
}
}
console.log("Popup Opened");
browser.runtime.sendMessage({msgType: "POPUP", connection: "PU Messaged Success"});
browser.runtime.onMessage.addListener(handleBS);
document.addEventListener('DOMContentLoaded',() => {
setElements();
loops();
});