@@ -99,7 +99,7 @@ function preprocessText(text) {
9999}
100100
101101// Function to check if two responses are meaningfully different
102- function isDifferentResponse ( originalText , modifiedText ) {
102+ function isDifferentResponse ( originalText , modifiedText , similarityThreshold ) {
103103 // Preprocess the texts before comparison
104104 const preprocessedOriginalText = preprocessText ( originalText ) ;
105105 const preprocessedModifiedText = preprocessText ( modifiedText ) ;
@@ -110,9 +110,6 @@ function isDifferentResponse(originalText, modifiedText) {
110110 preprocessedModifiedText
111111 ) ;
112112
113- // Set a threshold for similarity; responses with similarity below this threshold are considered different
114- const similarityThreshold = 0.90 ;
115-
116113 // Return true if the similarity is below the threshold
117114 return similarity < similarityThreshold ;
118115}
@@ -127,7 +124,15 @@ async function binarySearch(url, includedParams, searchParams, originalText) {
127124 const modifiedUrl = appendQueryParam ( url , searchParams [ 0 ] ) ;
128125 const modifiedResponse = await fetch ( modifiedUrl ) ;
129126 const modifiedText = await modifiedResponse . text ( ) ;
130- if ( isDifferentResponse ( originalText , modifiedText ) ) {
127+
128+ // Load similarityThreshold from storage
129+ const storedSettings = await new Promise ( resolve => {
130+ chrome . storage . sync . get ( 'similarityThreshold' , resolve ) ;
131+ } ) ;
132+
133+ const similarityThreshold = storedSettings . similarityThreshold || 0.97 ;
134+
135+ if ( isDifferentResponse ( originalText , modifiedText , similarityThreshold ) ) {
131136 addModifiedUrl ( modifiedUrl ) ;
132137 }
133138 return ;
@@ -145,7 +150,14 @@ async function binarySearch(url, includedParams, searchParams, originalText) {
145150 const modifiedResponse = await fetch ( modifiedUrl ) ;
146151 const modifiedText = await modifiedResponse . text ( ) ;
147152
148- if ( isDifferentResponse ( originalText , modifiedText ) ) {
153+ // Load similarityThreshold from storage
154+ const storedSettings = await new Promise ( resolve => {
155+ chrome . storage . sync . get ( 'similarityThreshold' , resolve ) ;
156+ } ) ;
157+
158+ const similarityThreshold = storedSettings . similarityThreshold || 0.97 ;
159+
160+ if ( isDifferentResponse ( originalText , modifiedText , similarityThreshold ) ) {
149161 // If the response is different, add the modified URL and search for more modifications
150162 addModifiedUrl ( modifiedUrl ) ;
151163 await binarySearch ( url , includedParams , searchParams . slice ( 0 , middleIndex ) , originalText ) ;
@@ -174,4 +186,4 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
174186
175187// Expose getModifiedUrls and clearModifiedUrls functions to popup
176188window . getModifiedUrls = getModifiedUrls ;
177- window . clearModifiedUrls = clearModifiedUrls ;
189+ window . clearModifiedUrls = clearModifiedUrls ;
0 commit comments