MCPcopy Create free account
hub / github.com/ChatGPTBox-dev/chatGPTBox / mountComponent

Function mountComponent

src/content-script/index.jsx:38–175  ·  view source on GitHub ↗

* @param {string} siteName * @param {SiteConfig} siteConfig

(siteName, siteConfig)

Source from the content-addressed store, hash-verified

36 * @param {SiteConfig} siteConfig
37 */
38async 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(

Callers 5

prepareForStaticCardFunction · 0.85
checkUrlChangeFunction · 0.85
checkPathChangeFunction · 0.85
checkUrlChangeFunction · 0.85
index.mjsFile · 0.85

Calls 6

getUserConfigFunction · 0.90
createElementAtPositionFunction · 0.90
endsWithQuestionMarkFunction · 0.90
initSessionFunction · 0.90
getInputFunction · 0.85

Tested by

no test coverage detected