improve b96ba7c0, getUserConfig() in realtime when mounting component

This commit is contained in:
josc146
2024-08-04 15:15:48 +08:00
parent 226fb108a1
commit f50249e74f
5 changed files with 18 additions and 14 deletions
+13 -9
View File
@@ -31,9 +31,10 @@ import NotificationForChatGPTWeb from '../components/NotificationForChatGPTWeb'
/**
* @param {SiteConfig} siteConfig
* @param {UserConfig} userConfig
*/
async function mountComponent(siteConfig, userConfig) {
async function mountComponent(siteConfig) {
const userConfig = await getUserConfig()
if (!userConfig.alwaysFloatingSidebar) {
const retry = 10
let oldUrl = location.href
@@ -74,17 +75,19 @@ async function mountComponent(siteConfig, userConfig) {
e.remove()
})
const position = {
x: window.innerWidth - 300 - Math.floor((20 / 100) * window.innerWidth),
y: window.innerHeight / 2 - 200,
}
const toolbarContainer = createElementAtPosition(position.x, position.y)
toolbarContainer.className = 'chatgptbox-toolbar-container-not-queryable'
if (userConfig.alwaysFloatingSidebar && question) {
const position = {
x: window.innerWidth - 300 - Math.floor((20 / 100) * window.innerWidth),
y: window.innerHeight / 2 - 200,
}
const toolbarContainer = createElementAtPosition(position.x, position.y)
toolbarContainer.className = 'chatgptbox-toolbar-container-not-queryable'
let triggered = false
if (userConfig.triggerMode === 'always') triggered = true
else if (userConfig.triggerMode === 'questionMark' && endsWithQuestionMark(question.trim()))
triggered = true
render(
<FloatingToolbar
session={initSession({ modelName: userConfig.modelName })}
@@ -98,6 +101,7 @@ async function mountComponent(siteConfig, userConfig) {
)
return
}
const container = document.createElement('div')
container.id = 'chatgptbox-container'
render(
@@ -313,7 +317,7 @@ async function prepareForStaticCard() {
}
}
if (initSuccess) mountComponent(siteConfig[siteName], userConfig)
if (initSuccess) mountComponent(siteConfig[siteName])
}
}
@@ -14,7 +14,7 @@ export default {
) {
const searchValue = await getInput(config.baidu.inputQuery)
if (searchValue) {
mountComponent(config.baidu, userConfig)
mountComponent(config.baidu)
}
}
})
@@ -14,7 +14,7 @@ export default {
const newPath = getVideoPath()
if (newPath !== oldPath) {
oldPath = newPath
mountComponent(config.bilibili, userConfig)
mountComponent(config.bilibili)
}
}
window.setInterval(checkPathChange, 500)
@@ -124,13 +124,13 @@ export default {
if (location.href !== oldUrl) {
oldUrl = location.href
if (isPull() || isIssue()) {
mountComponent(config.github, userConfig)
mountComponent(config.github)
return
}
const patchUrl = await getPatchUrl()
if (patchUrl) {
mountComponent(config.github, userConfig)
mountComponent(config.github)
}
}
}
@@ -14,7 +14,7 @@ export default {
const checkUrlChange = async () => {
if (location.href !== oldUrl) {
oldUrl = location.href
mountComponent(config.youtube, userConfig)
mountComponent(config.youtube)
}
}
window.setInterval(checkUrlChange, 500)