time/time.html
2020-12-13 18:22:00 +01:00

101 lines
2.1 KiB
HTML

<!DOCTYPE HTML>
<html lang="en">
<head>
<title>time</title>
<meta charset="UTF-8">
<script>
const darkColor = "#000000";
const lightColor = "#ffffff";
const fontSizeFallbackPx = 300;
const intervalMillisec = 200;
let light = false;
let fontSizePx = fontSizeFallbackPx;
let getStrings = [
function(){return (new Date()).toTimeString().split(" ")[0];},
function(){const a = (new Date()).toTimeString().split(" ")[0].split(":"); return a[0] + ":" + a[1];},
function(){const a = (new Date()).toTimeString().split(" ")[0].split(":"); return a[0];},
function(){const a = (new Date()).toTimeString().split(" ")[0].split(":"); return a[1];},
function(){const a = (new Date()).toTimeString().split(" ")[0].split(":"); return a[2];},
];
let getStrInd = 0;
function load() {
setTime();
setSize();
setColors();
setInterval(setTime, intervalMillisec);
}
function setTime() {
let str = getStrings[getStrInd]();
document.getElementById("time").innerHTML = str;
document.title = str;
}
function setSize() {
document.getElementById("time").style.fontSize = fontSizePx + "px";
}
function setColors() {
document.body.style.background = light ? lightColor : darkColor;
document.getElementById("time").style.color = light ? darkColor : lightColor;
}
document.addEventListener("keypress", keyPress);
function keyPress(event) {
switch (event.key) {
case " ":
getStrInd = ((getStrInd + 1) % getStrings.length);
break;
case "c":
light = !light;
setColors();
break;
case "+":
fontSizePx *= 1.2;
setSize();
break;
case "-":
fontSizePx /= 1.2;
setSize();
break;
case "0":
fontSizePx = fontSizeFallbackPx;
setSize();
break;
case "*":
fontSizePx *= 1.05;
setSize();
break;
case "_":
fontSizePx /= 1.05;
setSize();
break;
}
}
</script>
<style>
#time {
font-family: monospace;
}
.container {
position: absolute;
top: 50%;
left: 50%;
-moz-transform: translateX(-50%) translateY(-50%);
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
}
</style>
</head>
<body onload="load();">
<div class="container">
<span id="time"></span>
</div>
</body>
</html>