Skip to content

Commit

Permalink
Fix FastGPT disappearing on settings toggle (#65)
Browse files Browse the repository at this point in the history
Also change the context summarization to open in the popup as the extension, instead of a new tab.

This will be released on 0.5.1.

Fixes #45
Fixes #64
  • Loading branch information
BrunoBernardino authored Jan 26, 2024
1 parent 4600fcb commit bc7637b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
2 changes: 1 addition & 1 deletion chrome/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Kagi Search for Chrome",
"version": "0.5.0",
"version": "0.5.1",
"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",
Expand Down
2 changes: 1 addition & 1 deletion firefox/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Kagi Search for Firefox",
"version": "0.5.0",
"version": "0.5.1",
"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"
Expand Down
17 changes: 11 additions & 6 deletions shared/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,22 @@ async function loadStorageData() {
loadStorageData();

// The function kagiSummarize is called when clicking the context menu item.
function kagiSummarize(info, tab) {
async function kagiSummarize(info) {
// The linkUrl will be undefined if function is triggered by a page event. In that case, the url is taken from pageUrl
const url = info.linkUrl || info.pageUrl;
browser.tabs.create({
url: `https://kagi.com/summarizer/index.html?url=${encodeURIComponent(
url,
)}`,

await browser.windows.create({
url: browser.runtime.getURL(
`src/summarize_result.html?url=${encodeURIComponent(url)}`,
),
focused: true,
width: 600,
height: 500,
type: 'popup',
});
}

function kagiImageSearch(info, tab) {
function kagiImageSearch(info) {
const imageUrl = info.srcUrl;
browser.tabs.create({
url: `https://kagi.com/images?q=${imageUrl}&reverse=reference`,
Expand Down
2 changes: 2 additions & 0 deletions shared/src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,11 @@ async function setup() {
if (!hasPermissions) {
summarizeSection.style.display = 'none';
requestPermissionsSection.style.display = '';
fastGptSection.style.display = 'none';
} else {
summarizeSection.style.display = '';
requestPermissionsSection.style.display = 'none';
fastGptSection.style.display = '';
}
}
advancedToggle.setAttribute('title', 'Advanced settings');
Expand Down
43 changes: 24 additions & 19 deletions shared/src/summarize_result.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ async function setup() {

const searchParams = new URLSearchParams(window.location.search);

// If there's no URL, get the currently active tab and default params
if (!searchParams.get('url')) {
if (!searchParams.get('summary_type')) {
searchParams.set('summary_type', 'summary');
}

if (!searchParams.get('target_language')) {
searchParams.set('target_language', '');
}

// If there's no URL, get the currently active tab and default params
if (!searchParams.get('url')) {
const tab = await getActiveTab(true);

if (!tab) {
Expand All @@ -107,25 +112,25 @@ async function setup() {
const popupUrl = new URL(window.location.href);
popupUrl.searchParams.set('url', tab.url);
window.history.replaceState(null, '', popupUrl.toString());
}

const { token, api_token, api_engine, summary_type, target_language } =
await fetchSettings();
const { token, api_token, api_engine, summary_type, target_language } =
await fetchSettings();

if (token) {
searchParams.set('token', token);
}
if (api_token) {
searchParams.set('api_token', api_token);
}
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);
}
if (token) {
searchParams.set('token', token);
}
if (api_token) {
searchParams.set('api_token', api_token);
}
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 = '';
Expand Down

0 comments on commit bc7637b

Please sign in to comment.