Skip to content
This repository was archived by the owner on Jul 20, 2025. It is now read-only.

Commit aa7c35e

Browse files
authored
Bump to 1.1.0 (#12)
* Change name of package * Update package lock * Apply formatting --------- Co-authored-by: marksverdhei <>
1 parent 82185a8 commit aa7c35e

File tree

6 files changed

+130
-111
lines changed

6 files changed

+130
-111
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "Save Me A Click",
4-
"version": "1.0.1",
4+
"version": "1.1.0",
55
"description": "Summarize any link with a right-click",
66
"permissions": [
77
"contextMenus",

package-lock.json

Lines changed: 19 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "syac-extension-2",
3-
"version": "1.0.0",
2+
"name": "save-me-a-click",
3+
"version": "1.1.0",
44
"description": "Save Me A Click is a Chrome extension that provides a summary of a webpage when right-clicking on a link. It displays a popup with a title, body, and summary without needing to open the page.",
55
"main": "index.js",
66
"scripts": {

src/background.js

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
1-
const Article = require("newspaperjs").Article
2-
const LanguageDetect = require('languagedetect');
1+
const Article = require("newspaperjs").Article;
2+
const LanguageDetect = require("languagedetect");
33
const languageDetector = new LanguageDetect();
44

55
const PROMPTS = {
6-
"english": [
7-
{
8-
"role": "system",
9-
"content": "You are a tool that generates saved-you-a-click summaries when provided clickbait titles and content",
10-
},
11-
{
12-
"role": "user",
13-
"content": "Your task is the following: Given the title and the body of a clickbait article, provide the information that one would desire or wonder about upon reading the title.\n" +
14-
"* Be exact, on point and provide your answer as a repsonse to the title, and make your answers brief, preferrably in one sentence.\n" +
15-
" Example: Costco shoppers shifting away from specific item; CFO says it’s indicator of recession | Beef and steaks.\n" +
16-
"* If the article is a list of N items, simply list each item and nothing else.\n" +
17-
" Example: 5 Fast-Food Chains That Have Gone From the Best to the Bottom In a Few Years | Burgerim, Quiznos, Boston Market, Red Barn, Burger Chef\n" +
18-
"* If there is not sufficient information in the article body to answer the title, state so in the answer.\n" +
19-
" Example: Why Big Tech execs are swapping the boardroom for the dojo | Article doesn't say\n\n"
20-
},
6+
english: [
7+
{
8+
role: "system",
9+
content:
10+
"You are a tool that generates saved-you-a-click summaries when provided clickbait titles and content",
11+
},
12+
{
13+
role: "user",
14+
content:
15+
"Your task is the following: Given the title and the body of a clickbait article, provide the information that one would desire or wonder about upon reading the title.\n" +
16+
"* Be exact, on point and provide your answer as a repsonse to the title, and make your answers brief, preferrably in one sentence.\n" +
17+
" Example: Costco shoppers shifting away from specific item; CFO says it’s indicator of recession | Beef and steaks.\n" +
18+
"* If the article is a list of N items, simply list each item and nothing else.\n" +
19+
" Example: 5 Fast-Food Chains That Have Gone From the Best to the Bottom In a Few Years | Burgerim, Quiznos, Boston Market, Red Barn, Burger Chef\n" +
20+
"* If there is not sufficient information in the article body to answer the title, state so in the answer.\n" +
21+
" Example: Why Big Tech execs are swapping the boardroom for the dojo | Article doesn't say\n\n",
22+
},
2123
],
2224
// Options to enter other languages here
23-
}
25+
};
2426

2527
function getMissingLanguagePrompt(language) {
2628
return [
2729
{
28-
"role": "system",
29-
"content": `You are a tool that generates saved-you-a-click summaries when provided clickbait titles and content written in ${language}`,
30+
role: "system",
31+
content: `You are a tool that generates saved-you-a-click summaries when provided clickbait titles and content written in ${language}`,
3032
},
3133
{
32-
"role": "user",
33-
"content": "Given the title and the body of a clickbait article, please provide the information that one might desire upon reading the title. Make the answer as brief as you can.\n" +
34+
role: "user",
35+
content:
36+
"Given the title and the body of a clickbait article, please provide the information that one might desire upon reading the title. Make the answer as brief as you can.\n" +
3437
`If there is no information in the article content that answers the title, provide your answer as 'The article doesn't say' in ${language}. Write your response in ${language}`,
3538
},
36-
]
39+
];
3740
}
3841

39-
4042
chrome.runtime.onInstalled.addListener(() => {
4143
chrome.contextMenus.create({
4244
id: "saveMeAClick",
@@ -45,41 +47,47 @@ chrome.runtime.onInstalled.addListener(() => {
4547
});
4648
});
4749

48-
4950
chrome.contextMenus.onClicked.addListener((info, tab) => {
5051
if (info.menuItemId === "saveMeAClick") {
51-
console.log("Sending saveMeAClick to content.js")
52+
console.log("Sending saveMeAClick to content.js");
5253
chrome.tabs.sendMessage(tab.id, { url: info.linkUrl });
5354
}
5455
});
5556

56-
5757
chrome.runtime.onMessage.addListener(async (message, sender) => {
5858
if (message.type === "startSpinner") {
59-
chrome.tabs.sendMessage(sender.tab.id, { startSpinner: true, url: message.url });
59+
chrome.tabs.sendMessage(sender.tab.id, {
60+
startSpinner: true,
61+
url: message.url,
62+
});
6063
}
6164
if (message.type === "fetchSummary") {
62-
console.log("Received fetchSummary from content.js. Sending spinnner")
65+
console.log("Received fetchSummary from content.js. Sending spinnner");
6366
// Send the message to start the spinner
6467

6568
try {
6669
const summary = await getSummary(message.url);
67-
console.log("Summary received, sending to content.js")
68-
chrome.tabs.sendMessage(sender.tab.id, { summary: summary, overlayId: message.overlayId });
70+
console.log("Summary received, sending to content.js");
71+
chrome.tabs.sendMessage(sender.tab.id, {
72+
summary: summary,
73+
overlayId: message.overlayId,
74+
});
6975
} catch (error) {
70-
console.log("There was an error, sending to content.js")
71-
console.log(error.name);
76+
console.log("There was an error, sending to content.js");
77+
console.log(error.name);
7278
console.log(error.message);
7379
console.log(error.stack);
74-
chrome.tabs.sendMessage(sender.tab.id, { error: error.message, overlayId: message.overlayId });
80+
chrome.tabs.sendMessage(sender.tab.id, {
81+
error: error.message,
82+
overlayId: message.overlayId,
83+
});
7584
}
7685
}
7786
});
7887

79-
8088
function getApiKey() {
8189
return new Promise((resolve, reject) => {
82-
chrome.storage.sync.get(['apiKey'], function(result) {
90+
chrome.storage.sync.get(["apiKey"], function (result) {
8391
if (chrome.runtime.lastError) {
8492
return reject(chrome.runtime.lastError);
8593
}
@@ -88,42 +96,36 @@ function getApiKey() {
8896
});
8997
}
9098

91-
9299
function getDataContent(data) {
93100
if (
94-
(
95-
(!data)
96-
|| (!data.choices)
97-
|| (!data.choices[0])
98-
|| (!data.choices[0].message)
99-
|| (!data.choices[0].message.content)
100-
101-
)
101+
!data ||
102+
!data.choices ||
103+
!data.choices[0] ||
104+
!data.choices[0].message ||
105+
!data.choices[0].message.content
102106
) {
103107
return "Data missing";
104108
} else {
105-
return data.choices[0].message.content
109+
return data.choices[0].message.content;
106110
}
107-
108111
}
109112

110113
/**
111-
*
114+
*
112115
* @param {str} url url address of the clickbait article or web page
113116
* @returns {object} summary of the given clickbait content
114117
*/
115118
async function getSummary(url) {
116119
const article = await Article(url);
117120
const title = article.title;
118121
const body = article.text;
119-
120-
if (!(title && body))
121-
throw new Error("missing article title or text");
122-
122+
123+
if (!(title && body)) throw new Error("missing article title or text");
124+
123125
const languages = languageDetector.detect(title + body, 1);
124-
console.log(languages)
126+
console.log(languages);
125127
const language = languages[0][0];
126-
console.log(language)
128+
console.log(language);
127129

128130
if (language in PROMPTS) {
129131
prePrompt = PROMPTS[language];
@@ -132,11 +134,11 @@ async function getSummary(url) {
132134
}
133135

134136
fullPrompt = prePrompt.concat([
135-
{"role": "user", "content": `<article-title>${title}</article-title>`},
136-
{"role": "user", "content": `<article-body>${body}</article-body>`},
137-
])
138-
console.log(fullPrompt)
139-
137+
{ role: "user", content: `<article-title>${title}</article-title>` },
138+
{ role: "user", content: `<article-body>${body}</article-body>` },
139+
]);
140+
console.log(fullPrompt);
141+
140142
let result = {
141143
title: title,
142144
body: body,
@@ -151,12 +153,12 @@ async function getSummary(url) {
151153
method: "POST",
152154
headers: {
153155
"Content-Type": "application/json",
154-
"Authorization": `Bearer ${apiKey}`
156+
Authorization: `Bearer ${apiKey}`,
155157
},
156158
body: JSON.stringify({
157-
"model": "gpt-3.5-turbo",
158-
"messages": fullPrompt,
159-
"temperature": 0.7
159+
model: "gpt-3.5-turbo",
160+
messages: fullPrompt,
161+
temperature: 0.7,
160162
}),
161163
});
162164

@@ -174,4 +176,4 @@ async function getSummary(url) {
174176
console.error(error);
175177
throw error;
176178
}
177-
}
179+
}

src/content.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,34 @@ document.addEventListener("contextmenu", (event) => {
77

88
chrome.runtime.onMessage.addListener((message, sender) => {
99
if (message.startSpinner) {
10-
const overlay = displayOverlay("Loading...", "", "", lastRightClickPosition.x, lastRightClickPosition.y);
11-
chrome.runtime.sendMessage({ url: message.url, type: "fetchSummary", overlayId: overlay.id })
12-
10+
const overlay = displayOverlay(
11+
"Loading...",
12+
"",
13+
"",
14+
lastRightClickPosition.x,
15+
lastRightClickPosition.y
16+
);
17+
chrome.runtime.sendMessage({
18+
url: message.url,
19+
type: "fetchSummary",
20+
overlayId: overlay.id,
21+
});
1322
} else if (message.summary) {
1423
const { title, body, answer } = message.summary;
1524
console.log("summary received in content.js. Updating overlay");
1625
updateOverlay(message.overlayId, answer, body, title);
1726
} else if (message.error) {
1827
updateOverlay(message.overlayId, "Error", "", message.error);
1928
} else {
20-
chrome.runtime.sendMessage({ url: message.url, type: "startSpinner" })
29+
chrome.runtime.sendMessage({ url: message.url, type: "startSpinner" });
2130
}
2231
});
2332

24-
2533
function updateOverlay(overlayId, title, body, summary) {
2634
console.log("Update overlay called");
2735
const overlay = document.getElementById(overlayId);
28-
console.log(overlayId)
29-
console.log(overlay)
36+
console.log(overlayId);
37+
console.log(overlay);
3038

3139
// Remove the spinner
3240
const spinner = overlay.querySelector(".spinner");
@@ -48,13 +56,11 @@ function updateOverlay(overlayId, title, body, summary) {
4856
overlayBox.appendChild(summaryEl);
4957
}
5058

51-
52-
5359
function displayOverlay(title, body, summary, x, y) {
5460
// Create the overlay elements
5561
const overlay = document.createElement("div");
5662
overlay.className = "overlay";
57-
overlay.id = "overlay" + document.querySelectorAll(".overlay").length
63+
overlay.id = "overlay" + document.querySelectorAll(".overlay").length;
5864
overlay.style.left = `${x}px`;
5965
overlay.style.top = `${y}px`;
6066

@@ -86,6 +92,3 @@ function displayOverlay(title, body, summary, x, y) {
8692

8793
return overlay;
8894
}
89-
90-
91-

0 commit comments

Comments
 (0)