mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-07-01 17:09:06 +08:00
fix mounting failure caused by DuckDuckGo's initial rendering delay. #610
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import { waitForElementToExistAndSelect } from '../../../utils/index.mjs'
|
||||
import { config } from '../index'
|
||||
|
||||
export default {
|
||||
init: async (hostname, userConfig) => {
|
||||
if (userConfig.insertAtTop) {
|
||||
return !!(await waitForElementToExistAndSelect(config.duckduckgo.resultsContainerQuery[0], 5))
|
||||
}
|
||||
return true
|
||||
},
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import stackoverflow from './stackoverflow'
|
||||
import juejin from './juejin'
|
||||
import weixin from './weixin'
|
||||
import followin from './followin'
|
||||
import duckduckgo from './duckduckgo'
|
||||
|
||||
/**
|
||||
* @typedef {object} SiteConfigAction
|
||||
@@ -55,6 +56,9 @@ export const config = {
|
||||
sidebarContainerQuery: ['.js-react-sidebar', '.react-results--sidebar'],
|
||||
appendContainerQuery: ['#links_wrapper'],
|
||||
resultsContainerQuery: ['.react-results--main'],
|
||||
action: {
|
||||
init: duckduckgo.init,
|
||||
},
|
||||
},
|
||||
startpage: {
|
||||
inputQuery: ["input[name='query']"],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export function waitForElementToExistAndSelect(selector) {
|
||||
export function waitForElementToExistAndSelect(selector, timeout = 0) {
|
||||
return new Promise((resolve) => {
|
||||
if (document.querySelector(selector)) {
|
||||
return resolve(document.querySelector(selector))
|
||||
@@ -15,5 +15,11 @@ export function waitForElementToExistAndSelect(selector) {
|
||||
subtree: true,
|
||||
childList: true,
|
||||
})
|
||||
|
||||
if (timeout)
|
||||
setTimeout(() => {
|
||||
observer.disconnect()
|
||||
resolve(null)
|
||||
}, timeout)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user