Skip to content

Commit 67ae279

Browse files
authored
Create dark.user.js
1 parent 6fa9d3a commit 67ae279

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

dark.user.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
})();

0 commit comments

Comments
 (0)