PO18 Filter

Hide books in index search results based on specified keywords, authors, and tags.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo 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         PO18 Filter
// @description  Hide books in index search results based on specified keywords, authors, and tags.
// @version      1.0
// @author       null
// @match        https://www.po18.tw/findbooks/*
// @grant        none
// @license      MIT
// @namespace https://greasyfork.org/users/1272411
// ==/UserScript==

(function () {
  "use strict";

  const KEYWORDS = [
    /标题关键词1/i,
    /标题关键词2/i,
    /标题关键词3/i,
  ];
  const AUTHORS = [
    /作者关键词1/i,
    /作者关键词2/i,
    /作者关键词3/i,
  ];
  const TAGS = [
    /标签关键词1/i,
    /标签关键词2/i,
    /标签关键词3/i,
  ];

  function hideRowsByCriteria() {
    const rows = document.querySelectorAll(".row");
    rows.forEach((row) => {
      const textContent = row.textContent || row.innerText;
      const shouldHide =
        KEYWORDS.some((keyword) => keyword.test(textContent)) ||
        AUTHORS.some((author) => author.test(textContent)) ||
        TAGS.some((tag) => tag.test(textContent));

      if (shouldHide) {
        row.style.display = "none";
      }
    });
  }

  function observeDOMChanges() {
    const observer = new MutationObserver((mutations) => {
      mutations.forEach((mutation) => {
        if (mutation.addedNodes.length || mutation.removedNodes.length) {
          hideRowsByCriteria();
        }
      });
    });

    const config = { childList: true, subtree: true };
    const targetNode = document.querySelector("body");
    if (targetNode) {
      observer.observe(targetNode, config);
    } else {
      console.error("Failed to find the target node.");
    }
  }

  window.addEventListener("load", () => {
    hideRowsByCriteria();
    observeDOMChanges();
  });
})();