From 8a3d48d4a334feaea9ae4146601839e7d52920e1 Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Tue, 22 Oct 2024 20:07:26 +0700 Subject: [PATCH] Optimize Game slug generator by using cached RegEx --- build.ts | 3 +++ src/modules/patcher.ts | 15 +++++++++++++++ src/utils/bx-exposed.ts | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/build.ts b/build.ts index 5a3cbe4..be57933 100644 --- a/build.ts +++ b/build.ts @@ -100,6 +100,9 @@ const postProcess = (str: string): string => { }); } + // Fix unicode regex in Patcher.optimizeGameSlugGenerator + str = str.replaceAll('^\\™', '^\\\\u2122'); + assert(str.includes('/* ADDITIONAL CODE */')); assert(str.includes('window.BX_EXPOSED = BxExposed')); assert(str.includes('window.BxEvent = BxEvent')); diff --git a/src/modules/patcher.ts b/src/modules/patcher.ts index e74fa64..96a5b8c 100644 --- a/src/modules/patcher.ts +++ b/src/modules/patcher.ts @@ -972,6 +972,19 @@ if (this.baseStorageKey in window.BX_EXPOSED.overrideSettings) { return str; }, + // Optimize Game slug generator by using cached RegEx + optimizeGameSlugGenerator(str: string) { + let text = '/[;,/?:@&=+_`~$%#^*()!^\\u2122\\xae\\xa9]/g'; + if (!str.includes(text)) { + return false; + } + + str = str.replace(text, 'window.BX_EXPOSED.GameSlugRegexes[0]'); + str = str.replace('/ {2,}/g', 'window.BX_EXPOSED.GameSlugRegexes[1]'); + str = str.replace('/ /g', 'window.BX_EXPOSED.GameSlugRegexes[2]'); + + return str; + }, }; let PATCH_ORDERS: PatchArray = [ @@ -982,6 +995,8 @@ let PATCH_ORDERS: PatchArray = [ 'exposeInputSink', ] : []), + 'optimizeGameSlugGenerator', + 'detectBrowserRouterReady', 'patchRequestInfoCrash', diff --git a/src/utils/bx-exposed.ts b/src/utils/bx-exposed.ts index f5fa589..2eeb07a 100644 --- a/src/utils/bx-exposed.ts +++ b/src/utils/bx-exposed.ts @@ -144,4 +144,10 @@ export const BxExposed = { return false; }, + + GameSlugRegexes: [ + /[;,/?:@&=+_`~$%#^*()!^\u2122\xae\xa9]/g, + / {2,}/g, + / /g, + ], };