Skip to content

Commit

Permalink
Add "Saved time" to summary result - 0.6.0 (#68)
Browse files Browse the repository at this point in the history
- This only works for the regular summarizer endpoint, not the API one, and that's handled gracefully.
  • Loading branch information
BrunoBernardino authored Feb 12, 2024
1 parent bc7637b commit 851113b
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 7 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.1",
"version": "0.6.0",
"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.1",
"version": "0.6.0",
"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
4 changes: 3 additions & 1 deletion shared/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,16 @@ async function saveToken(
}

async function summarizePage(options) {
const { summary, success } = await summarizeContent(options);
const { summary, success, timeSavedInMinutes } =
await summarizeContent(options);

if (summary) {
await browser.runtime.sendMessage({
type: 'summary_finished',
summary,
success,
url: options.url,
timeSavedInMinutes,
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions shared/src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export async function summarizeContent({
}) {
let summary = 'Unknown error';
let success = false;
let timeSavedInMinutes = 0;
const useApi = Boolean(
api_token && ((api_engine && api_engine !== 'cecil') || text),
);
Expand Down Expand Up @@ -75,6 +76,7 @@ export async function summarizeContent({
}
} else {
summary = result?.output_text || 'Unknown error';
timeSavedInMinutes = result?.output_data?.word_stats?.time_saved || 0;
}

success = Boolean(result) && !Boolean(result.error);
Expand All @@ -94,6 +96,7 @@ export async function summarizeContent({
return {
summary,
success,
timeSavedInMinutes,
};
}

Expand Down
10 changes: 7 additions & 3 deletions shared/src/summarize_result.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ h3 {
}

p {
width: 70%;
text-align: center;
margin-top: 5px;
margin-top: 10px;
}

#summary_result {
Expand Down Expand Up @@ -88,3 +86,9 @@ p {
background-color: #f7a808;
border: 1px solid #d9950d;
}

#summary_stats {
padding: 10px;
font-size: 1rem;
line-height: 1.25rem;
}
4 changes: 4 additions & 0 deletions shared/src/summarize_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
</div>

<button id="copy_summary" style="display: none">Copy summary</button>

<div id="summary_stats" class="stats" style="display: none">
<p><strong>Time saved:</strong> <span id="summary_stats_time_saved">0 minutes</span>.</p>
</div>
</div>
<script type="module" src="summarize_result.js"></script>
</body>
Expand Down
27 changes: 26 additions & 1 deletion shared/src/summarize_result.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ async function setup() {
}
});

const summaryStatsElement = document.querySelector('#summary_stats');
if (!summaryStatsElement) {
console.error('Could not find summarize stats div');
return;
}

summaryStatsElement.style.display = 'none';

const summaryStatsTimeSavedElement = document.querySelector(
'#summary_stats_time_saved',
);
if (!summaryStatsTimeSavedElement) {
console.error('Could not find summarize stats time saved element');
return;
}

summaryStatsTimeSavedElement.innerText = '0 minutes';

browser.runtime.onMessage.addListener(async (data) => {
const searchParams = new URLSearchParams(window.location.search);
const url = searchParams.get('url');
Expand All @@ -71,6 +89,13 @@ async function setup() {

summaryResultElement.style.display = '';
summaryResultElement.innerText = summaryTextContents;

if (data.timeSavedInMinutes) {
summaryStatsElement.style.display = '';
summaryStatsTimeSavedElement.innerText = `${
data.timeSavedInMinutes
} minute${data.timeSavedInMinutes !== 1 ? 's' : ''}`;
}
}
});

Expand Down Expand Up @@ -136,7 +161,7 @@ async function setup() {
loadingElement.style.display = '';
summaryResultElement.classList.remove('error');
summaryResultElement.style.display = '';
summaryResultElement.innerHTML = 'Summarizing...';
summaryResultElement.innerText = 'Summarizing...';
copySummaryElement.style.display = 'none';
summaryTextContents = '';

Expand Down

0 comments on commit 851113b

Please sign in to comment.