From 552fdcc798235204f7f9835489a59a7d3288f1c5 Mon Sep 17 00:00:00 2001 From: Kiyomichi Kosaka Date: Sun, 15 Jun 2025 00:40:50 +0200 Subject: [PATCH] Delay initialization until DOM ready --- script.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/script.js b/script.js index aaf47b4..4202ffd 100644 --- a/script.js +++ b/script.js @@ -1,6 +1,13 @@ // CoBiE Time System Implementation // Using Unix TAI epoch (January 1, 1970, 00:00:00 TAI) // Note: TAI differs from UTC by leap seconds (37 seconds as of 2025) + +(function() { +if (!window.Cobie) { + console.error('cobie.js not loaded'); + return; +} + const { COBIE_EPOCH, COBIE_UNITS, @@ -794,6 +801,7 @@ function commitInput() { span.addEventListener('click', enterEdit); } +function init() { // Timezone change handler document.getElementById('timezone').addEventListener('change', (e) => { currentTimezone = e.target.value; @@ -923,3 +931,15 @@ function wheelNavigate(e) { } document.addEventListener('wheel', wheelNavigate); + +} + +if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', init); +} else { + init(); +} + +window.navigatePeriod = navigatePeriod; +window.goToNow = goToNow; +})();