From 247c908f460d7905311a76f29ea64c5531a0ae40 Mon Sep 17 00:00:00 2001 From: Mute Date: Thu, 10 Nov 2022 12:07:51 +0000 Subject: [PATCH] tz fix + allow spaces 0 is falsy, who would have thunk. Will now accept spaces like "UTC - 7" because people do write like this. --- mbchc-local.user.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mbchc-local.user.js b/mbchc-local.user.js index 3df622c..f7f6940 100644 --- a/mbchc-local.user.js +++ b/mbchc-local.user.js @@ -39,7 +39,7 @@ RE_PREF_ACTIVITY_ME: /^@/, RE_PREF_ACTIVITY: /^@@/, RE_ACT_CIDS: /^<(\d+)?:(\d+)?>/, - RE_TZ: /(?:GMT|UTC)([+-]\d\d?)/i, + RE_TZ: /(?:GMT|UTC)\s*([+-])\s*(\d\d?)/i, RE_ALL_LEFT: /^<+$/, RE_ALL_RIGHT: /^>+$/, RE_SPACES: /\s{2,}/g, @@ -385,10 +385,11 @@ return(false) }, find_timezone: function(char) { - let timezones = this.settings("timezones") - if (timezones && timezones[char.cid]) return(timezones[char.cid]) - let match = (char.Description) ? char.Description.match(this.RE_TZ) : null - if (match) return(Number.parseInt(match[1])) + const timezones = this.settings("timezones") + if (timezones && "number" === typeof timezones[char.cid]) return(timezones[char.cid]) + const match = (char.Description) ? char.Description.match(this.RE_TZ) : null + const int = match ? Number.parseInt(match[1] + match[2]) : 42 + if (this.in(int, -12, 12)) return(int) return(null) }, player_enters_room: function() { // or if the mod is loaded while player is in the room @@ -624,7 +625,7 @@ let colour = (C.MBCHC.VERSION === window.Player.MBCHC.VERSION) ? window.MBCHC.RGB_POLLY : window.MBCHC.RGB_MUTE window.DrawRect(CharX + 175 * Zoom, CharY, 50 * Zoom, 50 * Zoom, colour) } - if ((window.ChatRoomHideIconState < 1) && C.MBCHC_LOCAL && C.MBCHC_LOCAL.TZ) { + if ((window.ChatRoomHideIconState < 1) && C.MBCHC_LOCAL && "number" === typeof C.MBCHC_LOCAL.TZ) { let hours = new Date(window.CommonTime() + window.MBCHC.UTC_OFFSET + C.MBCHC_LOCAL.TZ * 60 * 60 * 1000).getHours() let text = (hours < 10) ? "0" + hours.toString() : hours.toString() window.DrawTextFit(text, CharX + 200 * Zoom, CharY + 25 * Zoom, 46 * Zoom, "white", "black")