Greasy Fork

Greasy Fork is available in English.

Novel Ranking Filtering

Filtering ranking novels by author and tag on syosetu.com and kakuyomu.jp

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

// ==UserScript==
// @name         Novel Ranking Filtering
// @namespace    SyosetuKakuyomuRankingFilter
// @version      2024-02-21
// @description  Filtering ranking novels by author and tag on syosetu.com and kakuyomu.jp
// @author       LE37
// @license     MIT; https://opensource.org/licenses/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_lst, n_nc, a_re, k_nc;
	switch (location.host) {
		case "yomou.syosetu.com":
			a_lst = [
				//Filtering by authorID:
				//https://mypage.syosetu.com/1/
				"1",
				//https://mypage.syosetu.com/4649/
				"4649"
			];
			n_nc = "p-ranklist-item";
			a_re = /\d+/;
			k_nc = "p-ranklist-item__keyword";
			break;
		case "kakuyomu.jp":
			a_lst = [
				//Filtering by authorID:
				//https://kakuyomu.jp/users/test1
				"test1",
				//https://kakuyomu.jp/users/novel
				"novel"
			];
			n_nc = "widget-work";
			a_re = /users\/(.*)$/;
			k_nc = "widget-workCard-tags";
			break;
	}
	const t_lst = [
		//Filtering by tagName:
		//https://kakuyomu.jp/tags/BL
		"BL",
		//https://kakuyomu.jp/tags/人外
		"人外"
	];
	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(k_nc)[0];
			if (k_ele === undefined) {
				//notag
			} else {
				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;
					}
				}
			}
		}
		if (dislike === true) {
			no[i].style.filter = "opacity(50%)";
			//hide
			//no[i].style.display = "none";
			//or use uBlock0's custom filter, eg.
			//yomou.syosetu.com#?#.p-ranklist-item:-abp-has(a[href$="/4649/"])
			//kakuyomu.jp#?#.widget-work:-abp-has(a.widget-workCard-authorLabel[href$="/test1"])
			//yomou.syosetu.com#?#.p-ranklist-item:-abp-has(>.p-ranklist-item__column>.p-ranklist-item__detail>.p-ranklist-item__keyword>a:-abp-contains(/BL|人外/))
			//kakuyomu.jp#?#.widget-work:-abp-has(>div.float-left>div.widget-workCard-data>p.widget-workCard-summary>span>a:-abp-contains(/BL|人外/))
		} else {
			//no[i].style.backgroundColor = "#0099FF";
		}
	}
})();