@@ -23,11 +23,24 @@ document.addEventListener("DOMContentLoaded", async () => {
2323
2424async function initOptions ( ) {
2525 let themes = [ "photon" , "australis" , "classic" , "pastel-svg" , "aero" ] ;
26- let currentTheme = ( await browser . storage . sync . get ( {
27- theme : await getDefaultTheme ( )
28- } ) ) . theme ;
26+ let data = ( await browser . storage . sync . get ( {
27+ theme : await getDefaultTheme ( ) ,
28+ preferredWindowState : "maximized"
29+ } ) ) ;
30+ let currentTheme = data . theme ;
2931 let themeSelector = document . querySelector ( "#theme" ) ;
3032
33+ let preferredWindowStateSelector = document . querySelector ( "#fullscreenExitState" ) ;
34+ for ( let i = 0 ; i < preferredWindowStateSelector . length ; i ++ ) {
35+ let option = preferredWindowStateSelector . item ( i ) ;
36+ if ( option . value === data . preferredWindowState ) {
37+ preferredWindowStateSelector . selectedIndex = i ;
38+ option . setAttribute ( "selected" , true ) ;
39+ } else {
40+ option . selected = false ;
41+ }
42+ }
43+
3144 for ( let t of themes ) {
3245 try {
3346 let response = await fetch ( `/themes/${ t } /theme.json` ) ;
@@ -87,10 +100,10 @@ async function initOptions() {
87100 select . addEventListener ( "change" , evt => {
88101 if ( select . selectedIndex >= 0 ) {
89102 let selectedOption = select . item ( select . selectedIndex ) ;
90- let themeDir = select . item ( select . selectedIndex ) . value ;
91- browser . storage . sync . set ( {
92- theme : themeDir
93- } ) ;
103+ let value = select . item ( select . selectedIndex ) . value ;
104+ let data = { } ;
105+ data [ select . dataset . save ] = value ;
106+ browser . storage . sync . set ( data ) ;
94107// if (selectedOption.dataset.icon) {
95108// select.style.cssText = `
96109// background-image: url("${selectedOption.dataset.icon}"), url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgdmlld0JveD0iMCAwIDE2IDE2Ij4KICA8cGF0aCBkPSJNOCwxMkwzLDcsNCw2bDQsNCw0LTQsMSwxWiIgZmlsbD0iIzZBNkE2QSIgLz4KPC9zdmc+Cg==) !important;
@@ -102,26 +115,28 @@ async function initOptions() {
102115// select.removeAttribute("style");
103116// }
104117
105- fetch ( `/themes/${ themeDir } /theme.json` ) . then ( r => r . json ( ) ) . then ( config => {
106- let extension = config . default_extension || "svg" ;
107- if ( config . browser_action ) {
108- let path = { } ;
109- for ( let k in config . browser_action ) {
110- path [ k ] = `/themes/${ themeDir } /${ config . browser_action [ k ] . includes ( '.' ) ?
111- config . browser_action [ k ] : config . browser_action [ k ] + '.' + extension } `
118+ if ( select . dataset . save === "theme" ) {
119+ fetch ( `/themes/${ value } /theme.json` ) . then ( r => r . json ( ) ) . then ( config => {
120+ let extension = config . default_extension || "svg" ;
121+ if ( config . browser_action ) {
122+ let path = { } ;
123+ for ( let k in config . browser_action ) {
124+ path [ k ] = `/themes/${ value } /${ config . browser_action [ k ] . includes ( '.' ) ?
125+ config . browser_action [ k ] : config . browser_action [ k ] + '.' + extension } `
126+ }
127+ browser . browserAction . setIcon ( { path : path } ) ;
128+ } else {
129+ browser . browserAction . setIcon ( { path : `/themes/${ value } /firefox.${ extension } ` } ) ;
112130 }
113- browser . browserAction . setIcon ( { path : path } ) ;
114- } else {
115- browser . browserAction . setIcon ( { path : `/themes/${ themeDir } /firefox.${ extension } ` } ) ;
116- }
117- } ) ;
131+ } ) ;
132+ }
118133 }
119134 } ) ;
120135 } ) ;
121136}
122137
123138async function i18nInit ( ) {
124- document . querySelectorAll ( "label[for]" ) . forEach ( translatable => {
139+ document . querySelectorAll ( "label[for]:not([data-i18n]) " ) . forEach ( translatable => {
125140 let text = browser . i18n . getMessage ( `options_${ translatable . getAttribute ( "for" ) } ` ) ;
126141 if ( text . length > 0 )
127142 translatable . textContent = text ;
0 commit comments