NyaaDarkModeEnhance

优化Nyaa的暗黑主题

As of 25.09.2022. See апошняя версія.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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';
		}
    }
};