Spaces:
Paused
Paused
Create script.js
Browse files- public/script.js +107 -0
public/script.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
let menuVisible = false;
|
| 2 |
+
|
| 3 |
+
document.addEventListener("DOMContentLoaded", () => {
|
| 4 |
+
fetch('/jonellmagallanes')
|
| 5 |
+
.then(response => response.json())
|
| 6 |
+
.then(data => {
|
| 7 |
+
const apiList = document.getElementById('api-list');
|
| 8 |
+
const categories = {};
|
| 9 |
+
|
| 10 |
+
data.forEach(api => {
|
| 11 |
+
if (!categories[api.category]) {
|
| 12 |
+
categories[api.category] = [];
|
| 13 |
+
}
|
| 14 |
+
categories[api.category].push(api);
|
| 15 |
+
});
|
| 16 |
+
|
| 17 |
+
const sortedCategories = Object.keys(categories).sort();
|
| 18 |
+
|
| 19 |
+
sortedCategories.forEach(category => {
|
| 20 |
+
const categoryButton = document.createElement('button');
|
| 21 |
+
categoryButton.className = "block w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 transition duration-300 ease-in-out transform hover:scale-105";
|
| 22 |
+
categoryButton.textContent = category;
|
| 23 |
+
categoryButton.onclick = () => toggleCategory(categoryButton);
|
| 24 |
+
apiList.appendChild(categoryButton);
|
| 25 |
+
|
| 26 |
+
const categoryDiv = document.createElement('div');
|
| 27 |
+
categoryDiv.id = category;
|
| 28 |
+
categoryDiv.className = 'hidden px-4 py-2';
|
| 29 |
+
|
| 30 |
+
categories[category].forEach(api => {
|
| 31 |
+
const fullUsage = `${api.usages}${api.query || ''}`;
|
| 32 |
+
const apiDiv = document.createElement('div');
|
| 33 |
+
apiDiv.innerHTML = `
|
| 34 |
+
<strong>${api.name}</strong>
|
| 35 |
+
<p>${api.desc}</p>
|
| 36 |
+
<p>Method: ${api.method.toUpperCase()}</p>
|
| 37 |
+
<p>Usage: <a href="${fullUsage}">${fullUsage}</a></p>
|
| 38 |
+
<button onclick="tryApi('${fullUsage}')" class="mt-2 px-4 py-2 bg-indigo-500 text-white text-sm rounded hover:bg-indigo-700 transition duration-300 ease-in-out transform hover:scale-105">Try</button>
|
| 39 |
+
`;
|
| 40 |
+
categoryDiv.appendChild(apiDiv);
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
apiList.appendChild(categoryDiv);
|
| 44 |
+
});
|
| 45 |
+
});
|
| 46 |
+
|
| 47 |
+
fetch('/requests')
|
| 48 |
+
.then(response => response.json())
|
| 49 |
+
.then(data => {
|
| 50 |
+
document.getElementById('request-count').textContent = `Request API: ${data.request}`;
|
| 51 |
+
});
|
| 52 |
+
|
| 53 |
+
setInterval(updateTime, 1000);
|
| 54 |
+
document.getElementById('user-agent').textContent = `User Agent: ${navigator.userAgent}`;
|
| 55 |
+
|
| 56 |
+
fetch('https://api.ipify.org?format=json')
|
| 57 |
+
.then(response => response.json())
|
| 58 |
+
.then(data => {
|
| 59 |
+
document.getElementById('ip').textContent = `IP Address: ${data.ip}`;
|
| 60 |
+
});
|
| 61 |
+
|
| 62 |
+
document.getElementById('device-info').classList.add('fade-in');
|
| 63 |
+
});
|
| 64 |
+
|
| 65 |
+
function toggleCategory(button) {
|
| 66 |
+
const allButtons = document.querySelectorAll('#api-list > button');
|
| 67 |
+
allButtons.forEach(btn => btn.classList.remove('highlighted'));
|
| 68 |
+
|
| 69 |
+
const categoryDiv = document.getElementById(button.textContent);
|
| 70 |
+
button.classList.toggle('highlighted');
|
| 71 |
+
categoryDiv.classList.toggle('hidden');
|
| 72 |
+
categoryDiv.classList.add('pop-up');
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
function tryApi(fullUsage) {
|
| 76 |
+
window.location.href = fullUsage;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function toggleMenu() {
|
| 80 |
+
const menu = document.getElementById('menu');
|
| 81 |
+
const toggleButton = document.getElementById('toggle-button');
|
| 82 |
+
|
| 83 |
+
if (menuVisible) {
|
| 84 |
+
menu.classList.remove('slide-in');
|
| 85 |
+
menu.classList.add('slide-out');
|
| 86 |
+
toggleButton.classList.remove('toggle-icon-vertical');
|
| 87 |
+
toggleButton.classList.add('toggle-icon-horizontal');
|
| 88 |
+
setTimeout(() => {
|
| 89 |
+
menu.classList.add('hidden');
|
| 90 |
+
toggleButton.style.zIndex = 1001;
|
| 91 |
+
}, 500);
|
| 92 |
+
} else {
|
| 93 |
+
menu.classList.remove('hidden');
|
| 94 |
+
menu.classList.remove('slide-out');
|
| 95 |
+
menu.classList.add('slide-in');
|
| 96 |
+
toggleButton.classList.remove('toggle-icon-horizontal');
|
| 97 |
+
toggleButton.classList.add('toggle-icon-vertical');
|
| 98 |
+
toggleButton.style.zIndex = 1001;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
menuVisible = !menuVisible;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
function updateTime() {
|
| 105 |
+
const now = new Date();
|
| 106 |
+
document.getElementById('current-time').textContent = `Current Time: ${now.toLocaleTimeString()}`;
|
| 107 |
+
}
|