@@ -3,6 +3,7 @@ import {showGlobalErrorMessage} from '../bootstrap.ts';
33import { fomanticQuery } from '../modules/fomantic/base.ts' ;
44import { addDelegatedEventListener , queryElems } from '../utils/dom.ts' ;
55import { registerGlobalInitFunc , registerGlobalSelectorFunc } from '../modules/observer.ts' ;
6+ import { isDarkTheme } from '../utils.ts' ;
67import { initAvatarUploaderWithCropper } from './comp/Cropper.ts' ;
78import { initCompSearchRepoBox } from './comp/SearchRepoBox.ts' ;
89
@@ -45,10 +46,27 @@ function initFooterThemeSelector() {
4546 } ) ;
4647}
4748
49+ function initMarkdownDarkLightImages ( ) {
50+ // Mirror Gitea's current "darkness" into a dataset so markup/CSS can
51+ // switch `#gh-dark-mode-only` / `#gh-light-mode-only` images correctly
52+ // for both explicit themes and "auto" themes.
53+ const root = document . documentElement ;
54+ const sync = ( ) => {
55+ root . setAttribute ( 'data-gitea-theme' , isDarkTheme ( ) ? 'dark' : 'light' ) ;
56+ } ;
57+ sync ( ) ;
58+
59+ // Track system theme changes in case Gitea is set to "auto".
60+ const mql = window . matchMedia ( '(prefers-color-scheme: dark)' ) ;
61+ const onChange = ( ) => sync ( ) ;
62+ mql . addEventListener ( 'change' , onChange ) ;
63+ }
64+
4865export function initCommmPageComponents ( ) {
4966 initHeadNavbarContentToggle ( ) ;
5067 initFooterLanguageMenu ( ) ;
5168 initFooterThemeSelector ( ) ;
69+ initMarkdownDarkLightImages ( ) ;
5270}
5371
5472export function initGlobalDropdown ( ) {
0 commit comments