1- var darkThemes = [ "dark" , "ayu" ] ;
1+ /* eslint-env es6 */
2+ /* eslint no-var: "error" */
3+ /* eslint prefer-const: "error" */
4+
5+ const darkThemes = [ "dark" , "ayu" ] ;
26window . currentTheme = document . getElementById ( "themeStyle" ) ;
37window . mainTheme = document . getElementById ( "mainThemeStyle" ) ;
48
5- var settingsDataset = ( function ( ) {
6- var settingsElement = document . getElementById ( "default-settings" ) ;
9+ const settingsDataset = ( function ( ) {
10+ const settingsElement = document . getElementById ( "default-settings" ) ;
711 if ( settingsElement === null ) {
812 return null ;
913 }
10- var dataset = settingsElement . dataset ;
14+ const dataset = settingsElement . dataset ;
1115 if ( dataset === undefined ) {
1216 return null ;
1317 }
1418 return dataset ;
1519} ) ( ) ;
1620
1721function getSettingValue ( settingName ) {
18- var current = getCurrentValue ( settingName ) ;
22+ const current = getCurrentValue ( settingName ) ;
1923 if ( current !== null ) {
2024 return current ;
2125 }
2226 if ( settingsDataset !== null ) {
2327 // See the comment for `default_settings.into_iter()` etc. in
2428 // `Options::from_matches` in `librustdoc/config.rs`.
25- var def = settingsDataset [ settingName . replace ( / - / g, '_' ) ] ;
29+ const def = settingsDataset [ settingName . replace ( / - / g, '_' ) ] ;
2630 if ( def !== undefined ) {
2731 return def ;
2832 }
2933 }
3034 return null ;
3135}
3236
33- var localStoredTheme = getSettingValue ( "theme" ) ;
37+ const localStoredTheme = getSettingValue ( "theme" ) ;
3438
35- var savedHref = [ ] ;
39+ const savedHref = [ ] ;
3640
3741// eslint-disable-next-line no-unused-vars
3842function hasClass ( elem , className ) {
@@ -63,17 +67,16 @@ function removeClass(elem, className) {
6367 */
6468function onEach ( arr , func , reversed ) {
6569 if ( arr && arr . length > 0 && func ) {
66- var length = arr . length ;
67- var i ;
6870 if ( reversed ) {
69- for ( i = length - 1 ; i >= 0 ; -- i ) {
71+ const length = arr . length ;
72+ for ( let i = length - 1 ; i >= 0 ; -- i ) {
7073 if ( func ( arr [ i ] ) ) {
7174 return true ;
7275 }
7376 }
7477 } else {
75- for ( i = 0 ; i < length ; ++ i ) {
76- if ( func ( arr [ i ] ) ) {
78+ for ( const elem of arr ) {
79+ if ( func ( elem ) ) {
7780 return true ;
7881 }
7982 }
@@ -121,7 +124,7 @@ function getCurrentValue(name) {
121124}
122125
123126function switchTheme ( styleElem , mainStyleElem , newTheme , saveTheme ) {
124- var newHref = mainStyleElem . href . replace (
127+ const newHref = mainStyleElem . href . replace (
125128 / \/ r u s t d o c ( [ ^ / ] * ) \. c s s / , "/" + newTheme + "$1" + ".css" ) ;
126129
127130 // If this new value comes from a system setting or from the previously
@@ -134,7 +137,7 @@ function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) {
134137 return ;
135138 }
136139
137- var found = false ;
140+ let found = false ;
138141 if ( savedHref . length === 0 ) {
139142 onEachLazy ( document . getElementsByTagName ( "link" ) , function ( el ) {
140143 savedHref . push ( el . href ) ;
@@ -161,17 +164,17 @@ function useSystemTheme(value) {
161164 updateLocalStorage ( "use-system-theme" , value ) ;
162165
163166 // update the toggle if we're on the settings page
164- var toggle = document . getElementById ( "use-system-theme" ) ;
167+ const toggle = document . getElementById ( "use-system-theme" ) ;
165168 if ( toggle && toggle instanceof HTMLInputElement ) {
166169 toggle . checked = value ;
167170 }
168171}
169172
170- var updateSystemTheme = ( function ( ) {
173+ const updateSystemTheme = ( function ( ) {
171174 if ( ! window . matchMedia ) {
172175 // fallback to the CSS computed value
173176 return function ( ) {
174- var cssTheme = getComputedStyle ( document . documentElement )
177+ const cssTheme = getComputedStyle ( document . documentElement )
175178 . getPropertyValue ( 'content' ) ;
176179
177180 switchTheme (
@@ -184,16 +187,16 @@ var updateSystemTheme = (function() {
184187 }
185188
186189 // only listen to (prefers-color-scheme: dark) because light is the default
187- var mql = window . matchMedia ( "(prefers-color-scheme: dark)" ) ;
190+ const mql = window . matchMedia ( "(prefers-color-scheme: dark)" ) ;
188191
189192 function handlePreferenceChange ( mql ) {
190- let use = function ( theme ) {
193+ const use = function ( theme ) {
191194 switchTheme ( window . currentTheme , window . mainTheme , theme , true ) ;
192195 } ;
193196 // maybe the user has disabled the setting in the meantime!
194197 if ( getSettingValue ( "use-system-theme" ) !== "false" ) {
195- var lightTheme = getSettingValue ( "preferred-light-theme" ) || "light" ;
196- var darkTheme = getSettingValue ( "preferred-dark-theme" ) || "dark" ;
198+ const lightTheme = getSettingValue ( "preferred-light-theme" ) || "light" ;
199+ const darkTheme = getSettingValue ( "preferred-dark-theme" ) || "dark" ;
197200
198201 if ( mql . matches ) {
199202 use ( darkTheme ) ;
0 commit comments