Compare commits

..

No commits in common. "3b0bc0588a9f27e24642a4c8ec3252afbf26d7c5" and "3b838722ffad106347803ca794d2774ce7086f86" have entirely different histories.

3 changed files with 19 additions and 129 deletions

View file

@ -1,9 +0,0 @@
The MIT License (MIT)
Copyright © 2023 Benjamin Stadlbauer
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,22 +0,0 @@
# `time`
A simple HTML-based clock display
Press `h` to show the hotkeys:
- `Space` sweeps through clock-displays
- `c` and `shift-c` sweeps through the color-schemes
- `+` increases size
- `-` decreases size
- `0` resets size
- `s` shows settings
## About
I wanted to have a full-screen clock for my dual-screen setup for a longer time. After I have learned the very basics of HTML and Javascript, I decided to write my own little full-screen-clock. After I decided to make it available for others, I added a help-function (press `h`) and after some refactoring I put it on GitHub.
There are at least a dozen more features in my head I could implement but this is what I have so far. And I don't know if this will work on your computer (regarding the browser, your keyboard-language etc).
I will try to keep this tiny application updated and I hopefully I will continue adding more features.
---
Copyright © 2023 Benjamin Stadlbauer

117
time.html
View file

@ -5,26 +5,12 @@
<meta charset="UTF-8">
<script>
const darkColor = "#000000";
const lightColor = "#ffffff";
const fontSizeFallbackPx = 300;
const intervalMillisec = 200;
const fontSizeFactor = 1.2;
const rgbSedecimalRe = /[\da-fA-F]{6}/
let schemes = {
index: 0,
colors: [
{text: "#ffffff", background: "#000000"},
{text: "#a0a0a0", background: "#101010"},
{text: "#ff0000", background: "#000000"},
{text: "#000000", background: "#ffffff"},
{text: "#101010", background: "#a0a0a0"},
{text: "#000000", background: "#ff0000"},
],
};
let color = schemes.colors[schemes.index];
let help = false;
let settings = false;
let light = false;
let fontSizePx = fontSizeFallbackPx;
let getStrings = [
function(){return (new Date()).toTimeString().split(" ")[0];},
@ -33,32 +19,18 @@ let getStrings = [
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;
let darkColorInput;
let lightColorInput;
function load() {
document.addEventListener("keydown", handleHotKey);
let inputs = document.getElementsByTagName("input")
for (let input of inputs) {
if (input.type == "color") {
input.addEventListener("input", e => writeColor(e));
input.addEventListener("change", e => writeColor(e));
}
}
setTime();
setSize();
setColors();
setColorsToInput();
setInterval(setTime, intervalMillisec);
}
function setTime() {
let str = getStrings[getStrInd]();
document.getElementById("time").innerHTML = str;
document.getElementById("time-preview").innerHTML = str;
document.title = str;
}
@ -67,90 +39,49 @@ function setSize() {
}
function setColors() {
document.body.style.background = color.background;
document.body.style.color = color.text;
document.getElementById("time").style.color = color.text;
document.body.style.background = light ? lightColor : darkColor;
document.getElementById("time").style.color = light ? darkColor : lightColor;
}
function handleHotKey(event) {
if (event.repeat && !(event.key==="+" || event.key==="-")) return;
document.addEventListener("keypress", keyPress);
function keyPress(event) {
switch (event.key) {
case " ":
getStrInd = ((getStrInd + 1) % getStrings.length);
setTime();
break;
case "c":
schemes.index = ((schemes.index + 1) % schemes.colors.length + schemes.colors.length) % schemes.colors.length;
color = schemes.colors[schemes.index];
light = !light;
setColors();
setColorsToInput();
break;
case "C":
schemes.index = ((schemes.index - 1) % schemes.colors.length + schemes.colors.length) % schemes.colors.length;
color = schemes.colors[schemes.index];
setColors();
setColorsToInput();
break;
case "+":
fontSizePx *= fontSizeFactor;
fontSizePx *= 1.2;
setSize();
break;
case "-":
fontSizePx /= fontSizeFactor;
fontSizePx /= 1.2;
setSize();
break;
case "0":
fontSizePx = fontSizeFallbackPx;
setSize();
break;
case "h":
toggleHelp();
case "*":
fontSizePx *= 1.05;
setSize();
break;
case "s":
toggleSettings();
case "_":
fontSizePx /= 1.05;
setSize();
break;
}
}
function toggleHelp() {
help = !help;
let elements = document.getElementsByClassName("help");
for (let element of elements) {
element.style.display = help ? "block" : "none";
}
}
function toggleSettings() {
settings = !settings;
document.getElementById("time-container").style.display = settings ? "none" : "block";
document.getElementById("settings-container").style.display = settings ? "block" : "none";
}
function setColorsToInput() {
document.getElementById("text-color").value = color.text;
document.getElementById("background-color").value = color.background;
}
function writeColor(event) {
color[event.target.id.split("-")[0]] = event.target.value;
setColors();
}
function saveColorsToSchemes() {
alert("sorry, not supported yet ;)");
}
</script>
<style>
body {
#time {
font-family: monospace;
}
input {
font-family: monospace;
font-weight: 600;
}
#time-container {
text-align: center;
}
.container {
position: absolute;
top: 50%;
@ -162,18 +93,8 @@ function saveColorsToSchemes() {
</style>
</head>
<body onload="load();">
<div class="container" id="time-container">
<span class="help" style="display:none"><b>Space</b> sweeps through clock-displays | <b>c</b>, <b>shift-c</b> sweeps through the color-schemes | <b>+</b> increases size | <b>-</b> decreases size | <b>0</b> resets font size | <b>s</b> settings</span>
<div class="container">
<span id="time"></span>
<span class="help" style="display:none"><a href="https://benjamin.stadlbauer.wien/git/Benjamin/time">Repository on Forgejo</a></span>
</div>
<div class="container" id="settings-container" style="display: none;">
<label for="text-color">Text color</label> <input type="color" id="text-color">
<label for="background-color" style="margin-top: 3px">Background color</label> <input type="color" id="background-color" style="margin-top: 3px">
<button onclick="saveColorsToSchemes();" style="margin-top: 3px" disabled>Save to schemes</button>
<p>
<span id="time-preview"></span>
</p>
</div>
</body>
</html>