From edf958f869ed2757b1c3a9636e7c221fd76332d7 Mon Sep 17 00:00:00 2001 From: Thomas Beverley Date: Fri, 22 Nov 2024 15:01:06 +0000 Subject: [PATCH] Tighten the check for overwriting window.ai with aibrow so script injection order doesnt matter --- src/extension/contentscript-main-override/index.ts | 8 ++++++-- src/extension/contentscript-main/index.ts | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/extension/contentscript-main-override/index.ts b/src/extension/contentscript-main-override/index.ts index 18c2e20..52f7610 100644 --- a/src/extension/contentscript-main-override/index.ts +++ b/src/extension/contentscript-main-override/index.ts @@ -2,10 +2,14 @@ const genericWindow = window as any if (genericWindow.aibrow) { genericWindow.ai = genericWindow.aibrow } else { - console.warn('aibrow not found') + if (genericWindow.ai) { + genericWindow.ai.__aibrowOverride = true + } } if (genericWindow.aibrowTranslation) { genericWindow.translation = genericWindow.aibrowTranslation } else { - console.warn('aibrowTranslation not found') + if (genericWindow.translation) { + genericWindow.translation.__aibrowOverride = true + } } diff --git a/src/extension/contentscript-main/index.ts b/src/extension/contentscript-main/index.ts index 8c32802..4b3853a 100644 --- a/src/extension/contentscript-main/index.ts +++ b/src/extension/contentscript-main/index.ts @@ -6,10 +6,10 @@ export const translation = new Translation(ai, (window as any).translation) if (process.env.BROWSER !== 'extlib') { const genericWindow = window as any - if (!window.ai) { + if (!window.ai || genericWindow.ai?.__aibrowOverride === true) { genericWindow.ai = ai } - if (!genericWindow.translation) { + if (!genericWindow.translation || genericWindow.translation?.__aibrowOverride === true) { genericWindow.translation = translation } genericWindow.aibrow = ai