From 5a0aa1aa75727fa093f8941657452ae1d86dd01a Mon Sep 17 00:00:00 2001 From: Jose Alvarez Date: Tue, 8 Oct 2024 10:33:05 -0400 Subject: [PATCH] Add Kagi search suggestions --- background_scripts/completion_engines.js | 21 ++++++++++++++++++++- tests/unit_tests/completion_engines_test.js | 8 ++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/background_scripts/completion_engines.js b/background_scripts/completion_engines.js index 39510bb22..5c2182725 100644 --- a/background_scripts/completion_engines.js +++ b/background_scripts/completion_engines.js @@ -228,6 +228,24 @@ class Brave extends BaseEngine { } } +// Kagi is a paid ad-free search engine +class Kagi extends BaseEngine { + constructor() { + super({ + engineUrl: "https://kagi.com/autosuggest?q=%s", + regexps: ["^https?://www\\.kagi\\.com/"], + example: { + searchUrl: "https://www.kagi.com/search?q=%s", + keyword: "k", + }, + }); + } + + parse(text) { + return JSON.parse(text).map((suggestion) => suggestion.t); + } +} + // On the user-facing documentation page pages/completion_engines.html, these completion search // engines will be shown to the user in this order. const CompletionEngines = [ @@ -241,8 +259,9 @@ const CompletionEngines = [ Webster, Qwant, Brave, + Kagi, ]; globalThis.CompletionEngines = CompletionEngines; -export { Amazon, Brave, DuckDuckGo, Qwant, Webster }; +export { Amazon, Brave, DuckDuckGo, Kagi, Qwant, Webster }; diff --git a/tests/unit_tests/completion_engines_test.js b/tests/unit_tests/completion_engines_test.js index 4041deeaa..884faa4dc 100644 --- a/tests/unit_tests/completion_engines_test.js +++ b/tests/unit_tests/completion_engines_test.js @@ -24,6 +24,14 @@ context("Brave completion", () => { }); }); +context("Kagi completion", () => { + should("parses results", () => { + const response = JSON.stringify([{ t: "one" }, { t: "two" }]); + const results = new Engines.Kagi().parse(response); + assert.equal(["one", "two"], results); + }); +}); + context("DuckDuckGo completion", () => { should("parses results", () => { const response = JSON.stringify([