From 375c0d2544b20124a8cf497819006e01cd217225 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Wed, 1 Mar 2023 19:14:59 -0800 Subject: host photos.json on cloudflare r2 --- site/assets/site.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 site/assets/site.js (limited to 'site/assets/site.js') diff --git a/site/assets/site.js b/site/assets/site.js new file mode 100644 index 0000000..4e72511 --- /dev/null +++ b/site/assets/site.js @@ -0,0 +1,32 @@ +function settime() { + const timestamp = document.querySelector('[data-timestamp-text]') + if (!timestamp || !('Intl' in window)) return + + const options = { + timeZone: "Asia/Taipei", + timeStyle: "short", + hour12: false + } + + // https://gist.github.com/muan/e7414b6241f088090acd916ed965540e + let time = new Intl.DateTimeFormat(navigator.language || "zh-TW", options).format(new Date()) + + // https://bugs.chromium.org/p/chromium/issues/detail?id=1262801 + if (time.match(/^24:/)) time = time.replace('24:', '00:') + + // Setting interpolated string instead of just the time because + // if there's no JS there should be no mentions of current time + const text = timestamp.getAttribute('data-timestamp-text').replace('{time}', time) + timestamp.innerHTML = text.replace(':', ':') + + const now = new Date() + const sec = now.getSeconds() + const secondIsEven = sec % 2 === 0 + const colon = document.querySelector('[data-colon]') + if (colon) colon.style.animationDelay = `${(secondIsEven ? 0 : 1000) - now.getMilliseconds()}ms` + + const delay = 60000 - ((sec * 1000) + now.getMilliseconds()) + setTimeout(settime, delay) +} + +settime() -- cgit v1.2.3