File: dark-switcher.php

package info (click to toggle)
adminer 5.4.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,828 kB
  • sloc: php: 28,768; javascript: 1,188; xml: 107; makefile: 48; sh: 3
file content (54 lines) | stat: -rw-r--r-- 1,683 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?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 extends Adminer\Plugin {

	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();
} else {
	adminerDark = +matchMedia('(prefers-color-scheme: dark)').matches;
}
</script>
<?php
	}

	function navigation($missing) {
		echo "<big style='position: fixed; bottom: .5em; right: .5em; cursor: pointer;'>☀</big>"
			. Adminer\script("adminerDarkSet(); qsl('big').onclick = adminerDarkSwitch;") . "\n"
		;
	}

	function screenshot() {
		return "https://www.adminer.org/static/plugins/dark-switcher.gif";
	}

	protected $translations = array(
		'cs' => array('' => 'Dovoluje přepínání světlého a tmavého vzhledu'),
		'de' => array('' => 'Umschalten zwischen hellem und dunklem Design erlauben'),
		'ja' => array('' => 'ダークモードへの切替え'),
		'pl' => array('' => 'Zezwalaj na przełączanie trybu jasnego i ciemnego'),
	);
}