-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0105836
commit b379961
Showing
3 changed files
with
67 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,15 @@ | ||
<html lang="en" data-bs-theme="dark"> | ||
<head> | ||
<title>Freddit Freebuild</title> | ||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta property="og:image" content="https://freddit.net/assets/imgs/freddit-freebuild.png"> | ||
<meta property="og:title" content="Freddit Freebuild"> | ||
<meta property="og:description" content="The world's only Minecraft server since 2015"> | ||
|
||
<title>Freddit Freebuild</title> | ||
<link rel="icon" type="image/png" href="assets/favico.webp"> | ||
<link rel="stylesheet" href="style.css"> | ||
|
||
<!-- Bootstrap CSS --> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> | ||
|
||
<style> | ||
main { | ||
max-width: 600px; | ||
margin: 0 auto; | ||
padding: 20px; | ||
} | ||
code { | ||
border-radius: 4px; | ||
padding: 2px 4px; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
|
@@ -38,7 +25,6 @@ | |
</main> | ||
</body> | ||
|
||
<!-- copy to clipboard toast --> | ||
<div class="toast" id="copied-toast" style="position: absolute; top: 0; right: 0;" autohide="true" data-bs-delay="2000"> | ||
<div class="toast-header"> | ||
<strong class="me-auto">Copied!</strong> | ||
|
@@ -53,54 +39,5 @@ | |
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script> | ||
<!-- Bootstrap JS --> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script> | ||
|
||
<script> | ||
const mcapi = 'https://eu.mc-api.net/v3/server' | ||
|
||
const servers = [ | ||
{'name': 'Freddit Freebuild', 'address': 'play.freddit.net', 'map_url': 'https://map.freddit.net'}, | ||
{'name': 'Freddit Survival', 'address': 'survival.freddit.net', 'map_url': 'https://survivalmap.freddit.net'} | ||
] | ||
|
||
const copyToClipboard = (text) => { | ||
navigator.clipboard.writeText(text) | ||
var toastEl = document.getElementById('copied-toast'); | ||
var toast = new bootstrap.Toast(toastEl); | ||
toast.show(); | ||
} | ||
|
||
const serverStatusCardHTML = (server_name, server_address, status, map_url, players, version) => { | ||
return ` | ||
<div class="col-md-4 p-2"> | ||
<div class="card"> | ||
<div class="card-header"> | ||
<img src="${mcapi}/favicon/${server_address}" alt="Server icon" style="width: 16px; height: 16px;"> | ||
${server_name} | ||
<div class="badge bg-${status === 'online' ? 'success' : 'danger'}">${status}</div> | ||
${version ? `<span class="badge bg-secondary">${version}</span>` : ''} | ||
</div> | ||
<div class="card-body"> | ||
<p>${players} player${players !== 1 ? 's' : ''} online</p> | ||
<button class="btn btn-sm btn-outline-primary" onclick="window.open('${map_url}')">Map</button> | ||
</div> | ||
<div class="card-footer" onclick="copyToClipboard('${server_address}')" style="cursor: pointer;"> | ||
<code>${server_address}</code> | ||
</div> | ||
</div> | ||
</div> | ||
` | ||
} | ||
|
||
servers.forEach(server => { | ||
$.get(mcapi + "/ping/" + server.address, function(data) { | ||
if (data.error) { | ||
$('#server-status').append(serverStatusCardHTML(server.name, server.address, 'offline', server.map_url, 0)) | ||
return | ||
} | ||
$('#server-status').append(serverStatusCardHTML(server.name, server.address, 'online', server.map_url, data.players.online, data.version.name)) | ||
}).fail(function() { | ||
$('#server-status').append(serverStatusCardHTML(server.name, server.address, 'offline', server.map_url, 0)) | ||
}) | ||
}) | ||
</script> | ||
<script src="src.js"></script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const mcapi = 'https://eu.mc-api.net/v3/server' | ||
|
||
const servers = [ | ||
{ | ||
'name': 'Freddit Freebuild', | ||
'address': 'play.freddit.net', | ||
'map_url': 'http://map.freddit.net' | ||
}, | ||
{ | ||
'name': 'Freddit Survival', | ||
'address': 'survival.freddit.net', | ||
'map_url': 'https://survivalmap.freddit.net' | ||
} | ||
] | ||
|
||
const copyToClipboard = (text) => { | ||
navigator.clipboard.writeText(text) | ||
var toastEl = document.getElementById('copied-toast'); | ||
var toast = new bootstrap.Toast(toastEl); | ||
toast.show(); | ||
} | ||
|
||
const serverStatusCardHTML = (server_name, server_address, status, map_url, players, version) => { | ||
return ` | ||
<div class="col-md-4 p-2"> | ||
<div class="card"> | ||
<div class="card-header"> | ||
<img src="${mcapi}/favicon/${server_address}" alt="Server icon" style="width: 16px; height: 16px;"> | ||
${server_name} | ||
<div class="badge bg-${status === 'online' ? 'success' : 'danger'}">${status}</div> | ||
${version ? `<span class="badge bg-secondary">${version}</span>` : ''} | ||
</div> | ||
<div class="card-body"> | ||
<p>${players} player${players !== 1 ? 's' : ''} online</p> | ||
<button class="btn btn-sm btn-outline-primary" onclick="window.open('${map_url}')">Map</button> | ||
</div> | ||
<div class="card-footer" onclick="copyToClipboard('${server_address}')" style="cursor: pointer;"> | ||
<code>${server_address}</code> | ||
</div> | ||
</div> | ||
</div> | ||
` | ||
} | ||
|
||
servers.forEach(server => { | ||
$.get(mcapi + "/ping/" + server.address, function(data) { | ||
if (data.error) { | ||
$('#server-status').append(serverStatusCardHTML(server.name, server.address, 'offline', server.map_url, 0)) | ||
return | ||
} | ||
$('#server-status').append(serverStatusCardHTML(server.name, server.address, 'online', server.map_url, data.players.online, data.version.name)) | ||
}).fail(function() { | ||
$('#server-status').append(serverStatusCardHTML(server.name, server.address, 'offline', server.map_url, 0)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
main { | ||
max-width: 600px; | ||
margin: 0 auto; | ||
padding: 20px; | ||
} | ||
code { | ||
border-radius: 4px; | ||
padding: 2px 4px; | ||
} |