Skip to content

Commit fa1922b

Browse files
committed
Auto Summaries only enabled for premium-plus users
1 parent 6df2b73 commit fa1922b

File tree

2 files changed

+42
-36
lines changed

2 files changed

+42
-36
lines changed

content.js

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let notificationSent = false;
33
function sendNotification() {
44
if (!notificationSent) {
55
chrome.runtime.sendMessage({ type: "checkboxDetected" });
6-
notificationSent = true; // Ensure notification is only sent once
6+
notificationSent = true;
77
}
88
}
99

@@ -62,66 +62,67 @@ function handlePolicyLinks() {
6262
let linksMap = {};
6363
let summarizedLinks = JSON.parse(localStorage.getItem('summarizedLinks') || '{}');
6464

65-
keywords.forEach(keyword => {
66-
const foundLinks = Array.from(document.querySelectorAll('a')).filter(link => {
67-
return (link.href.toLowerCase().includes(keyword) || link.innerText.toLowerCase().includes(keyword));
68-
});
69-
70-
foundLinks.forEach(link => {
71-
const linkDomain = rootDomain(new URL(link.href, window.location.origin).hostname);
72-
if (linkDomain === currentDomain) {
73-
if (!linksMap[keyword]) { // Ensure only the first match for each keyword is used
74-
linksMap[keyword] = { href: link.href, text: link.innerText.trim() };
75-
76-
// Check if not already summarized
77-
if (!summarizedLinks[link.href] && link.innerText.trim() !== "") {
78-
const summaryRequestData = {
79-
action: "generateSummary",
80-
url: link.href,
81-
policyName: link.innerText.trim()
82-
};
83-
chrome.runtime.sendMessage(summaryRequestData);
84-
displayPreloader(link.innerText.trim(), currentDomain);
85-
console.log("Sent summary request for " + link.innerText.trim());
86-
summarizedLinks[link.href] = true; // Mark as summarized
87-
localStorage.setItem('summarizedLinks', JSON.stringify(summarizedLinks)); // Save to local storage
65+
// get chrome.storage.local of auto_summaries, and if it exists, set it to autoSummaries, else set to false
66+
chrome.storage.local.get(['autoSummaries'], function (result) {
67+
let autoSummaries = result.autoSummaries || false;
68+
if (autoSummaries) {
69+
keywords.forEach(keyword => {
70+
const foundLinks = Array.from(document.querySelectorAll('a')).filter(link => {
71+
return (link.href.toLowerCase().includes(keyword) || link.innerText.toLowerCase().includes(keyword));
72+
});
73+
74+
foundLinks.forEach(link => {
75+
const linkDomain = rootDomain(new URL(link.href, window.location.origin).hostname);
76+
if (linkDomain === currentDomain) {
77+
if (!linksMap[keyword]) {
78+
linksMap[keyword] = { href: link.href, text: link.innerText.trim() };
79+
80+
if (!summarizedLinks[link.href] && link.innerText.trim() !== "") {
81+
const summaryRequestData = {
82+
action: "generateSummary",
83+
url: link.href,
84+
policyName: link.innerText.trim()
85+
};
86+
chrome.runtime.sendMessage(summaryRequestData);
87+
displayPreloader(link.innerText.trim(), currentDomain);
88+
console.log("Sent summary request for " + link.innerText.trim());
89+
summarizedLinks[link.href] = true;
90+
localStorage.setItem('summarizedLinks', JSON.stringify(summarizedLinks));
91+
}
92+
}
8893
}
89-
}
90-
}
91-
});
94+
});
95+
});
96+
}
9297
});
9398

94-
// Always return links that match the keywords, regardless of whether they've been summarized
99+
95100
if (Object.keys(linksMap).length > 0) {
96-
return Object.values(linksMap); // Return the links found for use in popup.js
101+
return Object.values(linksMap);
97102
} else {
98103
return [];
99104
}
100105
}
101106

102-
// This function is called from popup.js to fetch links
103107
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
104108
if (request.action === "findLinks") {
105-
const links = handlePolicyLinks(); // Assume this function is synchronous, adjust if not
109+
const links = handlePolicyLinks();
106110
sendResponse({ links: links });
107-
return true; // Indicates an asynchronous response is expected
111+
return true;
108112
}
109113
});
110114

111-
// Run initial detection on page load
112115
detectCheckboxes();
113116
detectTextConsent();
114117
handlePolicyLinks();
115118

116-
// Periodically check for updates without resending notifications or summary requests unnecessarily
117119
let consentCheckInterval = setInterval(() => {
118120
if (!notificationSent) {
119121
detectCheckboxes();
120122
detectTextConsent();
121123
}
122124
}, 5000);
123125

124-
// Cleanup
125126
setTimeout(() => {
126127
clearInterval(consentCheckInterval);
127128
}, 30000);
@@ -141,4 +142,4 @@ function rootDomain(hostname) {
141142

142143

143144

144-
// works now, but why suggested links are not showing up in the popup???? cry face emoji
145+
// works now, but only one preloader is showing at a time. Not huge deal, but should be fixed eventually

popup.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ function checkLogin() {
88
document.getElementById('nameDisplay').textContent = firstName;
99
document.getElementById('welcomeName').textContent = firstName;
1010

11+
// set chrome storage of auto_summaries: true if the user plan is premium-plus
12+
if (data.plan === 'premium-plus') {
13+
chrome.storage.local.set({ auto_summaries: true });
14+
}
15+
1116
chrome.storage.local.set({ first_name: data.first_name, userPlan: data.plan, summariesCount: data.summariesCount });
1217
updatePremiumFeaturesVisibility();
1318
});

0 commit comments

Comments
 (0)