@@ -3,7 +3,7 @@ let notificationSent = false;
3
3
function sendNotification ( ) {
4
4
if ( ! notificationSent ) {
5
5
chrome . runtime . sendMessage ( { type : "checkboxDetected" } ) ;
6
- notificationSent = true ; // Ensure notification is only sent once
6
+ notificationSent = true ;
7
7
}
8
8
}
9
9
@@ -62,66 +62,67 @@ function handlePolicyLinks() {
62
62
let linksMap = { } ;
63
63
let summarizedLinks = JSON . parse ( localStorage . getItem ( 'summarizedLinks' ) || '{}' ) ;
64
64
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
+ }
88
93
}
89
- }
90
- }
91
- } ) ;
94
+ } ) ;
95
+ } ) ;
96
+ }
92
97
} ) ;
93
98
94
- // Always return links that match the keywords, regardless of whether they've been summarized
99
+
95
100
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 ) ;
97
102
} else {
98
103
return [ ] ;
99
104
}
100
105
}
101
106
102
- // This function is called from popup.js to fetch links
103
107
chrome . runtime . onMessage . addListener ( function ( request , sender , sendResponse ) {
104
108
if ( request . action === "findLinks" ) {
105
- const links = handlePolicyLinks ( ) ; // Assume this function is synchronous, adjust if not
109
+ const links = handlePolicyLinks ( ) ;
106
110
sendResponse ( { links : links } ) ;
107
- return true ; // Indicates an asynchronous response is expected
111
+ return true ;
108
112
}
109
113
} ) ;
110
114
111
- // Run initial detection on page load
112
115
detectCheckboxes ( ) ;
113
116
detectTextConsent ( ) ;
114
117
handlePolicyLinks ( ) ;
115
118
116
- // Periodically check for updates without resending notifications or summary requests unnecessarily
117
119
let consentCheckInterval = setInterval ( ( ) => {
118
120
if ( ! notificationSent ) {
119
121
detectCheckboxes ( ) ;
120
122
detectTextConsent ( ) ;
121
123
}
122
124
} , 5000 ) ;
123
125
124
- // Cleanup
125
126
setTimeout ( ( ) => {
126
127
clearInterval ( consentCheckInterval ) ;
127
128
} , 30000 ) ;
@@ -141,4 +142,4 @@ function rootDomain(hostname) {
141
142
142
143
143
144
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
0 commit comments