Skip to content

Commit

Permalink
Tighten the check for overwriting window.ai with aibrow so script inj…
Browse files Browse the repository at this point in the history
…ection order doesnt matter
  • Loading branch information
Thomas101 committed Nov 22, 2024
1 parent f667b9e commit edf958f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/extension/contentscript-main-override/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions src/extension/contentscript-main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit edf958f

Please sign in to comment.