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

Support reader more in Firefox #52

Merged
merged 1 commit into from
Dec 6, 2023
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
7 changes: 4 additions & 3 deletions rome.json → biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://docs.rome.tools/schemas/12.1.3/schema.json",
"$schema": "https://biomejs.dev/schemas/1.4.1/schema.json",
"organizeImports": {
"enabled": false
},
Expand All @@ -11,14 +11,15 @@
"rules": {
"recommended": true,
"complexity": {
"noExtraBooleanCast": "off"
"noExtraBooleanCast": "off",
"noForEach": "off"
}
}
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentSize": 2
"indentWidth": 2
},
"javascript": {
"formatter": {
Expand Down
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.4.2",
"version": "0.4.3",
"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.4.2",
"version": "0.4.3",
"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
128 changes: 75 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"build": "npm run build-firefox && npm run build-chrome",
"build-firefox": "node build.js firefox",
"build-chrome": "node build.js chrome",
"format": "rome format --write . && rome check --apply .",
"lint": "rome check .",
"format": "biome format --write . && biome check --apply .",
"lint": "biome check .",
"test": "npm run lint"
},
"repository": {
Expand All @@ -25,9 +25,9 @@
},
"homepage": "https://github.com/kagisearch/browser_extensions#readme",
"devDependencies": {
"@biomejs/biome": "1.4.1",
"adm-zip": "0.5.10",
"nodemon": "3.0.1",
"rome": "12.1.3"
"nodemon": "3.0.1"
},
"engines": {
"node": "20.x",
Expand Down
30 changes: 20 additions & 10 deletions shared/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,24 @@ async function saveToken(

syncSessionFromExisting = shouldSync;

await browser.storage.local.set({
session_token: token,
sync_existing: shouldSync,
api_token: sessionApiToken,
api_engine: sessionApiEngine,
summary_type: sessionSummaryType,
target_language: sessionTargetLanguage,
});
try {
await browser.storage.local.set({
session_token: token,
sync_existing: shouldSync,
api_token: sessionApiToken,
api_engine: sessionApiEngine,
summary_type: sessionSummaryType,
target_language: sessionTargetLanguage,
});
} catch (error) {
console.error(error);

await browser.runtime.sendMessage({
type: 'save-error',
});

return;
}

await updateRules();

Expand Down Expand Up @@ -142,7 +152,7 @@ browser.webRequest.onBeforeRequest.addListener(
browser.runtime.onMessage.addListener(async (data) => {
switch (data.type) {
case 'save_token': {
saveToken(data, true);
await saveToken(data, true);
break;
}
case 'open_extension': {
Expand All @@ -158,7 +168,7 @@ browser.runtime.onMessage.addListener(async (data) => {
break;
}
case 'summarize_page': {
summarizePage(data);
await summarizePage(data);
break;
}
default:
Expand Down
10 changes: 7 additions & 3 deletions shared/src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ export async function fetchSettings() {
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',
);
const targetLanguageObject =
await browser.storage.local.get('target_language');

return {
token: sessionObject?.session_token,
Expand Down Expand Up @@ -140,6 +139,11 @@ export async function getActiveTab(fetchingFromShortcut = false) {
tab?.url?.startsWith('http://') || tab?.url?.startsWith('https://'),
) || tabs[0];

if (tab?.url?.startsWith('about:reader?url=')) {
const newUrl = new URL(tab.url);
tab.url = newUrl.searchParams.get('url');
}
Comment on lines +142 to +145
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the reader fix. Basically Firefox provides the URL with that protocol.


if (!tab || !tab.url) {
console.error('No tab/url found.');
console.error(JSON.stringify(tabs));
Expand Down
3 changes: 2 additions & 1 deletion shared/src/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ input[type="password"]:focus {
}

#status_permission_message,
#status_error_message {
#status_error_message,
#save_error {
color: #fd6820;
}

Expand Down
11 changes: 11 additions & 0 deletions shared/src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@
</div>
</div>

<div class="setting_row" style="display: none" id="save_error">
<div>
<div class="title">
Error saving token!
</div>
<div class="desc">
It seems the extension isn't able to save the token. Please try disabling the "<span>Allow in Incognito</span>" toggle, saving the token, then enabling it again.
</div>
</div>
</div>

<div class="setting_row">
<button id="token_save">Save settings</button>
</div>
Expand Down
Loading