-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprc.js
65 lines (55 loc) · 1.61 KB
/
prc.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
let myLeads = [];
const inputtext = document.getElementById('input-el');
const inputbutton = document.getElementById('input-btn');
const ulEl = document.getElementById('ul-el');
const showsaved = document.getElementById('showsavedarea');
const deletebutton = document.getElementById('delete-btn');
/*
let abc = `["www.1.com"]`;
abc = JSON.parse(abc) // array to string
abc.push("www.2.com") //push
abc = JSON.stringify(abc); // array to string
console.log(typeof abc) // verify it's a string
*/
let saveddata = JSON.parse(localStorage.getItem('myLeads'));
if(saveddata) {
myLeads = saveddata
renderLeads()
}
deletebutton.addEventListener('click', function(){
localStorage.clear();
myLeads = [];
renderLeads();
})
inputbutton.addEventListener('click', function(){
if(invalidinput()){
myLeads.push(inputtext.value)
inputtext.value = '';
localStorage.setItem('myLeads', JSON.stringify(myLeads));
renderLeads();
}
})
inputtext.addEventListener('keyup', (e) => {
if(e.key === 'Enter' && invalidinput() ){
myLeads.push(inputtext.value)
inputtext.value = '';
localStorage.setItem('myLeads', JSON.stringify(myLeads));
renderLeads();
}
});
function renderLeads(){
let listItems = '';
for (let i = 0; i < myLeads.length; i++) {
// listItems += "<li><a target='_blank' href='" + myLeads[i] + "'>" + myLeads[i] + "</a></li>"
listItems += `
<li>
<a target='_blank' href=https://shop.countdown.co.nz/shop/searchproducts?search='${myLeads[i]}'>
Search [ ${myLeads[i]} ] at Countdown supermarket
</a>
</li>`
}
ulEl.innerHTML = listItems;
}
function invalidinput(){
return inputtext.value !== '';
}