Skip to content

Commit

Permalink
refactor: move init.baidu to site-adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
josStorer committed Mar 10, 2023
1 parent 4c8ae1f commit f912e70
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
26 changes: 26 additions & 0 deletions src/content-script/site-adapters/baidu/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { config } from '../index'

export default {
init: async (hostname, userConfig, getInput, mountComponent) => {
try {
const targetNode = document.getElementById('wrapper_wrapper')
const observer = new MutationObserver(async (records) => {
if (
records.some(
(record) =>
record.type === 'childList' &&
[...record.addedNodes].some((node) => node.id === 'container'),
)
) {
const searchValue = await getInput(config.baidu.inputQuery)
if (searchValue) {
mountComponent(config.baidu, userConfig)
}
}
})
observer.observe(targetNode, { childList: true })
} catch (e) {
/* empty */
}
},
}
27 changes: 2 additions & 25 deletions src/content-script/site-adapters/index.mjs
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
const init = {
baidu: async (hostname, userConfig, getInput, mountComponent) => {
try {
const targetNode = document.getElementById('wrapper_wrapper')
const observer = new MutationObserver(async (records) => {
if (
records.some(
(record) =>
record.type === 'childList' &&
[...record.addedNodes].some((node) => node.id === 'container'),
)
) {
const searchValue = await getInput(config.baidu.inputQuery)
if (searchValue) {
mountComponent(config.baidu, userConfig)
}
}
})
observer.observe(targetNode, { childList: true })
} catch (e) {
/* empty */
}
},
}
import baidu from './baidu'

/**
* @typedef {object} SiteConfigAction
Expand Down Expand Up @@ -80,7 +57,7 @@ export const config = {
appendContainerQuery: ['#container'],
resultsContainerQuery: ['#content_left', '#results'],
action: {
init: init.baidu,
init: baidu.init,
},
},
kagi: {
Expand Down

0 comments on commit f912e70

Please sign in to comment.