-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalert.js
60 lines (45 loc) · 1.45 KB
/
alert.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
var array = [];
var count = 1;
chrome.storage.sync.get(['name'], function(result) {
result.name.forEach(function(item){
array.push(item);
});
});
function redirect(){
$input = document.querySelector("#name");
var length = $("#name").val().length;
if (length < 1){
alert('empty');
return;
}
array.push($input.value);
var d1 = document.getElementById('items');
d1.insertAdjacentHTML('beforeend', '<br><div class="remove" id= ' + count + ' size= 2345>' +
count + ". " + $input.value +
'<button id=' + count + '>Remove this item</button>' +
'</div>');
chrome.storage.sync.set({'name':array}, function() {
//console.log(array);
});
}
$(document).ready(function(){
chrome.storage.sync.get(['name'], function(result) {
result.name.forEach(function(item){
var d1 = document.getElementById('items');
d1.insertAdjacentHTML('beforeend', '<br><div class="remove" id= ' + count + '>' +
count + ". " + item +
'<button id=' + count + '>Remove this item</button>' +
'</div>');
count++;
});
});
document.getElementById('clickme').addEventListener('click', redirect);
var els = document.getElementsByClassName('remove');
console.log(els.length);
for (var i = 0; i < els.length; i++) {
console.log(elsp[i]);
els[i].addEventListener('click', function () {
console.log(els[i].id);
});
}
});