@@ -6,6 +6,8 @@ new (class ExtensionPopup {
66  websitesList  =  document . getElementById ( "websites-list" ) ; 
77  currentSiteFeatures  =  document . getElementById ( "current-site-toggles" ) ; 
88  currentSiteHostname  =  "" ; 
9+   autoUpdateSwitch  =  document . getElementById ( "auto-update" ) ; 
10+   lastFetchedTime  =  document . getElementById ( "last-fetched-time" ) ; 
911
1012  constructor ( )  { 
1113    this . loadSettings ( ) . then ( ( settings )  =>  { 
@@ -22,6 +24,12 @@ new (class ExtensionPopup {
2224      this . websitesList . classList . toggle ( "collapsed" ) ; 
2325    } ) ; 
2426
27+     this . autoUpdateSwitch . addEventListener ( 
28+       "change" , 
29+       this . saveSettings . bind ( this ) 
30+     ) ; 
31+     this . setupAutoUpdate ( ) ; 
32+     this . displayLastFetchedTime ( ) ; 
2533    this . setupContentScriptInjection ( ) ; 
2634    this . displayAddonVersion ( ) ; 
2735  } 
@@ -61,6 +69,9 @@ new (class ExtensionPopup {
6169      this . enableStylingSwitch . checked  = 
6270        this . browserStorageSettings . enableStyling ; 
6371    } 
72+     if  ( this . browserStorageSettings . autoUpdate  !==  undefined )  { 
73+       this . autoUpdateSwitch . checked  =  this . browserStorageSettings . autoUpdate ; 
74+     } 
6475    this . loadCurrentSiteFeatures ( ) ; 
6576    this . loadWebsitesList ( ) ; 
6677  } 
@@ -74,6 +85,7 @@ new (class ExtensionPopup {
7485  saveSettings ( )  { 
7586    this . browserStorageSettings . enableStyling  = 
7687      this . enableStylingSwitch . checked ; 
88+     this . browserStorageSettings . autoUpdate  =  this . autoUpdateSwitch . checked ; 
7789
7890    const  featureSettings  =  { } ; 
7991    this . currentSiteFeatures 
@@ -191,6 +203,7 @@ new (class ExtensionPopup {
191203      if  ( ! response . ok )  throw  new  Error ( "Failed to fetch styles.json" ) ; 
192204      const  styles  =  await  response . json ( ) ; 
193205      await  browser . storage . local . set ( {  styles } ) ; 
206+       await  browser . storage . local . set ( {  lastFetchedTime : Date . now ( )  } ) ; 
194207
195208      this . loadCurrentSiteFeatures ( ) ; 
196209      this . loadWebsitesList ( ) ; 
@@ -201,6 +214,7 @@ new (class ExtensionPopup {
201214        this . refetchCSSButton . textContent  =  "Refetch latest styles" ; 
202215      } ,  2000 ) ; 
203216      console . info ( "All styles refetched and updated from GitHub."  +  styles ) ; 
217+       this . displayLastFetchedTime ( ) ; 
204218    }  catch  ( error )  { 
205219      this . refetchCSSButton . textContent  =  "Error!" ; 
206220      setTimeout ( ( )  =>  { 
@@ -294,4 +308,22 @@ new (class ExtensionPopup {
294308      "addon-version" 
295309    ) . textContent  =  `Version: ${ version }  ; 
296310  } 
311+   
312+   setupAutoUpdate ( )  { 
313+     if  ( this . autoUpdateSwitch . checked )  { 
314+       browser . runtime . sendMessage ( {  action : "enableAutoUpdate"  } ) ; 
315+     }  else  { 
316+       browser . runtime . sendMessage ( {  action : "disableAutoUpdate"  } ) ; 
317+     } 
318+   } 
319+ 
320+   displayLastFetchedTime ( )  { 
321+     browser . storage . local . get ( "lastFetchedTime" ) . then ( ( result )  =>  { 
322+       if  ( result . lastFetchedTime )  { 
323+         this . lastFetchedTime . textContent  =  `Last fetched: ${ new  Date (  
324+           result . lastFetchedTime  
325+         ) . toLocaleString ( ) }  `; 
326+       } 
327+     } ) ; 
328+   } 
297329} ) ( ) ; 
0 commit comments