Simple Search Filter

2024/3/29 07:06:40

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        Simple Search Filter
// @namespace   Violentmonkey Scripts
// @match       https://search.bilibili.com/*
// @grant       none
// @version     1.0
// @author      anonfruit
// @license MIT
// @description 2024/3/29 07:06:40
// ==/UserScript==

// TODO: Add input fields to set thresholds
const ARTICLE_LIKE_COUNT_THRESHOLD = 20;
const VIDEO_PLAY_COUNT_THRESHOLD = 1000;

// TODO: Use MutationObserver to detect changes
setInterval(function () {
  if (!location.search.includes("order=pubdate")) {
    return;
  }
  const infoList = document.querySelectorAll(".atc-info");
  const likeRegex = /(\d+)点赞/;
  for (const info of infoList) {
    const text = info.innerText;
    const match = likeRegex.exec(text);
    if (match) {
      const likeCount = parseInt(match[1]);
      if (likeCount < ARTICLE_LIKE_COUNT_THRESHOLD) {
        const item = info.parentElement.parentElement;
        item.classList.add("userscript-bilibili-filter-unimportant");
      }
    }
  }
}, 1000);

setInterval(function () {
  if (!location.search.includes("order=pubdate")) {
    return;
  }
  const statsList = document.querySelectorAll(".bili-video-card__stats--left");
  for (const stats of statsList) {
    const playCountText = stats.querySelector(".bili-video-card__stats--item").innerText.trim();
    if (!playCountText.match(/^\d+$/)) {
      continue;
    }
    const playCount = parseInt(playCountText);
    if (playCount < VIDEO_PLAY_COUNT_THRESHOLD) {
      let parent = stats.parentElement;
      while (parent && !parent.classList.contains("video-list-item")) {
        parent = parent.parentElement;
      }
      if (parent) {
        parent.classList.add("userscript-bilibili-filter-unimportant");
      }
    }
  }
}, 1000);



const style = document.createElement("style");
style.innerText = `
.userscript-bilibili-filter-unimportant {
  filter: opacity(0.3);
}
.userscript-bilibili-filter-unimportant:hover {
  filter: none;
}
`;
document.head.appendChild(style);