chore: mount retry (#9)

This commit is contained in:
josc146
2023-03-19 12:50:55 +08:00
parent 5a70279829
commit fc09826b16
2 changed files with 18 additions and 11 deletions
+18 -9
View File
@@ -19,15 +19,24 @@ import Browser from 'webextension-polyfill'
* @param {UserConfig} userConfig
*/
async function mountComponent(siteConfig, userConfig) {
if (
!getPossibleElementByQuerySelector(siteConfig.sidebarContainerQuery) &&
!getPossibleElementByQuerySelector(siteConfig.appendContainerQuery) &&
!getPossibleElementByQuerySelector(siteConfig.sidebarContainerQuery) &&
!getPossibleElementByQuerySelector([userConfig.prependQuery]) &&
!getPossibleElementByQuerySelector([userConfig.appendQuery])
)
return
const retry = 10
for (let i = 1; i <= retry; i++) {
const e =
getPossibleElementByQuerySelector(siteConfig.sidebarContainerQuery) ||
getPossibleElementByQuerySelector(siteConfig.appendContainerQuery) ||
getPossibleElementByQuerySelector(siteConfig.resultsContainerQuery) ||
getPossibleElementByQuerySelector([userConfig.prependQuery]) ||
getPossibleElementByQuerySelector([userConfig.appendQuery])
if (e) {
console.log(`SiteAdapters Retry ${i}/${retry}: found`)
console.log(e)
break
} else {
console.log(`SiteAdapters Retry ${i}/${retry}: not found`)
if (i === retry) return
else await new Promise((r) => setTimeout(r, 500))
}
}
document.querySelectorAll('.chatgptbox-container').forEach((e) => {
unmountComponentAtNode(e)
e.remove()
@@ -44,8 +44,6 @@ export default {
subtitleContent += subtitleData.substring(0, subtitleData.indexOf('<')) + ','
}
await new Promise((r) => setTimeout(r, 1000))
return cropText(
`Provide a brief summary of the video using concise language and incorporating the video title.` +
`The video title is:"${title}".The subtitle content is as follows:\n${subtitleContent}`,