aboutsummaryrefslogtreecommitdiffstats
path: root/static/script.js
diff options
context:
space:
mode:
authorMitsuo Tokumori <[email protected]>2025-03-08 01:30:17 +0900
committerMitsuo Tokumori <[email protected]>2025-03-08 01:30:17 +0900
commitec80766af5e2f59f3842b613f271c1100705af5e (patch)
tree4798439deb8b0a951ebb924d4739b05ca27577b3 /static/script.js
parent304d0a2c3e0e1eea58d6db1762c1b96e450b5843 (diff)
downloadmasu-ec80766af5e2f59f3842b613f271c1100705af5e.tar.gz
masu-ec80766af5e2f59f3842b613f271c1100705af5e.tar.bz2
masu-ec80766af5e2f59f3842b613f271c1100705af5e.zip
Change block layout, add time visualization
Block layout is now flex.
Diffstat (limited to 'static/script.js')
-rw-r--r--static/script.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/static/script.js b/static/script.js
index 1cc3e44..f81f9ef 100644
--- a/static/script.js
+++ b/static/script.js
@@ -1,3 +1,5 @@
+import { initTimeVisualizer } from './timeVisualizer.js';
+
let polling = true
const blocks = {
time: { interval: 30 * 1000, lastUpdate: 0, update: updateTime }, // 30s
@@ -9,7 +11,9 @@ let lastPoll = 0;
function updateTime() {
fetch("/time")
.then(res => res.json())
- .then(data => document.getElementById("time").innerText = data.time);
+ .then(data => {
+ document.getElementById("weatherSummary").innerText = data.time;
+ });
}
function updateWeather() {
@@ -17,9 +21,12 @@ function updateWeather() {
fetch(`/weather?city=${encodeURIComponent(city)}`)
.then(res => res.json())
.then(data => {
- const weatherBlock = document.getElementById("weather");
- if (!data) weatherBlock.innerText = "Error: Bad city";
- else weatherBlock.innerText = `${data.summary}`;
+ if (!data) {
+ document.getElementById("weather-summary").innerText = `Error, "${city}" city not found`;
+ return
+ }
+ document.getElementById("weather-summary").innerText = data.summary;
+ document.getElementById("weather-icon").src = data.icon_url;
});
}
@@ -54,3 +61,6 @@ reloadAll();
// Poll every 500ms to check intervals (fast enough for 1s updates, light on CPU)
// maybe the 1s updates should be special case, but for now let's keep it simple
setInterval(pollUpdates, 500);
+
+// timeVisualizer
+initTimeVisualizer('timeVisualizer');