Skip to content

Commit f50249e

Browse files
committed
improve b96ba7c, getUserConfig() in realtime when mounting component
1 parent 226fb10 commit f50249e

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

src/content-script/index.jsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ import NotificationForChatGPTWeb from '../components/NotificationForChatGPTWeb'
3131

3232
/**
3333
* @param {SiteConfig} siteConfig
34-
* @param {UserConfig} userConfig
3534
*/
36-
async function mountComponent(siteConfig, userConfig) {
35+
async function mountComponent(siteConfig) {
36+
const userConfig = await getUserConfig()
37+
3738
if (!userConfig.alwaysFloatingSidebar) {
3839
const retry = 10
3940
let oldUrl = location.href
@@ -74,17 +75,19 @@ async function mountComponent(siteConfig, userConfig) {
7475
e.remove()
7576
})
7677

77-
const position = {
78-
x: window.innerWidth - 300 - Math.floor((20 / 100) * window.innerWidth),
79-
y: window.innerHeight / 2 - 200,
80-
}
81-
const toolbarContainer = createElementAtPosition(position.x, position.y)
82-
toolbarContainer.className = 'chatgptbox-toolbar-container-not-queryable'
8378
if (userConfig.alwaysFloatingSidebar && question) {
79+
const position = {
80+
x: window.innerWidth - 300 - Math.floor((20 / 100) * window.innerWidth),
81+
y: window.innerHeight / 2 - 200,
82+
}
83+
const toolbarContainer = createElementAtPosition(position.x, position.y)
84+
toolbarContainer.className = 'chatgptbox-toolbar-container-not-queryable'
85+
8486
let triggered = false
8587
if (userConfig.triggerMode === 'always') triggered = true
8688
else if (userConfig.triggerMode === 'questionMark' && endsWithQuestionMark(question.trim()))
8789
triggered = true
90+
8891
render(
8992
<FloatingToolbar
9093
session={initSession({ modelName: userConfig.modelName })}
@@ -98,6 +101,7 @@ async function mountComponent(siteConfig, userConfig) {
98101
)
99102
return
100103
}
104+
101105
const container = document.createElement('div')
102106
container.id = 'chatgptbox-container'
103107
render(
@@ -313,7 +317,7 @@ async function prepareForStaticCard() {
313317
}
314318
}
315319

316-
if (initSuccess) mountComponent(siteConfig[siteName], userConfig)
320+
if (initSuccess) mountComponent(siteConfig[siteName])
317321
}
318322
}
319323

src/content-script/site-adapters/baidu/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
) {
1515
const searchValue = await getInput(config.baidu.inputQuery)
1616
if (searchValue) {
17-
mountComponent(config.baidu, userConfig)
17+
mountComponent(config.baidu)
1818
}
1919
}
2020
})

src/content-script/site-adapters/bilibili/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
const newPath = getVideoPath()
1515
if (newPath !== oldPath) {
1616
oldPath = newPath
17-
mountComponent(config.bilibili, userConfig)
17+
mountComponent(config.bilibili)
1818
}
1919
}
2020
window.setInterval(checkPathChange, 500)

src/content-script/site-adapters/github/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ export default {
124124
if (location.href !== oldUrl) {
125125
oldUrl = location.href
126126
if (isPull() || isIssue()) {
127-
mountComponent(config.github, userConfig)
127+
mountComponent(config.github)
128128
return
129129
}
130130

131131
const patchUrl = await getPatchUrl()
132132
if (patchUrl) {
133-
mountComponent(config.github, userConfig)
133+
mountComponent(config.github)
134134
}
135135
}
136136
}

src/content-script/site-adapters/youtube/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
const checkUrlChange = async () => {
1515
if (location.href !== oldUrl) {
1616
oldUrl = location.href
17-
mountComponent(config.youtube, userConfig)
17+
mountComponent(config.youtube)
1818
}
1919
}
2020
window.setInterval(checkUrlChange, 500)

0 commit comments

Comments
 (0)