aboutsummaryrefslogtreecommitdiffstats
path: root/app/static/script.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/static/script.js')
-rw-r--r--app/static/script.js18
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()