* @param {string} siteName * @param {SiteConfig} siteConfig
(siteName, siteConfig)
| 36 | * @param {SiteConfig} siteConfig |
| 37 | */ |
| 38 | async function mountComponent(siteName, siteConfig) { |
| 39 | if (siteName === 'github' && location.href.includes('/wiki')) { |
| 40 | return |
| 41 | } |
| 42 | |
| 43 | console.debug('[content] mountComponent called with siteConfig:', siteConfig) |
| 44 | try { |
| 45 | const userConfig = await getUserConfig() |
| 46 | |
| 47 | if (!userConfig.alwaysFloatingSidebar) { |
| 48 | const retry = 10 |
| 49 | let oldUrl = location.href |
| 50 | for (let i = 1; i <= retry; i++) { |
| 51 | console.debug(`[content] mountComponent retry ${i}/${retry} for element detection.`) |
| 52 | if (location.href !== oldUrl) { |
| 53 | console.log('[content] URL changed during retry, stopping mountComponent.') |
| 54 | return |
| 55 | } |
| 56 | const e = |
| 57 | (siteConfig && |
| 58 | (getPossibleElementByQuerySelector(siteConfig.sidebarContainerQuery) || |
| 59 | getPossibleElementByQuerySelector(siteConfig.appendContainerQuery) || |
| 60 | getPossibleElementByQuerySelector(siteConfig.resultsContainerQuery))) || |
| 61 | getPossibleElementByQuerySelector([userConfig.prependQuery]) || |
| 62 | getPossibleElementByQuerySelector([userConfig.appendQuery]) |
| 63 | if (e) { |
| 64 | console.log('[content] Element found for mounting component:', e) |
| 65 | break |
| 66 | } else { |
| 67 | console.debug(`[content] Element not found on retry ${i}.`) |
| 68 | if (i === retry) { |
| 69 | console.warn('[content] Element not found after all retries for mountComponent.') |
| 70 | return |
| 71 | } |
| 72 | await new Promise((r) => setTimeout(r, 500)) |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | document.querySelectorAll('.chatgptbox-container,#chatgptbox-container').forEach((e) => { |
| 78 | try { |
| 79 | unmountComponentAtNode(e) |
| 80 | e.remove() |
| 81 | } catch (err) { |
| 82 | console.error('[content] Error removing existing chatgptbox container:', err) |
| 83 | } |
| 84 | }) |
| 85 | |
| 86 | let question |
| 87 | if (userConfig.inputQuery) { |
| 88 | console.debug('[content] Getting input from userConfig.inputQuery') |
| 89 | question = await getInput([userConfig.inputQuery]) |
| 90 | } |
| 91 | if (!question && siteConfig) { |
| 92 | console.debug('[content] Getting input from siteConfig.inputQuery') |
| 93 | question = await getInput(siteConfig.inputQuery) |
| 94 | } |
| 95 | console.debug( |
no test coverage detected