Hide low viewcount vids

Hides low view count recommended videos on YouTube

La data de 28-10-2024. Vezi ultima versiune.

// ==UserScript==
// @name        Hide low viewcount vids
// @description Hides low view count recommended videos on YouTube
// @match       https://www.youtube.com/*
// @version     1.1
// @author      Laku
// @namespace https://greasyfork.org/users/1387751
// ==/UserScript==

const threshold = 100;

function hide(v) {
  const e = v.querySelector('span.inline-metadata-item.style-scope.ytd-video-meta-block');
  if(e) {
    const cap = /(?:No|(\d+\.?\d{0,2})([KMB])?) views?/.exec(e.textContent);
    const count = parseFloat(cap[1]??0) * (({K:1e3,M:1e6,B:1e9})[cap[2]]??1);
    if(count < threshold) {
      v.style.display = "none";
    }
  }
}

function check(changes, observer) {
  changes.forEach((c)=>{
    const path = window.location.pathname;
    const id = c.target.id;
    if(path == "/" && id == "contents") {
      c.addedNodes.forEach((v) => hide(v));
    } else if(path.includes("watch") && (id == "items" || id == "contents")) {
      c.addedNodes.forEach((v) => {if(v.nodeName == "YTD-COMPACT-VIDEO-RENDERER") hide(v);});
    }
  })
}

(new MutationObserver(check)).observe(document, {childList: true, subtree: true});