-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
93 lines (72 loc) · 2.28 KB
/
app.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
let input = document.querySelector('.categories');
let count = document.querySelector('.count');
let apiList = document.querySelector('.apis');
let loaderHTML = document.querySelector('.loader');
let scrollToTopBtn = document.querySelector('#top');
document.querySelector('.show-btn').addEventListener('click', getApis);
const renderLoader = () => {
let loader = `<div class="spinner-border spinner" role="status"></div>`;
loaderHTML.insertAdjacentHTML('beforeend', loader);
}
const clearLoader = () => {
let spinner = document.querySelector('.spinner');
if (spinner) {
spinner.parentElement.removeChild(spinner);
}
}
async function getApis() {
apiList.innerHTML = "";
count.textContent = "";
let category = input.value;
renderLoader();
fetch(`https://api.publicapis.org/entries?category=${category}&https=true`)
.then(apis => {
data = apis.json();
return data;
}
)
.then(data => {
// console.log(data);
count.textContent = `${data.count} Apis found`;
let entries = data.entries;
// console.log(entries);
clearLoader();
entries.forEach(el => {
if (el.Auth == "")
el.Auth = 'No Auth';
displayApi(el);
});
window.scrollBy(0,300);
})
.catch(error => {
if (error) {
alert("Sorry, Something went wrong !");
}
})
}
const displayApi = (el) => {
let markup = `
<div class="apibox card " data-aos="fade-up">
<h4 class="mt-4">${el.API}</h4>
<p class="blue">${el.Description}</p>
<p class="float-left">Auth Type : ${el.Auth}</p>
<a href=${el.Link} class="btn link float-right" target="_blank" >View</a>
</div>
`;
apiList.insertAdjacentHTML('beforeend', markup)
}
//Scroll to top button
let displayScrollBtn = () => {
let y = window.scrollY;
if (y > 200) { scrollToTopBtn.classList.replace("hide", "show") }
else { scrollToTopBtn.classList.replace("show", "hide"); }
}
window.addEventListener('scroll', displayScrollBtn);
scrollToTopBtn.addEventListener('click', function () {
window.scrollTo({
top: 0,
left: 0,
behavior: 'smooth'
})
});
// Made by Mayank Rajput #hackelite01