Greasy Fork

Highlight Unread Novel

Add new color to novel which have more unread counts On Kakuyomu Narou Alphapolis Favorite Page

目前为 2024-03-22 提交的版本。查看 最新版本

// ==UserScript==
// @name           Highlight Unread Novel
// @name:ja        未読小説をハイライトする
// @namespace      https://greasyfork.org/en/users/1264733
// @version        2024-03-23
// @description    Add new color to novel which have more unread counts On Kakuyomu Narou Alphapolis Favorite Page
// @description:ja アルファポリス・カクヨム・なろうの気に入りページで、未読数が多い小説に色分けを追加する。
// @author         LE37
// @license        MIT
// @include        https://kakuyomu.jp/my/antenna/works
// @include        https://syosetu.com/favnovelmain/list/
// @include        https://www.alphapolis.co.jp/mypage/notification/index/110000*
// @grant          none
// ==/UserScript==

(()=>{
	'use strict';
	// Unread Number
	const urNum = 3;
	// Unread Color
	const urColor = "red";
	let oUnread, no;
	switch (location.host) {
		case "kakuyomu.jp":
			// Need to get count & resume
			oUnread = "div.widget-antennaList-itemInner";
			KY();
			break;
		case "syosetu.com":
			oUnread = "span.p-up-bookmark-item__unread-num";
			NR();
			break;
		case "www.alphapolis.co.jp":
			// Need to get alter
			oUnread = "div.content-main";
			AP();
			break;
	}
	function KY() {
		no = document.querySelectorAll(oUnread);
		for(let i = 0; i < no.length; i++) {
			const count = no[i].querySelector("li.widget-antennaList-unreadEpisodeCount");
			const resume = no[i].querySelector("a.widget-antennaList-continueReading").href;
			if (parseInt(count.textContent.match(/[0-9]+/)[0]) > urNum) {
				// Add direct link & urColor to count 
				count.innerHTML = '<a href="' + resume + '" style="color:' + urColor + ';">' + count.textContent + '</a>';
			}
		}
	}
	function NR() {
		no = document.querySelectorAll(oUnread);
		for(let i = 0; i < no.length; i++) {
			if (parseInt(no[i].textContent) > urNum) {
				no[i].parentElement.style.color = urColor;
			}
		}
	}
	function AP() {
		no = document.querySelectorAll(oUnread);
		for(let i = 0; i < no.length; i++) {
			const total = no[i].querySelector("a.total");
			const tn = parseInt(total.textContent.match(/[0-9]+/)[0]);
			const current = no[i].querySelector("a.disp-order");
			// New item dont have a readed mark yet
			const cn = current ? parseInt(current.textContent.match(/[0-9]+/)[0]) : 0;
			// Highlight new item's title instead
			const alter = current ? current : no[i].querySelector("h2.title a");
			if (tn - cn > urNum) {
				alter.style.color = urColor;
			}
		}
	}
})();