Skip to content

Commit

Permalink
Fix regex
Browse files Browse the repository at this point in the history
  • Loading branch information
psidex committed Feb 4, 2022
1 parent 106259f commit ec79cee
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
[![Chrome extension version](https://img.shields.io/chrome-web-store/v/oobpkmpnffeacpnfbbepbdlhbfdejhpg?colorA=35383d)](https://chrome.google.com/webstore/detail/custom-bang-search/oobpkmpnffeacpnfbbepbdlhbfdejhpg?hl=en)
[![Chrome extension rating](https://img.shields.io/chrome-web-store/rating/oobpkmpnffeacpnfbbepbdlhbfdejhpg?colorA=35383d)](https://chrome.google.com/webstore/detail/custom-bang-search/oobpkmpnffeacpnfbbepbdlhbfdejhpg?hl=en)
[![Chrome extension user count](https://img.shields.io/chrome-web-store/users/oobpkmpnffeacpnfbbepbdlhbfdejhpg?colorA=35383d)](https://chrome.google.com/webstore/detail/custom-bang-search/oobpkmpnffeacpnfbbepbdlhbfdejhpg?hl=en)
[![Donate link](https://img.shields.io/badge/Donate-Beer-FFDD00.svg?style=flat&colorA=35383d)](https://www.buymeacoffee.com/psidex)

[![Firefox Add-On link](./images/firefox.png)](https://addons.mozilla.org/en-US/firefox/addon/custombangsearch/)
[![Chrome Web Store link](./images/chrome.png)](https://chrome.google.com/webstore/detail/custom-bang-search/oobpkmpnffeacpnfbbepbdlhbfdejhpg?hl=en)

A web extension that allows you to use DuckDuckGo-like custom bangs directly
from the address bar.
A web extension that allows you to use DuckDuckGo-like custom bangs directly from the address bar.

This currently only works if you have Google, Bing, DuckDuckGo, or Qwant set as
your browsers search engine.
This currently only works if you have Google, Bing, DuckDuckGo, Qwant, or startpage set as your browsers search engine.

## Demo

Expand All @@ -39,11 +36,9 @@ your browsers search engine.

### Defaults

Take a look at the default bangs if you need some help understanding how to
write the URLs.
Take a look at the default bangs if you need some help understanding how to write the URLs.

_The Amazon, Ebay, and Etsy defaults are UK URLs so change those if you need
to!_
_The Amazon, Ebay, and Etsy defaults are UK URLs so change those if you need to!_

## How it works

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Custom Bang Search",
"version": "0.9",
"version": "0.9.1",
"description": "Allows you to use custom bangs inside the search bar",
"icons": {
"48": "icons/icon_48.png"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "custombangsearch",
"version": "0.9",
"version": "0.9.1",
"description": "A web extension that allows you to use DuckDuckGo-like custom bangs directly from the address bar",
"main": "main.js",
"scripts": {
Expand Down
9 changes: 4 additions & 5 deletions src/scripts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ function processRequest(r: WebRequest.OnBeforeRequestDetailsType): WebRequest.Bl

// Cut first bang from query text, it can be anywhere in the string
let bang = '';
queryText = queryText.replace(/(?:^\s*|(\b)\s+)!(\w+)(?:\s+(\b)|\s*$)/, (_, leftBoundary, gBang, rightBoundary): string => {
bang = gBang;
const wordToLeft = leftBoundary !== undefined;
const wordToRight = rightBoundary !== undefined;
return wordToRight && wordToLeft ? ' ' : '';
queryText = queryText.replace(/(^!\S+ | !\S+|^!\S+$)/, (match): string => {
bang = match.trim().replace('!', '');
return '';
});

if (!bang) { return {}; }

const bangObj = bangsCached[bang];
Expand Down

0 comments on commit ec79cee

Please sign in to comment.