NyaaDarkModeEnhance

优化Nyaa的暗黑主题

Version vom 25.09.2022. Aktuellste Version

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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