Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if the only thing in the query is a bang, redirect to homepage instead of the search page #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ function getBangredirectUrl() {
// Remove the first bang from the query
const cleanQuery = query.replace(/!\S+\s*/i, "").trim();

// If the query is just `!gh`, use `github.com` instead of `github.com/search?q=`
if (cleanQuery === "")
return selectedBang ? `https://${selectedBang.d}` : null;

// Format of the url is:
// https://www.google.com/search?q={{{s}}}
const searchUrl = selectedBang?.u.replace(
"{{{s}}}",
// Replace %2F with / to fix formats like "!ghr+t3dotgg/unduck"
encodeURIComponent(cleanQuery).replace(/%2F/g, "/")
encodeURIComponent(cleanQuery).replace(/%2F/g, "/"),
);
if (!searchUrl) return null;

Expand Down