Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FastGPT disappearing on settings toggle #65

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Comment on lines +213 to +224
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes fix opening up in the popup instead of a new tab with the summarizer (#45).

});
}

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 = '';
Comment on lines +276 to +280
Copy link
Contributor Author

@BrunoBernardino BrunoBernardino Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes fix FastGPT disappearing when toggling settings (#64).

}
}
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')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this file allow the popup to be initialized with just a URL param (right click context open), otherwise not all parameters would've been properly set.

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
Loading