-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
46 lines (42 loc) · 1.31 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
window.addEventListener("DOMContentLoaded", (event) => {
//console.debug("DOMContentLoaded");
cmdAdd.addEventListener("click", function() { addSwap(); });
cmdDel.addEventListener("click", function() { del(); });
fillList();
});
function addSwap(){
//console.debug("Adding");
const add = document.getElementById("txtSource").value + ":" + document.getElementById("txtDest").value;
//console.debug("Adding " + add);
if (add.length < 2){
console.log("Must be at least 2 characters.");
return;
}
browser.extension.getBackgroundPage().addSwap(add);
fillList();
document.getElementById("txtSource").value = "";
document.getElementById("txtDest").value = "";
}
function del(){
const item = swapList.value;
//console.debug("del " + item);
if (item != ""){
const sourceDest = item.split(":");
document.getElementById("txtSource").value = sourceDest[0];
document.getElementById("txtDest").value = sourceDest[1];
browser.extension.getBackgroundPage().del(item,fillList);
console.log("Deleted")
}
}
function fillList(){
swapList.innerHTML = "";
const swaps = browser.extension.getBackgroundPage().swapList;
if (swaps != []){
for (let i = 0; i < swaps.length; i++){
let opt = document.createElement("option");
opt.value = swaps[i];
opt.innerHTML = swaps[i];
swapList.appendChild(opt);
}
}
}