From 37a2af1fd3e040f3ff70b9cf68ae9f6dd872ef56 Mon Sep 17 00:00:00 2001 From: Deva Midhun Date: Mon, 10 Feb 2025 16:51:13 +0000 Subject: [PATCH] update with local swatchjs --- index.html | 3 ++- swatch.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 swatch.js diff --git a/index.html b/index.html index 3c459a9..a81b524 100644 --- a/index.html +++ b/index.html @@ -17,7 +17,7 @@ - + @@ -46,6 +46,7 @@

Deva, 19, he/him. India-based programmer & indie web enthusiast; likes building random things!

+@unkown
diff --git a/swatch.js b/swatch.js new file mode 100644 index 0000000..7c6aaef --- /dev/null +++ b/swatch.js @@ -0,0 +1,37 @@ +// https://melonking.net - Swatch Clock! v2 +// The script displays a live Swatch Internet Time clock on your website! +// For more info on swatch time visit https://wiki.melonland.net/swatch_time +// +// How to this script; just paste this onto your site where ever you want the clock to show: +// @000 +// OR if you dont want the info link +// @000 +// + +var swatchClock = document.getElementById("swatchClock"); +var swatchClockNoLink = document.getElementById("swatchClock-nolink"); +function updateSwatchClock() { + if (swatchClock != null) swatchClock.innerHTML = '@' + GetSwatchTime() + ""; + if (swatchClockNoLink != null) swatchClockNoLink.innerHTML = "@" + GetSwatchTime(); +} +setInterval(updateSwatchClock, 864); +function GetSwatchTime(showDecimals = true) { + // get date in UTC/GMT + var date = new Date(); + var hours = date.getUTCHours(); + var minutes = date.getUTCMinutes(); + var seconds = date.getUTCSeconds(); + var milliseconds = date.getUTCMilliseconds(); + // add hour to get time in Switzerland + hours = hours == 23 ? 0 : hours + 1; + // time in seconds + var timeInMilliseconds = ((hours * 60 + minutes) * 60 + seconds) * 1000 + milliseconds; + // there are 86.4 seconds in a beat + var millisecondsInABeat = 86400; + // calculate beats to two decimal places + if (showDecimals) { + return Math.abs(timeInMilliseconds / millisecondsInABeat).toFixed(2); + } else { + return Math.floor(Math.abs(timeInMilliseconds / millisecondsInABeat)); + } +} \ No newline at end of file