From e17ee3d74a0726ff4dd2a72f473e65d0ee8d3e7b Mon Sep 17 00:00:00 2001 From: nutty Date: Sun, 13 Sep 2026 09:03:04 +1000 Subject: [PATCH] Added a time format setting --- .common/utils/helpers.js | 12 ++++++++---- horizontal-chat/script.js | 9 +++++---- horizontal-chat/settings/settings.json | 19 +++++++++++++++++++ multichat-overlay/script.js | 11 ++++++----- multichat-overlay/settings/settings.json | 19 +++++++++++++++++++ 5 files changed, 57 insertions(+), 13 deletions(-) diff --git a/.common/utils/helpers.js b/.common/utils/helpers.js index c5bf6b4..a6925f5 100644 --- a/.common/utils/helpers.js +++ b/.common/utils/helpers.js @@ -202,17 +202,21 @@ function RenderKickEmotes(message) { }); } -function GetCurrentTimeFormatted() { +function GetCurrentTimeFormatted(timeFormat = '12-hour') { const now = new Date(); let hours = now.getHours(); const minutes = String(now.getMinutes()).padStart(2, '0'); - const ampm = hours >= 12 ? 'PM' : 'AM'; + if (timeFormat === '24-hour') { + const paddedHours = String(hours).padStart(2, '0'); + return `${paddedHours}:${minutes}`; + } + + const ampm = hours >= 12 ? 'PM' : 'AM'; hours = hours % 12; hours = hours ? hours : 12; // the hour '0' should be '12' - const formattedTime = `${hours}:${minutes} ${ampm}`; - return formattedTime; + return `${hours}:${minutes} ${ampm}`; } function DecodeHTMLString(html) { diff --git a/horizontal-chat/script.js b/horizontal-chat/script.js index c582207..34967d1 100644 --- a/horizontal-chat/script.js +++ b/horizontal-chat/script.js @@ -26,6 +26,7 @@ let kickSubBadges = []; const showPlatform = GetBooleanParam("showPlatform", true); const showAvatar = GetBooleanParam("showAvatar", true); const showTimestamps = GetBooleanParam("showTimestamps", false); +const timeFormat = urlParams.get("timeFormat") || "12-hour"; const showBadges = GetBooleanParam("showBadges", true); const showPronouns = GetBooleanParam("showPronouns", false); const showUsername = GetBooleanParam("showUsername", true); @@ -555,7 +556,7 @@ async function TwitchChatMessage(data) { // Set timestamp if (showTimestamps) { timestampDiv.classList.add("timestamp"); - timestampDiv.innerText = GetCurrentTimeFormatted(); + timestampDiv.innerText = GetCurrentTimeFormatted(timeFormat); } // Set the username info @@ -922,7 +923,7 @@ function YouTubeMessage(data) { // Set timestamp if (showTimestamps) { timestampDiv.classList.add("timestamp"); - timestampDiv.innerText = GetCurrentTimeFormatted(); + timestampDiv.innerText = GetCurrentTimeFormatted(timeFormat); } // Set the message data @@ -1350,7 +1351,7 @@ async function KickChatMessage(data) { // Set timestamp if (showTimestamps) { timestampDiv.classList.add("timestamp"); - timestampDiv.innerText = GetCurrentTimeFormatted(); + timestampDiv.innerText = GetCurrentTimeFormatted(timeFormat); } // Set the username info @@ -1588,7 +1589,7 @@ async function TikTokChat(data) { // Set timestamp if (showTimestamps) { timestampDiv.classList.add("timestamp"); - timestampDiv.innerText = GetCurrentTimeFormatted(); + timestampDiv.innerText = GetCurrentTimeFormatted(timeFormat); } // Set the username info diff --git a/horizontal-chat/settings/settings.json b/horizontal-chat/settings/settings.json index a99b145..eac218e 100644 --- a/horizontal-chat/settings/settings.json +++ b/horizontal-chat/settings/settings.json @@ -24,6 +24,25 @@ "defaultValue": false, "group": "Appearance" }, + { + "id": "timeFormat", + "label": "Time Format", + "description": "", + "type": "select", + "showIf": "showTimestamps", + "options": [ + { + "value": "12-hour", + "label": "12 Hour Time" + }, + { + "value": "24-hour", + "label": "24 Hour Time" + } + ], + "defaultValue": "12-hour", + "group": "Appearance" + }, { "id": "showBadges", "label": "Show Badges", diff --git a/multichat-overlay/script.js b/multichat-overlay/script.js index cdbbdf8..5c989db 100644 --- a/multichat-overlay/script.js +++ b/multichat-overlay/script.js @@ -23,6 +23,7 @@ let kickSubBadges = []; const showPlatform = GetBooleanParam("showPlatform", true); const showAvatar = GetBooleanParam("showAvatar", true); const showTimestamps = GetBooleanParam("showTimestamps", true); +const timeFormat = urlParams.get("timeFormat") || "12-hour"; const showBadges = GetBooleanParam("showBadges", true); const showPronouns = GetBooleanParam("showPronouns", true); const showUsername = GetBooleanParam("showUsername", true); @@ -654,7 +655,7 @@ async function TwitchChatMessage(data) { // Set timestamp if (showTimestamps) { timestampDiv.classList.add("timestamp"); - timestampDiv.innerText = GetCurrentTimeFormatted(); + timestampDiv.innerText = GetCurrentTimeFormatted(timeFormat); } // Set the username info @@ -919,7 +920,7 @@ async function TwitchAnnouncement(data) { // Set timestamp if (showTimestamps) { content.querySelector("#timestamp").classList.add("timestamp"); - content.querySelector("#timestamp").innerText = GetCurrentTimeFormatted(); + content.querySelector("#timestamp").innerText = GetCurrentTimeFormatted(timeFormat); } if (data.user.name.toLowerCase() == data.user.login.toLowerCase()) content.querySelector("#username").innerText = data.user.name; @@ -1412,7 +1413,7 @@ async function YouTubeMessage(data) { // Set timestamp if (showTimestamps) { timestampDiv.classList.add("timestamp"); - timestampDiv.innerText = GetCurrentTimeFormatted(); + timestampDiv.innerText = GetCurrentTimeFormatted(timeFormat); } // Set the message data @@ -2397,7 +2398,7 @@ async function KickChatMessage(data) { // Set timestamp if (showTimestamps) { timestampDiv.classList.add("timestamp"); - timestampDiv.innerText = GetCurrentTimeFormatted(); + timestampDiv.innerText = GetCurrentTimeFormatted(timeFormat); } // Set the username info @@ -2880,7 +2881,7 @@ async function TikTokChat(data) { // Set timestamp if (showTimestamps) { timestampDiv.classList.add("timestamp"); - timestampDiv.innerText = GetCurrentTimeFormatted(); + timestampDiv.innerText = GetCurrentTimeFormatted(timeFormat); } // Set the username info diff --git a/multichat-overlay/settings/settings.json b/multichat-overlay/settings/settings.json index fee2d12..8445c9d 100644 --- a/multichat-overlay/settings/settings.json +++ b/multichat-overlay/settings/settings.json @@ -24,6 +24,25 @@ "defaultValue": true, "group": "Appearance" }, + { + "id": "timeFormat", + "label": "Time Format", + "description": "", + "type": "select", + "showIf": "showTimestamps", + "options": [ + { + "value": "12-hour", + "label": "12 Hour Time" + }, + { + "value": "24-hour", + "label": "24 Hour Time" + } + ], + "defaultValue": "12-hour", + "group": "Appearance" + }, { "id": "showBadges", "label": "Show Badges",