Greasy Fork

Greasy Fork is available in English.

Novel Ranking Filter

Blur or hide disliked novels by author and tag on novel site's ranking page

目前为 2024-02-22 提交的版本,查看 最新版本

// ==UserScript==
// @name         Novel Ranking Filter
// @namespace    http://greasyfork.icu/en/users/1264733
// @version      2024-02-22
// @description  Blur or hide disliked novels by author and tag on novel site's ranking page
// @author       LE37
// @license      MIT
// @match        https://yomou.syosetu.com/rank/*
// @match        https://kakuyomu.jp/rankings/*
// @match        https://kakuyomu.jp/*recent_works
// @exclude      https://yomou.syosetu.com/rank/top/
// ==/UserScript==

(function() {
	'use strict';
	let a_re, a_lst, n_nc, n_ic, t_nc;
	// Settings Begin
	// Show disliked novel: 0 blur  1 hide
	const s_type = 0;
	switch (location.host) {
		// Narou
		case "yomou.syosetu.com":
			// Author id reg match
			a_re = /\d+/;
			// Disliked Author's ID liste, eg.
			a_lst = [
				// caviar https://mypage.syosetu.com/1/
				"1",
				// バセンジー https://mypage.syosetu.com/4649/
				"4649"
			];
			// Novel node class
			n_nc = "p-ranklist-item";
			// Novel intro class
			n_ic = "p-ranklist-item__synopsis";
			// Tag node class
			t_nc = "p-ranklist-item__keyword";
			break;
		// Kakuyomu
		case "kakuyomu.jp":
			// Author id reg match
			a_re = /users\/(.*)$/;
			// Disliked Author's ID liste, eg.
			a_lst = [
				// test1 https://kakuyomu.jp/users/test1
				"test1",
				// novel https://kakuyomu.jp/users/novel
				"novel"
			];
			// Novel node class
			n_nc = "widget-work";
			// Novel intro class
			n_ic = "widget-workCard-introduction";
			// Tag node class
			t_nc = "widget-workCard-tags";
			break;
	}
	// Disliked Tag liste for both sites, eg.
	const t_lst = [
		// https://yomou.syosetu.com/search.php?word=BL
		"BL",
		// https://kakuyomu.jp/tags/人外
		"人外"
	];
	// Settings End
	const no = document.getElementsByClassName(n_nc);
	let i = no.length;
	while (i--) {
		let dislike = false;
		const aid = no[i].getElementsByTagName("a")[1].href.match(a_re);
		if (a_lst.some(v => aid.includes(v))) {
			dislike = true;
		} else {
			const k_ele = no[i].getElementsByClassName(t_nc)[0];
			if (k_ele !== undefined) {
				const kwd = k_ele.getElementsByTagName("a");
				let k = kwd.length;
				while (k--) {
					const kdt = kwd[k].text;
					if (t_lst.some(v => kdt.includes(v))) {
						dislike = true;
						break;
					}
				}
			}
		}
		const ss = no[i].getElementsByClassName(n_ic)[0];
		if (dislike === true) {
			switch (s_type) {
				case 0:
					no[i].style.filter = "opacity(50%)";
					if (ss !== undefined) {
						ss.style.display = "none";
					}
					break;
				case 1:
					no[i].style.display = "none";
					break;
			}
		} else {
			// Novel isn't on any list
			//no[i].style.backgroundColor = "#0099FF";
			if (ss !== undefined) {
				ss.style.maxHeight = "120px";
				ss.style.overflow = "hidden";
			}
		}
	}
})();