-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
81 lines (74 loc) · 1.72 KB
/
Copy pathbackground.js
File metadata and controls
81 lines (74 loc) · 1.72 KB
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
var taskList = document.getElementById('taskList');
var form = document.getElementById('form');
var tasks = [];
form.addEventListener('submit', (e) => {
e.preventDefault();
if (
document.getElementsByClassName('at')[0].value != ''
) {
tasks.push(
document.getElementsByClassName('at')[0].value
);
render();
}
document.getElementsByClassName('at')[0].value = '';
chrome.runtime.sendMessage(
{ command: 'post', tasks },
(response) => {
console.log(response);
}
);
});
function render() {
taskList.innerHTML = '';
tasks.forEach((val, index) => {
var item = document.createElement('li');
var data;
if (val.slice(0, 4) == 'http') {
data =
"<button name='" +
index +
"' class='del'>-</button> <p> <a href='" +
val +
"'><abbr title='Ctrl + Click to open the link'>" +
val +
'</abbr></a></p>';
} else {
data =
"<button name='" +
index +
"' class='del'>-</button> <p> " +
val +
'</p>';
}
item.innerHTML = data;
taskList.prepend(item);
});
addButtonEvents();
store();
}
function store() {
chrome.storage.local.set({ tasks: tasks });
}
function load() {
chrome.storage.local.get(['tasks'], function (result) {
if (result.tasks) {
tasks = result.tasks;
render();
}
});
}
function addButtonEvents() {
var buttons = document.getElementsByClassName('del');
for (button of buttons) {
button.addEventListener('click', (e) => {
remove(e.srcElement.name);
});
}
}
function remove(index) {
tasks.splice(parseInt(index), 1);
render();
}
//initial load and render
load();