-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
56 lines (43 loc) · 1.43 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
// Load names from storage when the extension popup is opened
document.addEventListener('DOMContentLoaded', function() {
chrome.storage.local.get(['namesList'], function(result) {
if (result.namesList) {
result.namesList.forEach(function(name) {
addNameToList(name);
});
}
});
});
function addName() {
var name = document.getElementById("articleName").value;
if (name.trim() === "") return;
addNameToList(name);
// Save the updated list to local storage
saveNames();
}
function addNameToList(name) {
var table = document.getElementById("namesList");
var row = table.insertRow();
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = name;
cell2.innerHTML = "<span class='remove-button'>X</span>";
cell2.firstChild.addEventListener("click", function() {
removeName(this);
});
}
function removeName(r) {
var i = r.parentNode.parentNode.rowIndex;
document.getElementById("namesList").deleteRow(i);
// Save the updated list to local storage
saveNames();
}
function saveNames() {
var names = [];
var rows = document.getElementById("namesList").rows;
for (var i = 0; i < rows.length; i++) {
names.push(rows[i].cells[0].textContent);
}
chrome.storage.local.set({'namesList': names});
}
document.getElementById("confirmButton").addEventListener("click", addName);