File tree 1 file changed +7
-2
lines changed
1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -11,8 +11,13 @@ chrome.webRequest.onBeforeRequest.addListener(({ url }) => {
11
11
const urlObj = new URL ( url ) ;
12
12
const query = urlObj . searchParams . get ( 'q' ) ;
13
13
14
- // Check if searching for a bang
15
- if ( query && query . startsWith ( '!' ) ) {
14
+ // Check if query has a bang anywhere in it
15
+ if ( query && query . includes ( '!' ) && bangs . some ( ( bang ) => {
16
+ const bangStartIdx = query . indexOf ( `!${ bang . t } ` ) ;
17
+ const prevCharIdx = bangStartIdx - 1 ;
18
+ const nextCharIdx = bangStartIdx + bang . t . length + 1 ;
19
+ return bangStartIdx > - 1 && ( nextCharIdx === query . length || query [ nextCharIdx ] === ' ' ) && ( prevCharIdx === - 1 || query [ prevCharIdx ] === ' ' ) ;
20
+ } ) ) {
16
21
// Redirect to DuckDuckGo
17
22
return {
18
23
redirectUrl : `https://www.duckduckgo.com/?q=${ encodeURIComponent ( query ) } ` ,
You can’t perform that action at this time.
0 commit comments