Simple Search Filter

2024/3/29 07:06:40

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

Advertisement:

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

Advertisement:

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