// ==UserScript== // @name Novel Ranking Filter // @name:ja 小説ランキングフィルター // @namespace https://greasyfork.org/en/users/1264733 // @version 2024-03-19 // @description Alphapolis Hameln Kakuyomu Narou Ranking Page Filtering by AuthorID and Tag // @description:ja アルファポリス・ハーメルン・カクヨム・なろう 作者IDとタグによるランキングページの小説フィルタリング // @author LE37 // @license MIT // @include https://www.alphapolis.co.jp/novel/index* // @include https://www.alphapolis.co.jp/novel/ranking/* // @include https://kakuyomu.jp/rankings/* // @include https://kakuyomu.jp/*recent_works // @include https://syosetu.org/?mode=rank* // @include https://yomou.syosetu.com/rank/* // @exclude https://www.alphapolis.co.jp/novel/ranking/annual // @exclude https://yomou.syosetu.com/rank/top/ // @grant GM_setValue // @grant GM_getValue // @downloadURL none // ==/UserScript== (function() { 'use strict'; // a_k: AuthorListKey, a_l: AuthorLink, a_r: RegForAuthorID, n_n: NovelNode, t_n: Tag; let a_k, a_l, a_r, n_n, t_n; switch (location.host) { case "www.alphapolis.co.jp": a_k = "A"; a_l = "div.author>a:nth-child(1)"; a_r = /detail\/(\d+)$/; n_n = "div.section"; t_n = "li.tag a"; break; case "syosetu.org": a_k = "H"; a_l = "div.blo_title_sak a"; a_r = /user\/(\d+)/; n_n = "div.section3"; t_n = "div.all_keyword:nth-child(9) a"; break; case "kakuyomu.jp": a_k = "K"; a_l = "a.widget-workCard-authorLabel"; a_r = /users\/(.*)$/; n_n = "div.widget-work"; t_n = "a[itemprop='keywords']"; break; case "yomou.syosetu.com": a_k = "N"; a_l = "div.p-ranklist-item__author a"; a_r = /\/(\d+)/; n_n = "div.p-ranklist-item"; t_n = "div.p-ranklist-item__keyword a"; break; } // Default Css let dss = (`.nbg { background-color: #CCC; } .nbl { opacity: 36%; }.nhd { display: none; }.sbg { background-color: #09F; } .bna { position: fixed; top: 16%; left: 19%; width: 62%; height: 44px; z-index: 9999; } .bio { width: 44px; height: 44px; font-size: 200%; } #bmi { opacity: 50%; } #bta { background-color: #5CE; padding: 2%; } #bta:focus { color: lime; background-color: #222; } #bta, .bcd { visibility: hidden; }`); // gas: AutoSave [0 Off 1 On(Default)] let gas = GM_getValue("AS") === undefined ? 1 : GM_getValue("AS"); // gst: ShowType [0 Blur 1 Hide(Default)] let gst = GM_getValue("ST") === undefined ? 1 : GM_getValue("ST"); // gal: DislikedAuthorList let gal = GM_getValue(a_k) === undefined ? [] : GM_getValue(a_k); // gtl: DislikedTagList; let gtl = GM_getValue("TG") === undefined ? [] : GM_getValue("TG"); // css: Custom StyleSheet let css = GM_getValue("SS") === undefined ? dss : GM_getValue("SS"); const AC = (() => { const cs = document.createElement('style'); document.head.appendChild(cs); return (sS) => cs.textContent = sS; })(); AC(css); const no = document.querySelectorAll(n_n); // NormalMode NM(); function NM() { for (let i = 0; i < no.length; i++) { let d = CT(i); const al = no[i].querySelector(a_l); // No AuthorLink if (al === null) { d; } else { const ai = al.href.match(a_r)[1]; //console.log(ai); if (gal.some((v) => ai === v)) { al.classList.add("nbg"); DN(i); continue; } al.classList.remove("nbg"); d; } if (d) { DN(i); } else { no[i].classList.remove("nbl"); no[i].classList.remove("nhd"); } } } function CT(i) { const kl = no[i].querySelectorAll(t_n); // No Tag if (kl === null) { return false; } for (let k = 0; k < kl.length; k++) { const kd = kl[k]; //console.log(kd); if (gtl.some((v) => kd.text === v)) { kd.classList.add("nbg"); return true; } kd.classList.remove("nbg"); } return false; } function DN(i) { switch (gst) { case 0: no[i].classList.add("nbl"); no[i].classList.remove("nhd"); break; case 1: no[i].classList.remove("nbl"); no[i].classList.add("nhd"); break; } } // SelectMode: 0 Off 1 On let s_m = 0; const AE = (() => { const es = document.createElement('style'); document.head.appendChild(es); return (sS) => es.textContent = sS; })(); function SM() { //console.log(a_k + ": " + gal); //console.log("TG: " + gtl); let ess; if (s_m === 0) { s_m = 1; // Disable default click document.addEventListener("click", UH, true); ess = a_l + ", " + t_n + "{ border: thin solid #00F; }"; } else { s_m = 0; // Restore default click document.removeEventListener("click", UH, true); // Clear remain selected elements's background color const tno = document.getElementsByClassName("sbg"); for (let l = 0; l < tno.length; l++) { tno[l].classList.remove("sbg"); } ess = a_l + ", " + t_n + " { border: none; }"; } AE(ess); } // UpdateHandler function UH(e) { if (e.target.matches(a_l)) { const ai = e.target.href.match(a_r)[1]; UT(e, ai, gal); if (gas === 1) { GM_setValue(a_k, gal); } bta.innerText = gal; } else if (e.target.closest(t_n)) { const kd = e.target.textContent; UT(e, kd, gtl); if (gas === 1) { GM_setValue("TG", gtl); } bta.innerText = gtl; } NM(); return false; } // UpdateTemp function UT(e, s, l) { e.preventDefault(); e.target.classList.add("sbg"); const li = l.findIndex((v) => v === s); if (li !== -1) { l.splice(li,1); e.target.classList.remove("sbg"); } else { l.push(s); } return l; } // CustomMenu const bba = document.createElement("div"); bba.innerHTML = ''; document.body.appendChild(bba); const bta = document.getElementById("bta"); const bmi = document.getElementById("bmi"); bmi.addEventListener("click", CM, true); function CM() { bta.innerText = a_k; const bc = document.getElementsByClassName("bcd"); let bf; for (let j = 0; j < bc.length; j++) { switch (bc[j].id) { case "bst": bf = ST; break; case "bsm": bf = SM; break; case "bos": bf = OS; break; case "bta": bf = null; break; } if (bc[j].style.visibility !== "visible") { bc[j].style.visibility = "visible"; bc[j].addEventListener("click", bf, true); } else { bc[j].style.visibility = "hidden"; bc[j].removeEventListener("click", bf, true); } } } // ShowType function ST() { if (gst === 0) { gst = 1; } else { gst = 0; } if (gas === 1) { GM_setValue("ST", gst); } bta.innerText = gst; NM(); } // OptionSave function OS() { if (!bta.innerText.startsWith('SA')) { bta.innerText = 'SAVE=' + gas + '\r\nSHOW=' + gst + '\r\nAIDS=' + gal + '\r\nTAGS=' + gtl + '\r\nUCSS=' + css; } else { try { const tc = bta.innerText.split('\n', 5); const tas = tc[0].slice(5); const tst = tc[1].slice(5); const tal = tc[2].slice(5); const ttl = tc[3].slice(5); const tus = tc[4].slice(5); gas = tas === NaN || tas === '' ? 0 : parseInt(tas); gst = tst === NaN || tst === '' ? 0 : parseInt(tst); gal = tal === null || tal === '' ? [] : tal.split(','); gtl = ttl === null || ttl === '' ? [] : ttl.split(','); css = tus === null || tus === '' ? dss : tus; GM_setValue("AS", gas); GM_setValue("ST", gst); GM_setValue(a_k, gal); GM_setValue("TG", gtl); GM_setValue("SS", css); bta.innerText = '✔'; AC(css); NM(); } catch (error) { //console.error(error.message); bta.innerText = '❌'; } } } })();