PO18 Filter

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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();
  });
})();