Skip to content

Commit 5929a18

Browse files
committed
fix mounting failure caused by DuckDuckGo's initial rendering delay. #610
1 parent 4510cf4 commit 5929a18

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { waitForElementToExistAndSelect } from '../../../utils/index.mjs'
2+
import { config } from '../index'
3+
4+
export default {
5+
init: async (hostname, userConfig) => {
6+
if (userConfig.insertAtTop) {
7+
return !!(await waitForElementToExistAndSelect(config.duckduckgo.resultsContainerQuery[0], 5))
8+
}
9+
return true
10+
},
11+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import stackoverflow from './stackoverflow'
1010
import juejin from './juejin'
1111
import weixin from './weixin'
1212
import followin from './followin'
13+
import duckduckgo from './duckduckgo'
1314

1415
/**
1516
* @typedef {object} SiteConfigAction
@@ -55,6 +56,9 @@ export const config = {
5556
sidebarContainerQuery: ['.js-react-sidebar', '.react-results--sidebar'],
5657
appendContainerQuery: ['#links_wrapper'],
5758
resultsContainerQuery: ['.react-results--main'],
59+
action: {
60+
init: duckduckgo.init,
61+
},
5862
},
5963
startpage: {
6064
inputQuery: ["input[name='query']"],

src/utils/wait-for-element-to-exist-and-select.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function waitForElementToExistAndSelect(selector) {
1+
export function waitForElementToExistAndSelect(selector, timeout = 0) {
22
return new Promise((resolve) => {
33
if (document.querySelector(selector)) {
44
return resolve(document.querySelector(selector))
@@ -15,5 +15,11 @@ export function waitForElementToExistAndSelect(selector) {
1515
subtree: true,
1616
childList: true,
1717
})
18+
19+
if (timeout)
20+
setTimeout(() => {
21+
observer.disconnect()
22+
resolve(null)
23+
}, timeout)
1824
})
1925
}

0 commit comments

Comments
 (0)