NyaaDarkModeEnhance

优化Nyaa的暗黑主题

Stan na 25-09-2022. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         NyaaDarkModeEnhance
// @namespace    https://nyaa.si
// @version      0.1
// @description  优化Nyaa的暗黑主题
// @author       Telegram@GJKen
// @match        https://*.nyaa.si/*
// @icon         https://i.altapps.net/icons/nyaa-v2-ec0e0.png
// @grant        none
// @license      MIT
// ==/UserScript==

(function(){
	// 提前设置需要添加的标签
	let liTag = document.createElement('li');
	let liTagA = document.createElement('a');
	// 计算有多少个UL标签
	let ULCount = document.querySelector("#navbar > ul:nth-child(1)").children.length;
	var body = document.body.classList;
	(function CheckBody(){
		// 判断body是否有'darkMode'class类, 默认dark模式下修改颜色
		if(body.contains('dark')){ChangeColor()}
	})();
	function AddToggleBtn(){
		document.querySelector("#navbar > ul:nth-child(1)").appendChild(liTag)
		document.querySelector("#navbar > ul:nth-child(1)").children[ULCount].appendChild(liTagA)
		liTagA.href = '#'
		liTagA.innerText = 'DarkMode'
	};
	AddToggleBtn();
    document.querySelector("#navbar > ul:nth-child(1)").children[ULCount].addEventListener('click', function(){
		// 给按钮添加监听事件 | 判断body是否有'darkMode'class类
		if(body.contains('dark')){
			body.remove('dark')
			toggleDarkMode()
			// 恢复文字颜色函数
			let tbodyChild = document.querySelector("body > div.container > div.table-responsive > table > tbody").children;
			for(let i = 0; i < tbodyChild.length; i++){
				var x = tbodyChild[i].children[1].children;
				if(x[1]===undefined){
					// 无 comment 的情况
					x[0].removeAttribute('style');
				}else{
					x[1].removeAttribute('style');
				}
			}
		}else{
			body.add('dark')
			toggleDarkMode()
			ChangeColor()
		}
	});
})();

function ChangeColor(){
	// 修改文字颜色函数
	let tbodyChild = document.querySelector("body > div.container > div.table-responsive > table > tbody").children;
	for(let i = 0; i < tbodyChild.length; i++){
		let x = tbodyChild[i].children[1].children;
		if(x[1]===undefined){
			// 无 comment 的情况
			x[0].style.color='#cbcbcb';
		}else{
			x[1].style.color='#cbcbcb';
		}
    }
};