]> git.joonet.de Git - adminer.git/commitdiff
AdminerDarkSwitcher: Handle first click
authorPexle Chris <pexlechris@gmail.com>
Sun, 27 Apr 2025 12:13:21 +0000 (15:13 +0300)
committerJakub Vrana <jakub@vrana.cz>
Sun, 4 May 2025 11:10:38 +0000 (13:10 +0200)
Fixed an issue where the Dark Mode Switcher icon did not respond on the first click if the Dark Mode cookie had not been set yet. Now, clicking the icon correctly sets the cookie and immediately toggles Dark Mode.

plugins/dark-switcher.php

index df3ef2ac53eed2464ca3db870d0f385c021a0d2c..10ea97f568be905747b1449e1dfca1573c79ed54 100644 (file)
@@ -28,6 +28,8 @@ const saved = document.cookie.match(/adminer_dark=(\d)/);
 if (saved) {
        adminerDark = +saved[1];
        adminerDarkSet();
+} else {
+       adminerDark = +matchMedia('(prefers-color-scheme: dark)').matches;
 }
 </script>
 <?php
@@ -35,7 +37,7 @@ if (saved) {
 
        function navigation($missing) {
                echo "<big style='position: fixed; bottom: .5em; right: .5em; cursor: pointer;'>☀</big>"
-                       . Adminer\script("if (adminerDark != null) adminerDarkSet(); qsl('big').onclick = adminerDarkSwitch;") . "\n"
+                       . Adminer\script("adminerDarkSet(); qsl('big').onclick = adminerDarkSwitch;") . "\n"
                ;
        }