Skip to content

Commit 32481b8

Browse files
committed
use stock JSON entries field for data
1 parent d148df0 commit 32481b8

File tree

2 files changed

+40
-61
lines changed

2 files changed

+40
-61
lines changed

src/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ <h3 class="center-text">
3232
<tr class="tbl-head">
3333
<th>API</th>
3434
<th>Description</th>
35-
<th>Authorization</th>
35+
<th>Auth</th>
3636
<th>HTTPS</th>
3737
<th>Category</th>
3838
</tr>
@@ -43,7 +43,7 @@ <h3 class="center-text">
4343
<td>{{ item.Description }}</td>
4444
<td>{{ (item.Auth) ? item.Auth : '-' }}</td>
4545
<td>{{ (item.HTTPS) ? '✔' : '✖' }}</td>
46-
<td class="lol">{{ item.Section }}</td>
46+
<td class="lol">{{ item.Category }}</td>
4747
</tr>
4848
</tbody>
4949
</table>

src/scripts.js

Lines changed: 38 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,18 @@
1-
function loadJSON(callback) {
2-
var xobj = new XMLHttpRequest();
3-
xobj.overrideMimeType("application/json");
4-
xobj.open('GET', 'https://raw.githubusercontent.com/toddmotto/public-apis/master/json/entries.min.json', true);
5-
xobj.onreadystatechange = function () {
6-
if (xobj.readyState == 4 && xobj.status == "200") {
7-
// Required use of an anonymous callback as .open will NOT return a value
8-
// but simply returns undefined in asynchronous mode
9-
callback(xobj.responseText);
10-
}
11-
};
12-
xobj.send(null);
13-
}
14-
15-
function filterRows() {
16-
17-
var input, filter, table, tr, td, i;
18-
19-
input = document.getElementById("searchbox");
20-
filter = input.value.toUpperCase();
21-
table = document.getElementById("entries");
22-
tr = table.getElementsByTagName("tr");
23-
24-
// Loop through all table rows and hide those who don't match the search
25-
for (i = 0; i < tr.length; i++) {
26-
27-
displayRows = false;
28-
29-
title = tr[i].getElementsByTagName("td")[0];
30-
if (title) {
31-
if (title.innerHTML.toUpperCase().indexOf(filter) > -1) {
32-
displayRows = true;
33-
}
34-
}
35-
section = tr[i].getElementsByTagName("td")[4];
36-
if (section) {
37-
if (section.innerHTML.toUpperCase().indexOf(filter) > -1) {
38-
displayRows = true;
39-
}
40-
}
41-
if (displayRows) {
42-
tr[i].style.display = "";
43-
} else {
44-
tr[i].style.display = "none";
45-
}
46-
}
47-
}
48-
49-
loadJSON(function(response) {
50-
var items = JSON.parse(response);
1+
loadJSON(function(response) {
2+
var items = JSON.parse(response);
513
new Vue({
524
data: {
535
filter: ''
546
},
557
computed: {
568
data() {
57-
let output = [];
58-
for (var category in items) {
59-
for (var api in items[category]) {
60-
items[category][api].Category = category;
61-
output.push(items[category][api]);
62-
}
63-
}
64-
return output;
9+
return items.entries;
6510
}
6611
},
6712
methods: {
6813
filtered(item) {
6914
let show = true;
70-
15+
7116
if(this.filter.length) {
7217

7318
show = false;
@@ -91,3 +36,37 @@ loadJSON(function(response) {
9136
}
9237
}).$mount('#app');
9338
});
39+
40+
function loadJSON(callback) {
41+
var xobj = new XMLHttpRequest();
42+
xobj.overrideMimeType("application/json");
43+
xobj.open('GET', 'https://raw.githubusercontent.com/toddmotto/public-apis/master/json/entries.min.json', true);
44+
xobj.onreadystatechange = function () {
45+
if (xobj.readyState == 4 && xobj.status == "200") {
46+
// Required use of an anonymous callback as .open will NOT return a value
47+
// but simply returns undefined in asynchronous mode
48+
callback(xobj.responseText);
49+
}
50+
};
51+
xobj.send(null);
52+
}
53+
54+
function filterRows() {
55+
var input, filter, table, tr, td, i;
56+
input = document.getElementById("searchbox");
57+
filter = input.value.toUpperCase();
58+
table = document.getElementById("entries");
59+
tr = table.getElementsByTagName("tr");
60+
61+
// Loop through all table rows and hide those who don't match the search
62+
for (i = 0; i < tr.length; i++) {
63+
td = tr[i].getElementsByTagName("td")[0];
64+
if (td) {
65+
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
66+
tr[i].style.display = "";
67+
} else {
68+
tr[i].style.display = "none";
69+
}
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)