diff options
| author | Mitsuo Tokumori <[email protected]> | 2025-03-09 20:30:25 +0900 |
|---|---|---|
| committer | Mitsuo Tokumori <[email protected]> | 2025-03-09 20:30:25 +0900 |
| commit | edb9e94a98458fbac00075a3a407246668123eb4 (patch) | |
| tree | 2eecc2d720411b0e0a3ba1f4d23afad0608e88f3 /app/static/script.js | |
| parent | 4987626c394ca07c3ded98d9ed7095986553863e (diff) | |
| download | masu-master.tar.gz masu-master.tar.bz2 masu-master.zip | |
Diffstat (limited to 'app/static/script.js')
| -rw-r--r-- | app/static/script.js | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/app/static/script.js b/app/static/script.js index efd6836..84230a5 100644 --- a/app/static/script.js +++ b/app/static/script.js @@ -1,24 +1,22 @@ +"use strict"; import { updateTime } from './block_time.js'; import { updateWeather } from './block_weather.js'; const config = { - polling: true + polling: true, + pollingDelay: 500, // in ms. To be light on CPU make it >= 500ms } function init() { const blocks = { - time: { interval: 30 * 1000, lastUpdate: 0, update: updateTime }, // 30s + 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); + setInterval(() => pollUpdates(blocks), config.pollingDelay); } function reloadAll(blocks) { @@ -45,6 +43,12 @@ function initHeaderControls(blocks) { document.getElementById("pause").addEventListener("change", (e) => { config.polling = e.target.checked; }); + config.polling = document.getElementById("pause").checked; + document.getElementById("city").addEventListener("keypress", (e) => { + if (e.key === "Enter") { + updateWeather() + } + }); } init() |
