-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
102 lines (84 loc) · 2.43 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
let datas =[]
let inputj= document.querySelector("input");
let valuej = "";
let divj= document.querySelector(".ul");
const ulj = document.querySelector("ul");
const buttonj = document.querySelector("#submit");
const deletej = document.querySelector("#delete");
const tabj = document.querySelector("#tab");
const dltj = document.querySelector(".delete-btn");
fetchdata();
div();
function div(){
if(datas.length > 0){
divj.style.display="block";
}
}
function fetchdata(){
ulj.innerHTML="";
if(localStorage.key('data') != null){
datas=JSON.parse(localStorage.getItem("data"));
for (i=datas.length-1; i>-1; i--){
ulj.innerHTML+=`
<li>
<a target="_blank" href="${datas[i]}"> ${datas[i]} </a>
<button class="delete-btn" type="submit" value="${datas[i]}">
Delete
</button>
</li>`;
}
}
else if(datas.length == 0 || localStorage.key('data')== null){
divj.style.display="none";
}
}
ulj.addEventListener("click", function(event) {
if (event.target.classList.contains("delete-btn")) {
dlt(event.target.value);
}
});
function dlt(val){
datas=JSON.parse(localStorage.getItem("data"));
b=datas.indexOf(val);
datas.splice(b,1);
localStorage.setItem("data",JSON.stringify(datas));
if(localStorage.getItem('data') == "[]"){
localStorage.clear();
datas =[];
fetchdata();
}
fetchdata();
}
tabj.addEventListener('click',function(){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
valuej = tabs[0].url;
})
if(valuej != ""){
datas.push(valuej);
localStorage.setItem("data",JSON.stringify(datas));
div();
}
inputj.value="";
fetchdata();
})
deletej.addEventListener("click",function(){
localStorage.clear();
datas =[];
fetchdata();
})
inputj.addEventListener("keypress",function(event){
if(event.key === "Enter"){
event.preventDefault();
buttonj.click();
}
})
buttonj.addEventListener("click", function(){
valuej = inputj.value;
if(valuej != ""){
datas.push(valuej);
localStorage.setItem("data",JSON.stringify(datas));
div();
}
inputj.value="";
fetchdata();
})