@@ -129,7 +129,6 @@ const Fetcher = function (cache) { // Pass reload to avoid cached result
129129 host = hostNew ;
130130 filePath = filePath || filePathValue ;
131131 func = func || fetchResolver ;
132- if ( ! popup . up ( ) && ! filePath . includes ( '.dat' ) ) return ;
133132 path = path || ( ! http ? 'https:' : 'http:' ) + '//' + www + host + '/' + filePath ;
134133 fetch ( path , requestInit )
135134 . then ( onlyOK )
@@ -147,9 +146,8 @@ const Fetcher = function (cache) { // Pass reload to avoid cached result
147146 } ) ;
148147} ;
149148
150- //Popup API
149+ //Popup
151150const popup = ( function ( ) {
152- let up = 0 ;
153151
154152 function sellersUpdate ( ) {
155153 ( data . result . status === 0 ) ?
@@ -168,69 +166,57 @@ const popup = (function () {
168166 function ( tabs ) {
169167 if ( ! tabs || tabs . length === 0 ) return ;
170168 const request = Fetcher ( 'default' ) ;
171- if ( up ) request . getDomain ( tabs [ 0 ] . url ) ;
169+ request . getDomain ( tabs [ 0 ] . url ) ;
172170 }
173171 ) ;
174172 }
175173
176- // Capture URL if loaded later than the popup was open
177- function lateLoadURL ( tabId , changeInfo , pTab ) {
178- if ( changeInfo . url && pTab . active ) {
179- // Send message new fetch is upcomming
180- popup . message ( 'reset' ) ;
181- const request = Fetcher ( 'default' ) ;
182- if ( up ) request . getDomain ( changeInfo . url ) ;
183- }
184- }
185-
186174 let saveTimeout ;
175+ let tabUpdatedListener ;
187176
188177 return {
189- up : ( sendResponse ) => {
190- if ( sendResponse ) sendResponse ( up ) ;
191- return up ;
178+ noFetchEval : function ( d ) {
179+ chrome . storage . local . set ( d , function ( ) {
180+ if ( d . sellers !== undefined ) {
181+ config . sellers = d . sellers ;
182+ sellersUpdate ( ) ;
183+ }
184+ } ) ;
192185 } ,
193186 load : function ( ) {
194- up = 1 ;
195- chrome . storage . local . set ( { popupActive : up } ) ;
196- chrome . tabs . onUpdated . addListener ( lateLoadURL ) ;
187+ if ( ! tabUpdatedListener ) {
188+ chrome . tabs . onUpdated . addListener ( getTab ) ;
189+ tabUpdatedListener = true ;
190+ }
197191 getTab ( ) ;
198192 } ,
199- unload : function ( ) {
200- up = 0 ;
201- chrome . storage . local . set ( { popupActive : up } ) ;
202- chrome . tabs . onUpdated . removeListener ( lateLoadURL ) ;
203- } ,
204193 getSync : async function ( sendResponse ) {
205- const data = await config . getSync ( ) ;
206- if ( sendResponse ) {
207- sendResponse ( data ) ;
208- }
209- return data ;
194+ const d = await config . getSync ( ) ;
195+ if ( sendResponse ) {
196+ sendResponse ( d ) ;
197+ }
198+ return d ;
210199 } ,
211- saveSync : function ( data ) {
200+ saveSync : function ( d ) {
212201 if ( saveTimeout ) clearTimeout ( saveTimeout ) ;
213202
214203 saveTimeout = setTimeout ( function ( ) {
215- chrome . storage . local . set ( data , function ( ) {
216- if ( data . sellers !== undefined ) {
217- config . sellers = data . sellers ;
218- if ( up ) sellersUpdate ( ) ;
204+ chrome . storage . local . set ( d , function ( ) {
205+ if ( d . sellers !== undefined ) {
206+ config . sellers = d . sellers ;
219207 }
220208 } ) ;
221209 } , 500 ) ;
222210 } ,
223211 message : function ( resObj ) {
224- if ( up ) {
225- try {
226- chrome . runtime . sendMessage ( resObj , ( ) => {
227- if ( chrome . runtime . lastError ) {
228- console . error ( 'Message recipient unavailable:' , chrome . runtime . lastError ) ;
229- }
230- } ) ;
231- } catch ( error ) {
232- console . error ( 'Error sending message:' , error ) ;
233- }
212+ try {
213+ chrome . runtime . sendMessage ( resObj , ( ) => {
214+ if ( chrome . runtime . lastError ) {
215+ console . log ( 'Message recipient unavailable:' , chrome . runtime . lastError ) ;
216+ }
217+ } ) ;
218+ } catch ( error ) {
219+ console . log ( 'Error sending message:' , error ) ;
234220 }
235221 } ,
236222 refetch : function ( ) {
@@ -393,7 +379,7 @@ chrome.runtime.onMessage.addListener((message, _, sendResponse) => {
393379 return true ;
394380 }
395381
396- if ( handler && message . action === 'saveSync' ) {
382+ if ( handler && ( message . action === 'saveSync' || message . action === 'noFetchEval' ) ) {
397383 handler ( message . data ) ;
398384 sendResponse ( { received : 'true' } ) ;
399385 return true ;
0 commit comments