]> git.joonet.de Git - adminer.git/commitdiff
New plugin: Allow switching light and dark mode (fix #926)
authorJakub Vrana <jakub@vrana.cz>
Wed, 19 Mar 2025 19:20:43 +0000 (20:20 +0100)
committerJakub Vrana <jakub@vrana.cz>
Wed, 19 Mar 2025 19:20:43 +0000 (20:20 +0100)
CHANGELOG.md
plugins/dark-switcher.php [new file with mode: 0644]

index 707d1379e4b907f0b27369f20622a5d2eeadca6d..a994800fe007abab1c2995dd957a1598c8c5928e 100644 (file)
@@ -9,6 +9,7 @@
 - Plugins: autoload plugins from adminer-plugins/
 - Plugins: configure plugins with adminer-plugins.php
 - Plugins: Display loaded plugins in server overview
+- New plugin: Allow switching light and dark mode (bug #926)
 
 ## Adminer 5.0.6 (released 2025-03-17)
 - Align numbers right (bug #912)
diff --git a/plugins/dark-switcher.php b/plugins/dark-switcher.php
new file mode 100644 (file)
index 0000000..2d7e41e
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+
+/** Allow switching light and dark mode
+* @link https://www.adminer.org/plugins/#use
+* @author Jakub Vrana, https://www.vrana.cz/
+* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
+*/
+class AdminerDarkSwitcher {
+
+       function head($dark = null) {
+               ?>
+<script <?php echo Adminer\nonce(); ?>>
+let adminerDark;
+
+function adminerDarkSwitch() {
+       adminerDark = !adminerDark;
+       adminerDarkSet();
+}
+
+function adminerDarkSet() {
+       qsa('link[href$="dark.css"]').forEach(link => link.media = (adminerDark ? '' : 'never'));
+       qs('meta[name="color-scheme"]').content = (adminerDark ? 'dark' : 'light');
+       cookie('adminer_dark=' + (adminerDark ? 1 : 0), 30);
+}
+
+const saved = document.cookie.match(/adminer_dark=(\d)/);
+if (saved) {
+       adminerDark = +saved[1];
+       adminerDarkSet();
+}
+</script>
+<?php
+       }
+
+       function navigation($missing) {
+               echo "<label style='position: fixed; bottom: .5em; right: .5em;'><input type='checkbox'> dark</label>"
+                       . Adminer\script("if (adminerDark != null) adminerDarkSet(); mixin(qsl('input'), {onclick: adminerDarkSwitch, checked: adminerDark});") . "\n"
+               ;
+       }
+}