@@ -8,15 +8,15 @@ const searchDialog = document.querySelector("[data-search-dialog]")
88const searchInput = document . querySelector ( "[data-search-input]" )
99const searchStatus = document . querySelector ( "[data-search-status]" )
1010const searchResults = document . querySelector ( "[data-search-results]" )
11- const githubStars = document . querySelector ( "[data-github-stars]" )
1211
1312const themes = [ "auto" , "light" , "dark" ]
14- const themeLabels = { auto : "System theme " , light : "Light theme " , dark : "Dark theme " }
13+ const themeLabels = { auto : "System" , light : "Light" , dark : "Dark" }
1514
1615const updateThemeButton = ( ) => {
1716 const theme = root . dataset . theme ?? "auto"
18- themeButton . textContent = theme === "dark" ? "Light" : theme === "light" ? "Dark" : "Theme"
19- themeButton . title = themeLabels [ theme ]
17+ const label = themeLabels [ theme ]
18+ themeButton . textContent = label
19+ themeButton . title = `Current theme: ${ label } `
2020}
2121
2222themeButton ?. addEventListener ( "click" , ( ) => {
@@ -28,39 +28,6 @@ themeButton?.addEventListener("click", () => {
2828} )
2929updateThemeButton ( )
3030
31- const showGitHubStars = ( count ) => {
32- const countElement = githubStars ?. querySelector ( "[data-github-star-count]" )
33- if ( githubStars === null || countElement === null || ! Number . isSafeInteger ( count ) || count < 0 ) return
34- countElement . textContent = new Intl . NumberFormat ( undefined , {
35- maximumFractionDigits : 1 ,
36- notation : count >= 1_000 ? "compact" : "standard"
37- } ) . format ( count )
38- githubStars . title = `${ count . toLocaleString ( ) } GitHub star${ count === 1 ? "" : "s" } `
39- githubStars . hidden = false
40- }
41-
42- const loadGitHubStars = async ( ) => {
43- const repository = githubStars ?. dataset . githubStars
44- if ( repository === undefined ) return
45- const cacheKey = `api-reference:github-stars:${ repository } `
46- try {
47- const cached = sessionStorage . getItem ( cacheKey )
48- if ( cached !== null ) {
49- showGitHubStars ( Number ( cached ) )
50- return
51- }
52- const response = await fetch ( `https://api.github.com/repos/${ repository } ` )
53- if ( ! response . ok ) return
54- const body = await response . json ( )
55- if ( ! Number . isSafeInteger ( body . stargazers_count ) || body . stargazers_count < 0 ) return
56- sessionStorage . setItem ( cacheKey , String ( body . stargazers_count ) )
57- showGitHubStars ( body . stargazers_count )
58- } catch {
59- // The repository link remains usable when storage or GitHub is unavailable.
60- }
61- }
62- void loadGitHubStars ( )
63-
6431const setNavigationOpen = ( open ) => {
6532 document . body . classList . toggle ( "navigation-is-open" , open )
6633 navigationButton ?. setAttribute ( "aria-expanded" , String ( open ) )
0 commit comments