Browse Source

Fixed dark theme banner

pull/76/merge
Jure Šorn 1 week ago
parent
commit
98846e0e66
2 changed files with 16 additions and 4 deletions
  1. 10
      index.html
  2. 10
      parse.js

10
index.html

@ -64,7 +64,12 @@
</sup></p><p class="banner" style="margin-bottom: 20px; padding-bottom: 7px;"><img src="web/image_888.jpeg" alt="Monty Python"></p><script>
// Changes the banner image and link-to-theme if "theme=dark" is in query string
// or if browser prefers dark mode and theme is not explicitly set.
if ( (window.location.search.search(/[?&]theme=dark/) !== -1) || ((window.location.search.search(/[?&]theme=light/) == -1) && (window.matchMedia('(prefers-color-scheme: dark)').matches)) ) {
const theme_not_set_in_query = window.location.search.search(/[?&]theme=light/) == -1
const browser_prefers_dark = window.matchMedia('(prefers-color-scheme: dark)').matches;
if ((window.location.search.search(/[?&]theme=dark/) !== -1) ||
(theme_not_set_in_query && browser_prefers_dark)) {
activateDarkMode();
}
@ -78,7 +83,8 @@
img_dark.src = "web/image_orig_blue6.png";
img_dark.alt = "Monthy Python";
if ((window.location.search.search(/[?&]theme=dark2/) !== -1) ||
(window.location.search.search(/[?&]theme=dark3/) !== -1)) {
(window.location.search.search(/[?&]theme=dark3/) !== -1) ||
(theme_not_set_in_query && browser_prefers_dark)) {
img_dark.style = "width: 910px;";
} else {
img_dark.style = "width: 960px;";

10
parse.js

@ -738,7 +738,12 @@ const DARK_THEME_SCRIPT =
'<script>\n' +
' // Changes the banner image and link-to-theme if "theme=dark" is in query string\n' +
' // or if browser prefers dark mode and theme is not explicitly set.\n' +
' if ( (window.location.search.search(/[?&]theme=dark/) !== -1) || ((window.location.search.search(/[?&]theme=light/) == -1) && (window.matchMedia(\'(prefers-color-scheme: dark)\').matches)) ) {\n' +
'\n' +
'const theme_not_set_in_query = window.location.search.search(/[?&]theme=light/) == -1\n' +
'const browser_prefers_dark = window.matchMedia(\'(prefers-color-scheme: dark)\').matches;\n' +
'\n' +
' if ((window.location.search.search(/[?&]theme=dark/) !== -1) || \n' +
' (theme_not_set_in_query && browser_prefers_dark)) {\n' +
' activateDarkMode();\n' +
' }\n' +
'\n' +
@ -752,7 +757,8 @@ const DARK_THEME_SCRIPT =
' img_dark.src = "web/image_orig_blue6.png";\n' +
' img_dark.alt = "Monthy Python";\n' +
' if ((window.location.search.search(/[?&]theme=dark2/) !== -1) ||\n' +
' (window.location.search.search(/[?&]theme=dark3/) !== -1)) {\n' +
' (window.location.search.search(/[?&]theme=dark3/) !== -1) ||\n' +
' (theme_not_set_in_query && browser_prefers_dark)) {\n' +
' img_dark.style = "width: 910px;";\n' +
' } else {\n' +
' img_dark.style = "width: 960px;";\n' +

Loading…
Cancel
Save