aboutsummaryrefslogtreecommitdiff
path: root/src/main.ts
diff options
context:
space:
mode:
authorTheo Browne <me@t3.gg>2025-04-18 16:43:09 -0700
committerGitHub <noreply@github.com>2025-04-18 16:43:09 -0700
commitaad79f91151f95311b8442020bc0375b052f6e97 (patch)
treecc65b29cdf06be0523e92631c8501526244664ab /src/main.ts
parentcea48a65841b4fb51d354ba0e8d95cf4bc91ff0e (diff)
parente089c09c051e3065d72a5e79b3f0a6e001cab246 (diff)
downloadunkagi-aad79f91151f95311b8442020bc0375b052f6e97.tar.xz
unkagi-aad79f91151f95311b8442020bc0375b052f6e97.zip
Merge pull request #24 from ronanru/main
if the only thing in the query is a bang, redirect to homepage instead of the search page
Diffstat (limited to 'src/main.ts')
-rw-r--r--src/main.ts6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/main.ts b/src/main.ts
index 13ebe48..4452a6f 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -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;