From 16cabb38ad0ee65484cae9588af6ce05fa0bae3b Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Thu, 11 Apr 2024 22:47:28 +0300 Subject: [PATCH] Fix init order in RA mods --- public/scripts/RossAscends-mods.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index c2782a281..b007a0d7e 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -108,13 +108,22 @@ export function humanizeGenTime(total_gen_time) { return time_spent; } -let parsedUA = null; -try { - parsedUA = Bowser.parse(navigator.userAgent); -} catch { - // In case the user agent is an empty string or Bowser can't parse it for some other reason -} +/** + * DON'T OPTIMIZE, don't change this to a const or let, it needs to be a var. + */ +var parsedUA = null; +function getParsedUA() { + if (!parsedUA) { + try { + parsedUA = Bowser.parse(navigator.userAgent); + } catch { + // In case the user agent is an empty string or Bowser can't parse it for some other reason + } + } + + return parsedUA; +} /** * Checks if the device is a mobile device. @@ -123,7 +132,7 @@ try { export function isMobile() { const mobileTypes = ['mobile', 'tablet']; - return mobileTypes.includes(parsedUA?.platform?.type); + return mobileTypes.includes(getParsedUA()?.platform?.type); } export function shouldSendOnEnter() {