-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (44 loc) · 1.46 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
let myLeads = JSON.parse(localStorage.getItem("myLeads"));
if(myLeads===null){
myLeads = []
localStorage.setItem("myLeads",JSON.stringify(myLeads));
}
const inputEl = document.getElementById("input-el");
const inputBtn = document.getElementById("input-btn");
const ulList = document.getElementById("ul-el");
const dltBtn = document.getElementById("dlt-btn");
const grabTab = document.getElementById("grabtab-btn");
renderLeads();
inputBtn.addEventListener("click",save());
dltBtn.addEventListener("dblclick", function(){
localStorage.clear();
ulList.textContent = "";
})
grabTab.addEventListener("click",function(){
chrome.tabs.query({currentWindow: true, active: true}, function(tabs){
inputEl.value = tabs[0].url;
save();
});
})
function saveLead(leedLink){
myLeads = JSON.parse(localStorage.getItem("myLeads"))
myLeads.push(leedLink)
localStorage.setItem("myLeads",JSON.stringify(myLeads))
}
function save(){
var leadLink = inputEl.value;
if(leadLink!==''){
let li = document.createElement("li");
li.innerHTML = `<a href="${leadLink}" target="_blank">${leadLink}</a>`
ulList.append(li);
saveLead(leadLink);
inputEl.value = ''
}
}
function renderLeads(){
let listItem = "";
for(i=0;i<myLeads.length;i++){
listItem += `<li><a href="${myLeads[i]}" target="_blank">${myLeads[i]}</a></li>`;
}
ulList.innerHTML = listItem
}