Last active
August 4, 2022 08:46
-
-
Save jasalt/772f2fb109580d672af9a0ea2741a796 to your computer and use it in GitHub Desktop.
jkl.hacklab.fi Wordpress kävijäseuranta Block rev220804
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>HTML 5 Boilerplate</title> | |
<!-- <link rel="stylesheet" href="style.css"> --> | |
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script> | |
</head> | |
<body> | |
<div id="kavseuranta"> | |
<h3 id="kavseuranta-status">Kävijäseuranta latautuu... javascript vaadittu.</h3> | |
<p id="kavseuranta-visitors" style="display:none;"></p> | |
<h3 id="kavseuranta-kerhoilta" style="display:none;">Kerhoilta, tervetuloa käymään! Club meeting in progress, welcome visitors!</h3> | |
<p><i>Data päivittyy minuutin välein, <a id="kavseurantaUpdateBtn" href="">päivitä nyt.</a> Haluatko itsesi näkyviin tähän? Liity hacklabin wifiin ja <a href="https://visitors.jkl.hacklab.fi/">rekisteröi nickisi</a>.</i></p></div> | |
<script> | |
var kavseurantaUrl = "https://visitors.jkl.hacklab.fi/api/v1/visitors?format=json-v2"; | |
function kavseurantaUpdate(){ | |
jQuery.getJSON(kavseurantaUrl, function(data){ | |
// jQuery('#kavseuranta-status').text("Paikallaolijat / Current visitors"); | |
var visitors = ""; | |
// open === true -> "Ovet ovat avoinna, tervetuloa" | |
// empty === true -> "Hacklab on nyt tyhjä" | |
// else -> "Hacklabilla on joku paikalla" | |
if (data.open === true){ | |
console.log("Ovet ovat avoinna, tervetuloa"); | |
jQuery('#kavseuranta-status').text("Ovet ovat avoinna, tervetuloa"); | |
} else if (data.empty === true){ | |
console.log("Hacklab on nyt tyhjä"); | |
jQuery('#kavseuranta-status').text("Hacklab on nyt tyhjä"); | |
jQuery('#kavseuranta-visitors').hide(); | |
} else { | |
console.log("Hacklabilla ollaan paikalla"); | |
jQuery('#kavseuranta-status').text("Hacklabilla ollaan paikalla"); | |
} | |
if ( data.present.length ){ // if array not empty | |
data.present.forEach(element => { | |
visitors += element.nick; | |
visitors += ", "; | |
}); | |
// Ugly way to remove ending comma | |
visitors = visitors.substring(0, visitors.length - 2); | |
visitors += "."; | |
jQuery('#kavseuranta-visitors').text("Wifiin kirjautuneena " + visitors) ; | |
jQuery('#kavseuranta-visitors').show(); | |
} | |
// if ('open' in data){ | |
// jQuery('#kavseuranta-visitors').show(); | |
// } | |
jQuery("#kavseurantaUpdateBtn").show(); | |
}); | |
} | |
jQuery(document).ready(function($) { | |
kavseurantaUpdate(); | |
jQuery('#kavseurantaUpdateBtn').click( function(e){ | |
e.preventDefault(); | |
jQuery("#kavseurantaUpdateBtn").hide(); | |
kavseurantaUpdate(); | |
} | |
); | |
window.setInterval(kavseurantaUpdate, 60000); | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment