File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ // ==UserScript==
2
+ // @name Dark Mode
3
+ // @name :zh-CN 暗黑模式
4
+ // @namespace https://github.com/smxl
5
+ // @home https://github.com/smxl
6
+ // @version 1.0.0
7
+ // @description :zh-CN 自动在没有暗黑主题的网站增加暗黑模式, 需要手动增加目标网站到 match
8
+ // @author smxl
9
+ // @license MIT
10
+ // @description Automatically add dark mode to websites that do not have it by default. Please add your target site in match
11
+ // @match *://yandex.*/*
12
+ // ==/UserScript==
13
+
14
+ ( function ( ) {
15
+ 'use strict' ;
16
+
17
+ // Check if prefers-color-scheme: dark is supported by the browser
18
+ if ( window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ) {
19
+ // Check if the website already has a color scheme defined
20
+ const html = document . getElementsByTagName ( 'html' ) [ 0 ] ;
21
+ const colorScheme = html . getAttribute ( 'data-color-scheme' ) ;
22
+ if ( colorScheme && ( colorScheme === 'light' || colorScheme === 'dark' ) ) {
23
+ return ;
24
+ }
25
+
26
+ // Add dark mode
27
+ const darkModeCSS = document . createElement ( 'style' ) ;
28
+ darkModeCSS . type = 'text/css' ;
29
+ darkModeCSS . innerHTML = ' body,#b_results>li {background-color: #222 !important;color: #eee !important;}a {color: #9cf !important;}' ;
30
+ html . setAttribute ( 'data-color-scheme' , 'dark' ) ;
31
+ document . head . appendChild ( darkModeCSS ) ;
32
+ }
33
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments