-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
149 lines (128 loc) · 6.17 KB
/
script.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const api = 'https://api.publicapis.org/entries';
fetch(api)
.then(response => response.json())
.then(data => {
const entries = data.entries.slice(0, 100);
allData(entries);
});
function allData(data) {
let card = ``;
data.forEach(d => card += cards(d));
document.querySelector('.content-cards').innerHTML = card;
document.querySelector('.content h1').innerHTML = 'Example Data';
document.querySelector('.content p > strong').innerHTML = data.length;
no(data);
apiKey(data);
OAuth(data);
}
// Untuk menampilkan data api yang dicari berdasarkan nama dari api.
const search = document.getElementById('search');
search.addEventListener('input', async function() {
fetch(api)
.then(response => response.json())
.then(data => {
const keyword = search.value;
const result = data.entries.filter(d => d.API.toLowerCase().includes(keyword.toLowerCase()));
searchData(result);
});
});
function searchData(data) {
let card = ``;
data.forEach(d => card += cards(d));
document.querySelector('.content-cards').innerHTML = card;
document.querySelector('.content h1').innerHTML = 'Result';
document.querySelector('.content p > strong').innerHTML = data.length;
no(data);
apiKey(data);
OAuth(data);
}
const buttons = document.querySelectorAll('.sidebar-link ul li');
buttons.forEach(button => {
button.addEventListener('click', function() {
const id = this.id;
fetch(api)
.then(response => response.json())
.then(data => {
const entries = data.entries.filter(result => result.Category.toLowerCase() == id);
sidebar(entries);
});
});
});
function sidebar(data) {
let card = '';
data.forEach(category => card += cards(category));
document.querySelector('.content-cards').innerHTML = card;
document.querySelector('.content h1').innerHTML = "Result";
document.querySelector('.content p > strong').innerHTML = data.length;
no(data);
apiKey(data);
OAuth(data);
}
function no(data) {
// Untuk menampilkan jumlah data api yang tidak membutuhkan autentikasi
let totalNo = ``;
const no = data.filter(d => d.Auth === '');
const nos = document.querySelector('.no');
totalNo += `
<h1>${no.length}</h1>
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M14.59 8L12 10.59 9.41 8 8 9.41 10.59 12 8 14.59 9.41 16 12 13.41 14.59 16 16 14.59 13.41 12 16 9.41 14.59 8zM12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z"/></svg>
`;
nos.innerHTML = totalNo;
}
function apiKey(data) {
// Untuk menampilkan jumlah data api yang membutuhkan autentikasi dengan apiKey
let totalApikey = ``;
const apiKey = data.filter(d => d.Auth === 'apiKey');
const apiKeys = document.querySelector('.apikey');
totalApikey += `
<h1>${apiKey.length}</h1>
<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><rect fill="none" height="24" width="24"/></g><g><path d="M21,10h-8.35C11.83,7.67,9.61,6,7,6c-3.31,0-6,2.69-6,6s2.69,6,6,6c2.61,0,4.83-1.67,5.65-4H13l2,2l2-2l2,2l4-4.04L21,10z M7,15c-1.65,0-3-1.35-3-3c0-1.65,1.35-3,3-3s3,1.35,3,3C10,13.65,8.65,15,7,15z"/></g></svg>
`;
apiKeys.innerHTML = totalApikey;
}
function OAuth(data) {
// Untuk menampilkan jumlah data api yang membutuhkan autentikasi dengan OAuth.
let totalOAuth = ``;
const oauth = data.filter(d => d.Auth === 'OAuth');
const oauths = document.querySelector('.oauth');
totalOAuth += `
<h1>${oauth.length}</h1>
<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><path d="M0,0h24v24H0V0z" fill="none"/></g><g><path d="M17,8l-1.41,1.41L17.17,11H9v2h8.17l-1.58,1.58L17,16l4-4L17,8z M5,5h7V3H5C3.9,3,3,3.9,3,5v14c0,1.1,0.9,2,2,2h7v-2H5V5z"/></g></svg>
`;
oauths.innerHTML = totalOAuth;
}
function cards(result) {
return `
<div class="card">
<div class="card-body">
<h3>${result.API}</h3>
<p>${result.Description}</p>
</div>
<div class="card-footer">
<div class="card-key">
<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><rect fill="none" height="24" width="24"/></g><g><path d="M21,10h-8.35C11.83,7.67,9.61,6,7,6c-3.31,0-6,2.69-6,6s2.69,6,6,6c2.61,0,4.83-1.67,5.65-4H13l2,2l2-2l2,2l4-4.04L21,10z M7,15c-1.65,0-3-1.35-3-3c0-1.65,1.35-3,3-3s3,1.35,3,3C10,13.65,8.65,15,7,15z"/></g></svg>
<span>${result.Auth === "" ? "No Auth" : result.Auth}</span>
</div>
<a href="${result.Link}" target="_blank">Visit Site</a>
</div>
</div>
`;
}
const sidebars = document.querySelectorAll('.sidebar-link ul li');
sidebars.forEach(sidebar => {
sidebar.addEventListener('click', function() {
for(const sidebar of sidebars) {
sidebar.classList.remove('active');
}
sidebar.classList.add('active');
});
});
const toggle = document.getElementById('toggle');
toggle.addEventListener('click', () => {
const sidebar = document.querySelector('.sidebar');
const sidebarBrandSpan = document.querySelector('.sidebar .sidebar-brand span');
sidebar.classList.toggle('side');
sidebarBrandSpan.addEventListener('click', () => {
sidebar.classList.remove('side');
});
});