Simple Search Filter

2024/3/29 07:06:40

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

Advertisement:

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

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