-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
69 lines (54 loc) · 2.05 KB
/
options.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
function buildTableRow(nameValue, activeColumnsValue) {
const viewsTableBody = document.getElementById('views-table-body');
const tableRow = document.createElement("tr");
const nameCell = document.createElement("td");
const nameInput = document.createElement("input");
nameInput.setAttribute("type", "text");
nameInput.value = nameValue;
const activeColumnsCell = document.createElement("td");
const activeColumnsInput = document.createElement("textarea");
activeColumnsInput.value = activeColumnsValue;
const actionsCell = document.createElement('td');
const removeButton = document.createElement('button');
removeButton.textContent = 'Remove';
removeButton.classList.add('btn');
removeButton.classList.add('btn-danger');
removeButton.addEventListener('click', () => {
tableRow.remove();
});
nameCell.appendChild(nameInput);
activeColumnsCell.appendChild(activeColumnsInput);
actionsCell.appendChild(removeButton);
tableRow.appendChild(nameCell);
tableRow.appendChild(activeColumnsCell);
tableRow.appendChild(actionsCell);
viewsTableBody.appendChild(tableRow);
};
function loadViews() {
chrome.storage.local.get("views", (result) => {
result.views.forEach((view) => {
buildTableRow(view.name, view.activeColumns);
});
});
}
const addNewViewButton = document.getElementById('add-new-view');
const saveButton = document.getElementById('save');
addNewViewButton.addEventListener('click', () => {
buildTableRow('', '');
});
saveButton.addEventListener('click', () => {
const viewsTableBody = document.getElementById('views-table-body');
const tableRows = viewsTableBody.querySelectorAll('tr');
const views = [];
tableRows.forEach((tableRow) => {
const nameInput = tableRow.querySelector('input');
const allColumnsTextArea = tableRow.querySelector('textarea');
const name = nameInput.value;
const activeColumns = allColumnsTextArea.value;
views.push({ name, activeColumns });
});
chrome.storage.local.set({ views }, () => {
alert("All changes saved.");
});
});
loadViews();