-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
85 lines (74 loc) · 2.47 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
var array=[];
var searchText="";
const baseURL="https://www.dep16pricelookupserv.net/";
function getArray() {
return fetch(baseURL.concat('data'))
.then(response => response.json())
.then(data => {
console.log(data);
data.forEach(element => {
array.push(element);
});
})
.catch(error => console.error(error));
/*
return fetch('temp.json').then(response=>response.json()).then(data=>{
data.forEach(element=>{
array.push(element);
})
})
*/
}
function getItems() {
this.getArray().then(()=>{
const suggestionContainer = document.getElementById("suggestions");
for (let i = 0; i < array.length; i++) {
const button = document.createElement("button");
button.textContent = array[i].id;
if (array[i].id.includes(button.textContent)) {
button.classList.add('suggestion-button');
}
button.addEventListener('click',()=>{
console.log(`${button.textContent} button clicked`)
sessionStorage.setItem('product', JSON.stringify(array[i]));
window.location.href = 'details.html';
})
suggestionContainer.appendChild(button);
}
})
}
function showSuggestions() {
const suggestionContainer = document.getElementById("suggestions");
searchText = document.getElementById("search-bar").value.toLowerCase();
const buttons = suggestionContainer.getElementsByTagName("button");
for (let i = 0; i < buttons.length; i++) {
const button = buttons[i];
const buttonText = button.textContent.toLowerCase();
if (buttonText.includes(searchText)) {
button.style.display = "block";
} else {
button.style.display = "none";
}
}
}
function secretPage() {
console.log("here we go")
window.location.href = 'image-page.html';
}
function resetContent() {
searchText="";
document.getElementById("search-bar").value="";
const suggestionContainer = document.getElementById("suggestions");
const buttons = suggestionContainer.getElementsByTagName("button");
console.log(buttons.length);
console.log(array.length);
for(let i=0;i<buttons.length;i++) {
buttons[i].style.display = "block";
}
}
function addNumber(num) {
searchText+=num+"";
document.getElementById("search-bar").value=searchText;
showSuggestions();
console.log(searchText);
}