diff --git a/.nodemonignore b/.nodemonignore deleted file mode 100644 index 8f141a2..0000000 --- a/.nodemonignore +++ /dev/null @@ -1,2 +0,0 @@ -built/ -node_modules/ diff --git a/.nvmrc b/.nvmrc index 5e0828a..805b5a4 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v18.16.1 +v20.9.0 diff --git a/chrome/manifest.json b/chrome/manifest.json index f078fe7..0b9bed9 100644 --- a/chrome/manifest.json +++ b/chrome/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Kagi Search for Chrome", - "version": "0.4.1", + "version": "0.4.2", "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", diff --git a/firefox/manifest.json b/firefox/manifest.json index 5efc55d..8b665ee 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Kagi Search for Firefox", - "version": "0.4.1", + "version": "0.4.2", "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" diff --git a/nodemon.json b/nodemon.json new file mode 100644 index 0000000..ecd253e --- /dev/null +++ b/nodemon.json @@ -0,0 +1,5 @@ +{ + "verbose": false, + "ignore": [".git", "built/**", "node_modules/**/node_modules"], + "ext": "js,json,css,html" +} diff --git a/package-lock.json b/package-lock.json index a6233ad..cac160a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,12 +10,12 @@ "license": "MIT", "devDependencies": { "adm-zip": "0.5.10", - "nodemon": "2.0.22", + "nodemon": "3.0.1", "rome": "12.1.3" }, "engines": { - "node": "18.x", - "npm": "9.x" + "node": "20.x", + "npm": "10.x" } }, "node_modules/@rometools/cli-darwin-arm64": { @@ -216,9 +216,9 @@ } }, "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", "dev": true, "hasInstallScript": true, "optional": true, @@ -329,9 +329,9 @@ "dev": true }, "node_modules/nodemon": { - "version": "2.0.22", - "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.22.tgz", - "integrity": "sha512-B8YqaKMmyuCO7BowF1Z1/mkPqLk6cs/l63Ojtd6otKjMx47Dq1utxfRxcavH1I7VSaL8n5BUaoutadnsX3AAVQ==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.0.1.tgz", + "integrity": "sha512-g9AZ7HmkhQkqXkRc20w+ZfQ73cHLbE8hnPbtaFbFtCumZsjyMhKk9LajQ07U5Ux28lvFjZ5X7HvWR1xzU8jHVw==", "dev": true, "dependencies": { "chokidar": "^3.5.2", @@ -339,8 +339,8 @@ "ignore-by-default": "^1.0.1", "minimatch": "^3.1.2", "pstree.remy": "^1.1.8", - "semver": "^5.7.1", - "simple-update-notifier": "^1.0.7", + "semver": "^7.5.3", + "simple-update-notifier": "^2.0.0", "supports-color": "^5.5.0", "touch": "^3.1.0", "undefsafe": "^2.0.5" @@ -349,7 +349,7 @@ "nodemon": "bin/nodemon.js" }, "engines": { - "node": ">=8.10.0" + "node": ">=10" }, "funding": { "type": "opencollective", @@ -432,9 +432,9 @@ } }, "node_modules/semver": { - "version": "7.5.2", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.2.tgz", - "integrity": "sha512-SoftuTROv/cRjCze/scjGyiDtcUyxw1rgYQSZY7XTmtR5hX+dm76iDbTH8TkLPHCQmlbQVSSbNZCPM2hb0knnQ==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" @@ -447,15 +447,15 @@ } }, "node_modules/simple-update-notifier": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-1.1.0.tgz", - "integrity": "sha512-VpsrsJSUcJEseSbMHkrsrAVSdvVS5I96Qo1QAQ4FxQ9wXFcB+pjj7FB7/us9+GcgfW4ziHtYMc1J0PLczb55mg==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", + "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", "dev": true, "dependencies": { - "semver": "~7.0.0" + "semver": "^7.5.3" }, "engines": { - "node": ">=8.10.0" + "node": ">=10" } }, "node_modules/supports-color": { diff --git a/package.json b/package.json index b3f2453..6a27dae 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "private": true, "scripts": { "watch-firefox": "nodemon --ext js,json,css,html build.js firefox watch", - "watch-chrome": "nodemon --ext js,json,css,html build.js chrome watch", + "watch-chrome": "nodemon build.js chrome watch", "build": "npm run build-firefox && npm run build-chrome", "build-firefox": "node build.js firefox", "build-chrome": "node build.js chrome", @@ -26,14 +26,11 @@ "homepage": "https://github.com/kagisearch/browser_extensions#readme", "devDependencies": { "adm-zip": "0.5.10", - "nodemon": "2.0.22", + "nodemon": "3.0.1", "rome": "12.1.3" }, "engines": { - "node": "18.x", - "npm": "9.x" - }, - "overrides": { - "semver": "7.5.2" + "node": "20.x", + "npm": "10.x" } } diff --git a/shared/src/background.js b/shared/src/background.js index bc74485..76563fd 100644 --- a/shared/src/background.js +++ b/shared/src/background.js @@ -8,6 +8,8 @@ let sessionToken = undefined; let syncSessionFromExisting = true; let sessionApiToken = undefined; let sessionApiEngine = undefined; +let sessionSummaryType = undefined; +let sessionTargetLanguage = undefined; let IS_CHROME = true; // Very hacky, but currently works flawlessly @@ -16,7 +18,7 @@ if (typeof browser.runtime.getBrowserInfo === 'function') { } async function saveToken( - { token, api_token, api_engine, sync } = {}, + { token, api_token, api_engine, sync, summary_type, target_language } = {}, isManual = false, ) { sessionToken = typeof token !== 'undefined' ? token : sessionToken; @@ -24,6 +26,12 @@ async function saveToken( typeof api_token !== 'undefined' ? api_token : sessionApiToken; sessionApiEngine = typeof api_engine !== 'undefined' ? api_engine : sessionApiEngine; + sessionSummaryType = + typeof summary_type !== 'undefined' ? summary_type : sessionSummaryType; + sessionTargetLanguage = + typeof target_language !== 'undefined' + ? target_language + : sessionTargetLanguage; let shouldSync = sync || !isManual; if (typeof sessionToken === 'undefined' || sessionToken.trim().length === 0) { @@ -38,6 +46,8 @@ async function saveToken( sync_existing: shouldSync, api_token: sessionApiToken, api_engine: sessionApiEngine, + summary_type: sessionSummaryType, + target_language: sessionTargetLanguage, }); await updateRules(); @@ -48,6 +58,8 @@ async function saveToken( token: sessionToken, api_token: sessionApiToken, api_engine: sessionApiEngine, + summary_type: sessionSummaryType, + target_language: sessionTargetLanguage, }); } @@ -168,12 +180,21 @@ browser.commands?.onCommand.addListener(async (command) => { }); async function loadStorageData() { - const { token, sync_existing, api_token, api_engine } = await fetchSettings(); + const { + token, + sync_existing, + api_token, + api_engine, + summary_type, + target_language, + } = await fetchSettings(); sessionToken = token; syncSessionFromExisting = sync_existing; sessionApiToken = api_token; sessionApiEngine = api_engine; + sessionSummaryType = summary_type; + sessionTargetLanguage = target_language; } loadStorageData(); diff --git a/shared/src/lib/utils.js b/shared/src/lib/utils.js index ec90f81..c061152 100644 --- a/shared/src/lib/utils.js +++ b/shared/src/lib/utils.js @@ -102,6 +102,10 @@ export async function fetchSettings() { 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'); + const summaryTypeObject = await browser.storage.local.get('summary_type'); + const targetLanguageObject = await browser.storage.local.get( + 'target_language', + ); return { token: sessionObject?.session_token, @@ -111,6 +115,8 @@ export async function fetchSettings() { : true, api_token: apiObject?.api_token, api_engine: apiEngineObject?.api_engine, + summary_type: summaryTypeObject?.summary_type, + target_language: targetLanguageObject?.target_language, }; } diff --git a/shared/src/popup.js b/shared/src/popup.js index 1c83d29..fc4ea16 100644 --- a/shared/src/popup.js +++ b/shared/src/popup.js @@ -206,6 +206,10 @@ async function setup() { const api_engine = apiEngineSelect.value; + const summary_type = summaryTypeSelect.value; + + const target_language = targetLanguageSelect.value; + saveTokenButton.innerText = 'Saving...'; await browser.runtime.sendMessage({ @@ -213,6 +217,8 @@ async function setup() { token, api_token, api_engine, + summary_type, + target_language, }); }); @@ -284,7 +290,18 @@ async function setup() { type: 'popup', }); - window.close(); + // Save new summary_type preferences + await browser.runtime.sendMessage({ + type: 'save_token', + token: searchParams.token, + api_token: searchParams.api_token, + api_engine: searchParams.api_engine, + summary_type: searchParams.summary_type, + target_language: searchParams.target_language, + }); + + // Give the browser time to save the info before closing the window (when await isn't respected) + setTimeout(() => window.close(), 100); } summarizePageButton.addEventListener('click', handleSummarizePageButtonClick); @@ -332,6 +349,8 @@ async function setup() { api_token, sync_existing, api_engine, + summary_type, + target_language, } = {}) { if (token) { tokenInput.value = token; @@ -370,6 +389,14 @@ async function setup() { apiEngineSelect.value = api_engine; } + if (summary_type) { + summaryTypeSelect.value = summary_type; + } + + if (target_language) { + targetLanguageSelect.value = target_language; + } + const hasIncognitoAccess = await browser.extension.isAllowedIncognitoAccess(); diff --git a/shared/src/summarize_result.js b/shared/src/summarize_result.js index 404fd1a..e64dc30 100644 --- a/shared/src/summarize_result.js +++ b/shared/src/summarize_result.js @@ -107,7 +107,8 @@ async function setup() { popupUrl.searchParams.set('url', tab.url); window.history.replaceState(null, '', popupUrl.toString()); - const { token, api_token, api_engine } = await fetchSettings(); + const { token, api_token, api_engine, summary_type, target_language } = + await fetchSettings(); if (token) { searchParams.set('token', token); @@ -118,6 +119,12 @@ async function setup() { if (api_engine) { searchParams.set('api_engine', api_engine); } + if (summary_type) { + searchParams.set('summary_type', summary_type); + } + if (target_language) { + searchParams.set('target_language', target_language); + } } loadingElement.style.display = '';