aboutsummaryrefslogtreecommitdiffstats
path: root/static/script.js
diff options
context:
space:
mode:
authorMitsuo Tokumori <[email protected]>2025-03-08 16:03:30 +0900
committerMitsuo Tokumori <[email protected]>2025-03-08 16:03:30 +0900
commit51163b167cce01af6101438e5e61145ad798f213 (patch)
tree9c8e75266cedfb205db175b0b2bc41b49df75cea /static/script.js
parentd9af103b9a8aed86d6ac834f1240edfb2173ffa0 (diff)
downloadmasu-51163b167cce01af6101438e5e61145ad798f213.tar.gz
masu-51163b167cce01af6101438e5e61145ad798f213.tar.bz2
masu-51163b167cce01af6101438e5e61145ad798f213.zip
Restructure python code to be modular
The python code is now a package named app. app/models: db models app/routes: flask blueprints app/static: css, js app/templates: jinja html templates
Diffstat (limited to 'static/script.js')
-rw-r--r--static/script.js50
1 files changed, 0 insertions, 50 deletions
diff --git a/static/script.js b/static/script.js
deleted file mode 100644
index efd6836..0000000
--- a/static/script.js
+++ /dev/null
@@ -1,50 +0,0 @@
-import { updateTime } from './block_time.js';
-import { updateWeather } from './block_weather.js';
-
-const config = {
- polling: true
-}
-
-function init() {
- const blocks = {
- time: { interval: 30 * 1000, lastUpdate: 0, update: updateTime }, // 30s
- weather: { interval: 30 * 60000, lastUpdate: 0, update: updateWeather } // 30min
- // Add more: { interval: X, lastUpdate: 0, update: updateFunction }
- };
-
- initHeaderControls(blocks)
-
- // Initial load
- // 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
- reloadAll(blocks);
- setInterval(() => pollUpdates(blocks), 500);
-}
-
-function reloadAll(blocks) {
- Object.keys(blocks).forEach(key => {
- blocks[key].update();
- blocks[key].lastUpdate = Date.now();
- });
-}
-
-function pollUpdates(blocks) {
- if (!config.polling) return;
- const now = Date.now();
- Object.keys(blocks).forEach(key => {
- const block = blocks[key];
- if (now - block.lastUpdate >= block.interval) {
- block.update();
- block.lastUpdate = now;
- }
- });
-}
-
-function initHeaderControls(blocks) {
- document.getElementById("reload").addEventListener("click", () => reloadAll(blocks));
- document.getElementById("pause").addEventListener("change", (e) => {
- config.polling = e.target.checked;
- });
-}
-
-init()