A simple Node application that emulates DuckDuckGo-style Bangs (search engine shortcuts).
The main script search.js works as follows:
- exposes an API endpoint
/searchthat accepts a single parameterqfrom HTTP GET calls; and - parses
qto determine whether there is a prefixing or affixing “bang” string (defined as a space-delimited string comprising of a leading lettervfollowed by a sequence of alphanumerics) and —- if there is exactly one bang string as defined, looks up it with the leading
vtruncated, against theuser.jsfile, which is an array of pairingtandukeys —- if there is a matching
tkey, navigates the browser to the URL in the pairingukey, with its substring{{{s}}}substituted withq, truncated of the bang string; otherwise - navigates the browser to DuckDuckGo with the parsed bang string and search query, so that it can be matched against DuckDuckGo’s full catalog of bangs (available at https://duckduckgo.com/bang.js); or
- if there is a matching
- if there are multiple bang strings, follows Step 2(i) with the first treated as the bang string; or
- if there is not any bang string, navigates the browser to Google (anonymously proxied by using DuckDuckGo’s
!gbang) with theqas the search query.
- if there is exactly one bang string as defined, looks up it with the leading
You can define your bang strings in user.json following the template below:
You can run the script locally with
node .and find it at localhost:3000.
Or, you can deploy the repo to Vercel for free by clicking the button below.
A preview deployment is available at https://vbang2.vercel.app/. It is recommended to deploy your own instance.
Note: You may want to set the forked repo as private and select an obscure or protected URL for better privacy, especially if you want to save bangs that redirect to confidential or paywalled locations.
Of course, you can also use any cloud service that supports the depolyment of Node.js code, such as fly.io, Cloudflare Worker, etc.
The project is made as a demo for an upcoming member-only post at SSPAI Prime (https://sspai.com/prime/explore). If you find this useful, please consider purchasing a subscription as a form of support. Thanks.
[ { "t": "exampleBangString", "u": "https://search.example.org/subpath/?query={{{s}}}" }, // omitted ]