Skip to content

Commit f4ffbe7

Browse files
authored
Merge pull request #3 from thomas-forbes/master
2 parents b3fd4ca + 2337a3d commit f4ffbe7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

background.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ chrome.webRequest.onBeforeRequest.addListener(({ url }) => {
1111
const urlObj = new URL(url);
1212
const query = urlObj.searchParams.get('q');
1313

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+
})) {
1621
// Redirect to DuckDuckGo
1722
return {
1823
redirectUrl: `https://www.duckduckgo.com/?q=${encodeURIComponent(query)}`,

0 commit comments

Comments
 (0)