-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
78 lines (59 loc) · 1.74 KB
/
index.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
70
71
72
73
74
75
76
77
78
let arr = [];
const inputEl = document.getElementById("input-el");
const saveEl = document.getElementById("input-btn");
const tabEl = document.getElementById("tab-btn");
const deleteEl = document.getElementById("delete-btn");
const ulEl = document.getElementById("ul-tag");
const sitesFromLocalStorage = JSON.parse( localStorage.getItem("mysites") );
if (sitesFromLocalStorage) {
arr = sitesFromLocalStorage;
render(arr);
}
tabEl.addEventListener("click",function(){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
console.log("prine");
arr.push(tabs[0].url);
localStorage.setItem("mysites", JSON.stringify(arr) );
render(arr);
})
})
function insertion_sort(array){
for(let i=1;i<array.length;i++){
let curr = i;
while (curr!=0){
var temp = array[curr];
[array[curr], array[curr-1]] = [array[curr-1], array[curr]];
curr -= 1;
}
}
}
function render(array){
let items = ""
if (array.length>1){
insertion_sort(array);
}
for(let i=0;i<array.length;i++){
if (array[i]==""){
array.pop(i);
break;
}
items += `
<li>
<span>${i} ) </span> <a target="_blank" href="${array[i]}">${array[i]}
</a>
</li>
`;
}
ulEl.innerHTML = items;
}
saveEl.addEventListener("click",function(){
arr.push(inputEl.value);
inputEl.value = "";
localStorage.setItem("mysites", JSON.stringify(arr));
render(arr);
})
deleteEl.addEventListener("click",function(){
localStorage.clear();
arr = [];
render(arr);
})