Compare commits
10 commits
3b838722ff
...
3b0bc0588a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b0bc0588a | ||
|
|
7cbfe6f54a | ||
|
|
6a3406e75c | ||
|
|
7a44e6414f | ||
|
|
acf8a766ea | ||
|
|
a744948bd7 | ||
|
|
648c618fe0 | ||
|
|
3bbdbd9968 | ||
|
|
86a5026576 | ||
|
|
801acd101a |
9
LICENSE.txt
Normal file
9
LICENSE.txt
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
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.
|
||||
22
README.md
Normal file
22
README.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# `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
117
time.html
|
|
@ -5,12 +5,26 @@
|
|||
<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 light = false;
|
||||
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 fontSizePx = fontSizeFallbackPx;
|
||||
let getStrings = [
|
||||
function(){return (new Date()).toTimeString().split(" ")[0];},
|
||||
|
|
@ -19,18 +33,32 @@ 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;
|
||||
}
|
||||
|
||||
|
|
@ -39,49 +67,90 @@ function setSize() {
|
|||
}
|
||||
|
||||
function setColors() {
|
||||
document.body.style.background = light ? lightColor : darkColor;
|
||||
document.getElementById("time").style.color = light ? darkColor : lightColor;
|
||||
document.body.style.background = color.background;
|
||||
document.body.style.color = color.text;
|
||||
document.getElementById("time").style.color = color.text;
|
||||
}
|
||||
|
||||
document.addEventListener("keypress", keyPress);
|
||||
|
||||
function keyPress(event) {
|
||||
function handleHotKey(event) {
|
||||
if (event.repeat && !(event.key==="+" || event.key==="-")) return;
|
||||
switch (event.key) {
|
||||
case " ":
|
||||
getStrInd = ((getStrInd + 1) % getStrings.length);
|
||||
setTime();
|
||||
break;
|
||||
case "c":
|
||||
light = !light;
|
||||
schemes.index = ((schemes.index + 1) % schemes.colors.length + schemes.colors.length) % schemes.colors.length;
|
||||
color = schemes.colors[schemes.index];
|
||||
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 *= 1.2;
|
||||
fontSizePx *= fontSizeFactor;
|
||||
setSize();
|
||||
break;
|
||||
case "-":
|
||||
fontSizePx /= 1.2;
|
||||
fontSizePx /= fontSizeFactor;
|
||||
setSize();
|
||||
break;
|
||||
case "0":
|
||||
fontSizePx = fontSizeFallbackPx;
|
||||
setSize();
|
||||
break;
|
||||
case "*":
|
||||
fontSizePx *= 1.05;
|
||||
setSize();
|
||||
case "h":
|
||||
toggleHelp();
|
||||
break;
|
||||
case "_":
|
||||
fontSizePx /= 1.05;
|
||||
setSize();
|
||||
case "s":
|
||||
toggleSettings();
|
||||
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>
|
||||
#time {
|
||||
body {
|
||||
font-family: monospace;
|
||||
}
|
||||
input {
|
||||
font-family: monospace;
|
||||
font-weight: 600;
|
||||
}
|
||||
#time-container {
|
||||
text-align: center;
|
||||
}
|
||||
.container {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
|
|
@ -93,8 +162,18 @@ function keyPress(event) {
|
|||
</style>
|
||||
</head>
|
||||
<body onload="load();">
|
||||
<div class="container">
|
||||
<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>
|
||||
<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>
|
||||
|
|
|
|||
Loading…
Reference in a new issue