Skip to content

Commit d163103

Browse files
committed
chore: mount retry (#9)
1 parent 5a3c4dd commit d163103

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/content-script/index.jsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,24 @@ import Browser from 'webextension-polyfill'
1919
* @param {UserConfig} userConfig
2020
*/
2121
async function mountComponent(siteConfig, userConfig) {
22-
if (
23-
!getPossibleElementByQuerySelector(siteConfig.sidebarContainerQuery) &&
24-
!getPossibleElementByQuerySelector(siteConfig.appendContainerQuery) &&
25-
!getPossibleElementByQuerySelector(siteConfig.sidebarContainerQuery) &&
26-
!getPossibleElementByQuerySelector([userConfig.prependQuery]) &&
27-
!getPossibleElementByQuerySelector([userConfig.appendQuery])
28-
)
29-
return
30-
22+
const retry = 10
23+
for (let i = 1; i <= retry; i++) {
24+
const e =
25+
getPossibleElementByQuerySelector(siteConfig.sidebarContainerQuery) ||
26+
getPossibleElementByQuerySelector(siteConfig.appendContainerQuery) ||
27+
getPossibleElementByQuerySelector(siteConfig.resultsContainerQuery) ||
28+
getPossibleElementByQuerySelector([userConfig.prependQuery]) ||
29+
getPossibleElementByQuerySelector([userConfig.appendQuery])
30+
if (e) {
31+
console.log(`SiteAdapters Retry ${i}/${retry}: found`)
32+
console.log(e)
33+
break
34+
} else {
35+
console.log(`SiteAdapters Retry ${i}/${retry}: not found`)
36+
if (i === retry) return
37+
else await new Promise((r) => setTimeout(r, 500))
38+
}
39+
}
3140
document.querySelectorAll('.chatgptbox-container').forEach((e) => {
3241
unmountComponentAtNode(e)
3342
e.remove()

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ export default {
4444
subtitleContent += subtitleData.substring(0, subtitleData.indexOf('<')) + ','
4545
}
4646

47-
await new Promise((r) => setTimeout(r, 1000))
48-
4947
return cropText(
5048
`Provide a brief summary of the video using concise language and incorporating the video title.` +
5149
`The video title is:"${title}".The subtitle content is as follows:\n${subtitleContent}`,

0 commit comments

Comments
 (0)