diff --git a/src/extension/contentscript-main-override/index.ts b/src/extension/contentscript-main-override/index.ts index 52f7610..39f648d 100644 --- a/src/extension/contentscript-main-override/index.ts +++ b/src/extension/contentscript-main-override/index.ts @@ -1,15 +1,37 @@ -const genericWindow = window as any -if (genericWindow.aibrow) { - genericWindow.ai = genericWindow.aibrow -} else { - if (genericWindow.ai) { - genericWindow.ai.__aibrowOverride = true +/** + * This can be safely called multiple times + */ +function override () { + const genericWindow = window as any + if (genericWindow.aibrow) { + genericWindow.ai = genericWindow.aibrow + } else { + if (genericWindow.ai) { + genericWindow.ai.__aibrowOverride = true + } } -} -if (genericWindow.aibrowTranslation) { - genericWindow.translation = genericWindow.aibrowTranslation -} else { - if (genericWindow.translation) { - genericWindow.translation.__aibrowOverride = true + if (genericWindow.aibrowTranslation) { + genericWindow.translation = genericWindow.aibrowTranslation + } else { + if (genericWindow.translation) { + genericWindow.translation.__aibrowOverride = true + } } } + +override() + +// { + if (document.head) { + observer.disconnect() + override() + } + }) + observer.observe(document.documentElement, { childList: true }) +}