44 lines
1.3 KiB
HTML
44 lines
1.3 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Random Image</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
html, body { height: 100%; overflow: hidden; background: #1a1a1a; }
|
|
img { display: block; max-width: 100%; max-height: 100%; margin: auto; cursor: pointer; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<img id="random-img" alt="Random image">
|
|
<script>
|
|
function loadImage(hash) {
|
|
document.getElementById('random-img').src = '/' + hash;
|
|
history.replaceState(null, '', '#' + hash);
|
|
}
|
|
|
|
async function loadNewImage() {
|
|
const response = await fetch('/random?' + Date.now());
|
|
const data = await response.json();
|
|
loadImage(data.img);
|
|
}
|
|
|
|
document.getElementById('random-img').addEventListener('click', loadNewImage);
|
|
document.addEventListener('keydown', function(e) {
|
|
if (e.code === 'Space') {
|
|
e.preventDefault();
|
|
loadNewImage();
|
|
}
|
|
});
|
|
|
|
const hash = window.location.hash.slice(1);
|
|
if (hash) {
|
|
loadImage(hash);
|
|
} else {
|
|
loadNewImage();
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|