diff --git a/chrome/manifest.json b/chrome/manifest.json index 63e5c74..e509990 100644 --- a/chrome/manifest.json +++ b/chrome/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Kagi Search for Chrome", - "version": "0.3.5", + "version": "0.3.6", "description": "A simple extension for setting Kagi as a default search engine, and automatically logging in to Kagi in incognito browsing windows", "background": { "service_worker": "src/background.js", @@ -19,12 +19,12 @@ "default_popup": "src/popup.html" }, "permissions": [ - "activeTab", "cookies", "declarativeNetRequestWithHostAccess", "webRequest", "storage" ], + "optional_permissions": ["activeTab"], "host_permissions": ["https://kagi.com/*"], "chrome_settings_overrides": { "search_provider": { diff --git a/firefox/manifest.json b/firefox/manifest.json index a372fcc..e5849e7 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Kagi Search for Firefox", - "version": "0.3.5", + "version": "0.3.6", "description": "A simple helper extension for setting Kagi as a default search engine, and automatically logging in to Kagi in incognito browsing windows.", "background": { "page": "src/background_page.html" @@ -18,12 +18,12 @@ "default_popup": "src/popup.html" }, "permissions": [ - "activeTab", "cookies", "declarativeNetRequestWithHostAccess", "webRequest", "storage" ], + "optional_permissions": ["activeTab"], "host_permissions": ["https://kagi.com/*"], "chrome_settings_overrides": { "search_provider": { @@ -47,7 +47,8 @@ }, "browser_specific_settings": { "gecko": { - "id": "search@kagi.com" + "id": "search@kagi.com", + "strict_min_version": "102.0" } } } diff --git a/shared/src/background.js b/shared/src/background.js index 5edd284..c0726af 100644 --- a/shared/src/background.js +++ b/shared/src/background.js @@ -1,4 +1,4 @@ -import { summarizeContent } from './lib/utils.js'; +import { summarizeContent, fetchSettings } from './lib/utils.js'; if (!globalThis.browser) { globalThis.browser = chrome; @@ -167,25 +167,12 @@ browser.commands.onCommand.addListener(async (command) => { }); async function loadStorageData() { - const sessionObject = await browser.storage.local.get('session_token'); - if (sessionObject?.session_token) { - sessionToken = sessionObject.session_token; - } - - const syncObject = await browser.storage.local.get('sync_existing'); - if (typeof syncObject?.sync_existing !== 'undefined') { - syncSessionFromExisting = syncObject.sync_existing; - } + const { token, sync_existing, api_token, api_engine } = await fetchSettings(); - const apiObject = await browser.storage.local.get('api_token'); - if (typeof apiObject?.api_token !== 'undefined') { - sessionApiToken = apiObject.api_token; - } - - const apiEngineObject = await browser.storage.local.get('api_engine'); - if (typeof apiEngineObject?.api_engine !== 'undefined') { - sessionApiEngine = apiEngineObject.api_engine; - } + sessionToken = token; + syncSessionFromExisting = sync_existing; + sessionApiToken = api_token; + sessionApiEngine = api_engine; } loadStorageData(); diff --git a/shared/src/lib/utils.js b/shared/src/lib/utils.js index cb9b3ad..902f425 100644 --- a/shared/src/lib/utils.js +++ b/shared/src/lib/utils.js @@ -13,7 +13,9 @@ export async function summarizeContent({ }) { let summary = 'Unknown error'; let success = false; - const useApi = Boolean(api_token); + const useApi = Boolean( + api_token && ((api_engine && api_engine !== 'cecil') || text), + ); try { const requestParams = { @@ -95,13 +97,13 @@ export async function summarizeContent({ }; } -export async function updateSettings(handleGetData) { +export async function fetchSettings() { const sessionObject = await browser.storage.local.get('session_token'); const syncObject = await browser.storage.local.get('sync_existing'); const apiObject = await browser.storage.local.get('api_token'); const apiEngineObject = await browser.storage.local.get('api_engine'); - await handleGetData({ + return { token: sessionObject?.session_token, sync_existing: typeof syncObject?.sync_existing !== 'undefined' @@ -109,5 +111,27 @@ export async function updateSettings(handleGetData) { : true, api_token: apiObject?.api_token, api_engine: apiEngineObject?.api_engine, + }; +} + +export async function getActiveTab() { + const tabs = await browser.tabs.query({ + active: true, + lastFocusedWindow: true, }); + + // Chrome/Firefox might give us more than one active tab when something like "chrome://*" or "about:*" is also open + const tab = + tabs.find( + (tab) => + tab?.url?.startsWith('http://') || tab?.url?.startsWith('https://'), + ) || tabs[0]; + + if (!tab || !tab.url) { + console.error('No tab/url found.'); + console.error(tabs); + return null; + } + + return tab; } diff --git a/shared/src/popup.css b/shared/src/popup.css index deb29ec..c90115c 100644 --- a/shared/src/popup.css +++ b/shared/src/popup.css @@ -147,6 +147,7 @@ h3 { #incognito { max-width: 100%; padding: 0 15px; + font-size: 0.9rem; } .setting_row { @@ -285,19 +286,19 @@ p { right: 2px; } -#summarize { +#summarize, #request_permissions { margin-top: 10px; width: 100%; padding: 0 15px; } -#summarize .setting_row { +#summarize .setting_row, #request_permissions .setting_row { margin-top: 10px; padding: 0; justify-content: space-between; } -#summarize .setting_row > div { +#summarize .setting_row > div, #request_permissions .setting_row > div { margin-right: 10px; } @@ -306,7 +307,7 @@ p { margin-bottom: 5px; } -#summarize_page { +#summarize_page, #request_permissions_button { background-color: #ffb319; border: 1px solid #ffb319; color: #191919; @@ -320,7 +321,13 @@ p { margin-right: 10px; } -#summarize_page:hover { +#request_permissions_button { + max-width: 400px; + margin-left: auto; + margin-right: auto; +} + +#summarize_page:hover, #request_permissions_button:hover { background-color: #f7a808; border: 1px solid #d9950d; } diff --git a/shared/src/popup.html b/shared/src/popup.html index 1daaeb5..ee6b697 100644 --- a/shared/src/popup.html +++ b/shared/src/popup.html @@ -152,7 +152,7 @@
@@ -181,7 +181,7 @@
-
+