@@ -5,16 +5,7 @@ import { createRoot } from 'react-dom/client';
55import { browser } from 'wxt/browser' ;
66import { LogseqCopliot } from './LogseqCopliot' ;
77import mountQuickCapture from './QuickCapture' ;
8- import searchEngines , {
9- Baidu ,
10- Bing ,
11- Ecosia ,
12- DuckDuckGo ,
13- Google ,
14- SearX ,
15- Yandex ,
16- CustomSearchEngine ,
17- } from './searchingEngines/searchingEngines' ;
8+ import { CustomSearchEngine } from './searchingEngines/searchingEngines' ;
189
1910export default defineContentScript ( {
2011 // Set manifest options
@@ -44,20 +35,10 @@ export default defineContentScript({
4435 async function getEngine ( ) {
4536 // Get enabled search engines from storage
4637 const enabledEngines = await searchEngineConfig . getValue ( ) ;
47- const enabledEngineIds = new Set (
48- enabledEngines . filter ( e => e . enabled ) . map ( e => e . id )
49- ) ;
50-
51- // First try built-in search engines
52- for ( const engine of searchEngines ) {
53- if ( engine . isMatch ( ) && enabledEngineIds . has ( engine . getId ( ) ) ) {
54- return engine ;
55- }
56- }
38+ const enabledEngineConfigs = enabledEngines . filter ( e => e . enabled ) ;
5739
58- // Then try custom search engines
59- const customEngines = enabledEngines . filter ( e => e . enabled && e . isCustom ) ;
60- for ( const engineConfig of customEngines ) {
40+ // Try all enabled search engines (both built-in and custom)
41+ for ( const engineConfig of enabledEngineConfigs ) {
6142 if ( engineConfig . urlPattern && engineConfig . querySelector && engineConfig . elementSelector ) {
6243 const customEngine = new CustomSearchEngine ( {
6344 id : engineConfig . id ,
@@ -67,7 +48,7 @@ export default defineContentScript({
6748 elementSelector : engineConfig . elementSelector ,
6849 insertPosition : engineConfig . insertPosition || 'last' ,
6950 } ) ;
70-
51+
7152 if ( customEngine . isMatch ( ) ) {
7253 return customEngine ;
7354 }
@@ -86,25 +67,23 @@ export default defineContentScript({
8667 return root ;
8768 } ;
8869
89- async function run (
90- searchEngine : Google | Bing | Ecosia | DuckDuckGo | Yandex | SearX | Baidu | CustomSearchEngine ,
91- ) {
70+ async function run ( searchEngine : CustomSearchEngine ) {
9271 console . debug ( 'Logseq copliot' , window . location . hostname ) ;
9372
94- if ( searchEngine instanceof DuckDuckGo ) {
73+ if ( searchEngine . getId ( ) === 'duckduckgo' ) {
9574 fixDuckDuckGoDark ( )
9675 }
9776
98- const query = searchEngine . getQuery ( ) ;
99- if ( query ) {
100- console . log ( `match ${ typeof searchEngine } , query ${ query } ` ) ;
101- const container = await searchEngine . gotElement ( ) ;
102- if ( ! container ) {
103- console . warn ( 'Failed to get container element for search engine' ) ;
104- return ;
105- }
106- // Executed when content script is loaded, can be async
107- const searchEngineUi = await createShadowRootUi ( ctx , {
77+ const query = searchEngine . getQuery ( ) ;
78+ if ( query ) {
79+ console . log ( `match ${ typeof searchEngine } , query ${ query } ` ) ;
80+ const container = await searchEngine . gotElement ( ) ;
81+ if ( ! container ) {
82+ console . warn ( 'Failed to get container element for search engine' ) ;
83+ return ;
84+ }
85+ // Executed when content script is loaded, can be async
86+ const searchEngineUi = await createShadowRootUi ( ctx , {
10887 name : 'logseq-copilot-search-engine' ,
10988 position : 'inline' ,
11089 anchor : container ,
@@ -136,9 +115,7 @@ export default defineContentScript({
136115
137116 if ( searchEngine ) {
138117 run ( searchEngine ) ;
139- if ( searchEngine . reload ) {
140- searchEngine . reload ( ( ) => run ( searchEngine ) ) ;
141- }
118+ searchEngine . reload ( ( ) => run ( searchEngine ) ) ;
142119 }
143120
144121 const { enableClipNoteFloatButton } = await getLogseqCopliotConfig ( ) ;
0 commit comments