NyaaDarkModeEnhance

优化Nyaa的暗黑主题

25.09.2022 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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