Simple Search Filter

2024/3/29 07:06:40

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Advertisement:

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

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