CheckLink Status
This commit is contained in:
@@ -14,7 +14,6 @@ const links = [
|
||||
"https://nosotros.btcforplebs.com",
|
||||
"https://mint.btcforplebs.com",
|
||||
"https://cashu.btcforplebs.com",
|
||||
"https://nostrapps.com",
|
||||
// Add more links as needed
|
||||
];
|
||||
|
||||
|
||||
@@ -2,14 +2,11 @@ module.exports = {
|
||||
port: process.env.PORT || 5252,
|
||||
// Add any other configuration variables here
|
||||
allowedOrigins: [
|
||||
'http://localhost',
|
||||
'http://localhost:5252',
|
||||
'https://localhost',
|
||||
'https://localhost:5252',
|
||||
'https://localhost:5252',
|
||||
'https://localhost:9000',
|
||||
'http://localhost:9000',
|
||||
'https://btcforplebs.com',
|
||||
'https://www.btcforplebs.com',
|
||||
'http://btcforplebs.com',
|
||||
'http://www.btcforplebs.com',
|
||||
'https://services.btcforplebs.com',
|
||||
'http://services.btcforplebs.com'
|
||||
]
|
||||
|
||||
@@ -1,35 +1,3 @@
|
||||
// Store statuses globally
|
||||
let linkStatuses = {};
|
||||
|
||||
// Fetch statuses on page load
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// Fetch statuses immediately but keep folders closed
|
||||
fetch(`${config.apiBaseUrl}/api/link-status`)
|
||||
.then(res => res.json())
|
||||
.then(statuses => {
|
||||
linkStatuses = statuses; // Store for later use
|
||||
console.log("Cached link statuses:", linkStatuses);
|
||||
})
|
||||
.catch(error => console.error("Error:", error));
|
||||
});
|
||||
|
||||
// Helper function to update status emojis
|
||||
function updateFolderStatuses(folder, statuses) {
|
||||
folder.querySelectorAll("a").forEach(link => {
|
||||
const url = link.href;
|
||||
const matchingUrl = Object.keys(statuses).find(statusUrl =>
|
||||
url.includes(new URL(statusUrl).hostname)
|
||||
);
|
||||
const status = matchingUrl ? statuses[matchingUrl] : "unknown";
|
||||
const emoji = status === "online" ? "🟢" : "🔴";
|
||||
|
||||
const statusSpan = link.querySelector('.status-emoji');
|
||||
if (statusSpan) {
|
||||
statusSpan.textContent = emoji;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function toggleFolder(folderId, buttonId) {
|
||||
const folder = document.getElementById(folderId);
|
||||
const button = document.getElementById(buttonId);
|
||||
@@ -39,54 +7,8 @@ function toggleFolder(folderId, buttonId) {
|
||||
folder.style.display = "block";
|
||||
button.innerHTML = button.innerHTML.replace("↓", "↑");
|
||||
|
||||
// Use cached statuses if available, otherwise fetch new ones
|
||||
if (Object.keys(linkStatuses).length > 0) {
|
||||
updateFolderStatuses(folder, linkStatuses);
|
||||
} else {
|
||||
fetch(`${config.apiBaseUrl}/api/link-status`)
|
||||
.then(res => res.json())
|
||||
.then(statuses => {
|
||||
linkStatuses = statuses;
|
||||
updateFolderStatuses(folder, statuses);
|
||||
})
|
||||
.catch(error => console.error("Error:", error));
|
||||
}
|
||||
} else {
|
||||
folder.style.display = "none";
|
||||
button.innerHTML = button.innerHTML.replace("↑", "↓");
|
||||
}
|
||||
// Wait for both DOM and fetch to complete
|
||||
async function init() {
|
||||
try {
|
||||
// Fetch the status first
|
||||
console.log("Fetching statuses...");
|
||||
const response = await fetch(`${config.apiBaseUrl}/api/link-status`);
|
||||
const statuses = await response.json();
|
||||
console.log("Got statuses:", statuses);
|
||||
|
||||
// Now update the links
|
||||
document.querySelectorAll(".links a").forEach(link => {
|
||||
const url = link.href;
|
||||
console.log('Checking link:', url); // Debug log
|
||||
const matchingUrl = Object.keys(statuses).find(statusUrl => {
|
||||
const linkHostname = new URL(url).hostname;
|
||||
const statusHostname = new URL(statusUrl).hostname;
|
||||
console.log('Comparing:', linkHostname, 'with', statusHostname); // Debug log
|
||||
return linkHostname === statusHostname;
|
||||
});
|
||||
console.log('Matching URL found:', matchingUrl); // Debug log
|
||||
const status = matchingUrl ? statuses[matchingUrl] : "unknown";
|
||||
console.log('Status for', url, 'is', status); // Debug log
|
||||
const emoji = status === "online" ? "🟢" : "🔴";
|
||||
|
||||
// Find the span inside this link and update it
|
||||
const statusSpan = link.querySelector('.status-emoji');
|
||||
if (statusSpan) {
|
||||
statusSpan.textContent = emoji;
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
@@ -19,6 +21,7 @@
|
||||
<!-- scripts -->
|
||||
|
||||
<script src="/assets/js/home.js"></script>
|
||||
<script src="/assets/js/scripts.js"></script>
|
||||
<link rel="stylesheet" href="/assets/css/main.css">
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" rel="stylesheet">
|
||||
</head>
|
||||
@@ -31,44 +34,103 @@
|
||||
<h3>A place to help ordinary people learn about Bitcoin</h3>
|
||||
<img src="/images/btcforplebs_profile.gif" alt="Profile Picture" class="profile-picture">
|
||||
|
||||
<div class="button-div">
|
||||
<!-- Buttons -->
|
||||
<a href="/learn-bitcoin" class="button" class="prefetch">Learn About Bitcoin</a>
|
||||
<a href="/learn-nostr" class="button" class="prefetch">Learn About Nostr</a>
|
||||
<a href="/learn-cashu" class="button" class="prefetch">Learn About Cashu</a>
|
||||
<a href="/bitcoin-and-the-bible" class="button" class="prefetch">Bitcoin & The Bible</a>
|
||||
</div>
|
||||
<button class="button" id="bitcoin-folder-btn" onclick="toggleFolder('folder2', 'bitcoin-folder-btn')">Use Bitcoin <span style="color: #F7931A;">↓</span></button>
|
||||
<div class="links" id="folder2">
|
||||
<a href="https://lightning.btcforplebs.com" target="_blank" class="prefetch">Lightning <span class="status-emoji"></span></a>
|
||||
<a href="https://mempool.btcforplebs.com" target="_blank" class="prefetch">Mempool <span class="status-emoji"></span></a>
|
||||
<a href="https://bitview.space/" target="_blank" class="prefetch">Bitview.space ⚪️</span></a>
|
||||
</div>
|
||||
|
||||
<button class="button" id="nostr-folder-btn" onclick="toggleFolder('folder1', 'nostr-folder-btn')">Use Nostr <span style="color: #F7931A;">↓</span></button>
|
||||
<div class="links" id="folder1">
|
||||
<a href="https://nostrudel.btcforplebs.com" target="_blank" class="prefetch">Nostrudel <span class="status-emoji"></span></a>
|
||||
<a href="https://nosotros.btcforplebs.com" target="_blank" class="prefetch">Nosotros <span class="status-emoji"></span></a>
|
||||
<a href="https://bloom.btcforplebs.com" target="_blank" class="prefetch">Bloom <span class="status-emoji"></span></a>
|
||||
<a href="https://relay.btcforplebs.com" target="_blank" class="prefetch">Relay <span class="status-emoji"></span></a>
|
||||
<a href="https://nostrapps.com" target="_blank">NostrApps.com ⚪️</a>
|
||||
</div>
|
||||
<button class="button" id="cashu-folder-btn" onclick="toggleFolder('folder3', 'cashu-folder-btn')">Use Cashu <span style="color: #F7931A;">↓</span></button>
|
||||
<div class="links" id="folder3">
|
||||
<a href="https://cashu.btcforplebs.com" class="prefetch">Cashu Web App <span class="status-emoji"></span></a>
|
||||
<a href="https://macadamia.cash" class="prefetch">Macadamia (iOS) ⚪️</a>
|
||||
<a href="https://minibits.cash" class="prefetch">Minibits (Android) ⚪️</a>
|
||||
</div>
|
||||
<!-- Learn Links (unchanged) -->
|
||||
<a href="/learn-bitcoin" class="button prefetch">Learn About Bitcoin</a>
|
||||
<a href="/learn-nostr" class="button prefetch">Learn About Nostr</a>
|
||||
<a href="/learn-cashu" class="button prefetch">Learn About Cashu</a>
|
||||
<a href="/bitcoin-and-the-bible" class="button prefetch">Bitcoin & The Bible</a>
|
||||
|
||||
<!-- Bitcoin Links -->
|
||||
<button class="button" id="bitcoin-folder-btn" onclick="toggleFolder('folder2', 'bitcoin-folder-btn')">Use Bitcoin <span style="color: #F7931A;">↓</span></button>
|
||||
<div class="links" id="folder2">
|
||||
<a href="https://lightning.btcforplebs.com" target="_blank" class="prefetch">
|
||||
Lightning <span class="status-emoji" data-url="https://lightning.btcforplebs.com">⏳</span>
|
||||
</a>
|
||||
<a href="https://mempool.btcforplebs.com" target="_blank" class="prefetch">
|
||||
Mempool <span class="status-emoji" data-url="https://mempool.btcforplebs.com">⏳</span>
|
||||
</a>
|
||||
<a href="https://bitview.space/" target="_blank" class="prefetch">
|
||||
Bitview.space ⚪️
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Nostr Links -->
|
||||
<button class="button" id="nostr-folder-btn" onclick="toggleFolder('folder1', 'nostr-folder-btn')">Use Nostr <span style="color: #F7931A;">↓</span></button>
|
||||
<div class="links" id="folder1">
|
||||
<a href="https://nostrudel.btcforplebs.com" target="_blank" class="prefetch">
|
||||
Nostrudel <span class="status-emoji" data-url="https://nostrudel.btcforplebs.com">⏳</span>
|
||||
</a>
|
||||
<a href="https://nosotros.btcforplebs.com" target="_blank" class="prefetch">
|
||||
Nosotros <span class="status-emoji" data-url="https://nosotros.btcforplebs.com">⏳</span>
|
||||
</a>
|
||||
<a href="https://bloom.btcforplebs.com" target="_blank" class="prefetch">
|
||||
Bloom <span class="status-emoji" data-url="https://bloom.btcforplebs.com">⏳</span>
|
||||
</a>
|
||||
<a href="https://relay.btcforplebs.com" target="_blank" class="prefetch">
|
||||
Relay <span class="status-emoji" data-url="https://relay.btcforplebs.com">⏳</span>
|
||||
</a>
|
||||
<a href="https://nostrapps.com" target="_blank">
|
||||
NostrApps.com ⚪️
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Cashu Links -->
|
||||
<button class="button" id="cashu-folder-btn" onclick="toggleFolder('folder3', 'cashu-folder-btn')">Use Cashu <span style="color: #F7931A;">↓</span></button>
|
||||
<div class="links" id="folder3">
|
||||
<a href="https://cashu.btcforplebs.com" class="prefetch">
|
||||
Cashu Web App <span class="status-emoji" data-url="https://cashu.btcforplebs.com">⏳</span>
|
||||
</a>
|
||||
<a href="https://macadamia.cash" class="prefetch">
|
||||
Macadamia (iOS) ⚪️
|
||||
</a>
|
||||
<a href="https://minibits.cash" class="prefetch">
|
||||
Minibits (Android) ⚪️
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<a href="https://live.btcforplebs.com" class="button" class="prefetch">BTCforPlebs Live<span class="status-emoji"></span></a>
|
||||
<br></br>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
|
||||
const apiEndpoint = "http://localhost:5252/api/link-status";
|
||||
|
||||
async function init() {
|
||||
try {
|
||||
console.log("🔄 Fetching statuses from:", apiEndpoint);
|
||||
const response = await fetch(apiEndpoint);
|
||||
const statuses = await response.json();
|
||||
console.log("✅ Received statuses:", statuses);
|
||||
|
||||
document.querySelectorAll(".status-emoji[data-url]").forEach(span => {
|
||||
const url = span.dataset.url;
|
||||
console.log("🔍 Checking span for:", url);
|
||||
|
||||
if (!url) {
|
||||
console.warn("⚠️ Span missing data-url:", span);
|
||||
return;
|
||||
}
|
||||
|
||||
const status = statuses[url];
|
||||
|
||||
if (!status) {
|
||||
console.warn(`⚠️ No status found in JSON for: ${url}`);
|
||||
} else {
|
||||
const emoji = status === "online" ? "🟢" : "🔴";
|
||||
console.log(`✅ ${url} is ${status}, setting emoji: ${emoji}`);
|
||||
span.textContent = `${emoji} `;
|
||||
span.style.display = 'inline-block';
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("❌ Error fetching or processing statuses:", error);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<div id="footer"></div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
Reference in New Issue
Block a user