NyaaDarkModeEnhance

优化Nyaa的暗黑主题

Versione datata 25/09/2022. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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