Youtube no below 1K

Remove small view count video thumbs in the main page

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Youtube no below 1K
// @namespace    http://tampermonkey.net/
// @version      0.23
// @description  Remove small view count video thumbs in the main page
// @author       CosmicRice
// @license      MIT
// @match        https://www.youtube.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';
    const absoluteUrls = ['https://www.youtube.com', 'https://www.youtube.com/'];
    const partialUrls = ['https://www.youtube.com/watch?'];

    const removeSmallViews = () => {
        // Under 1K
        const allThumbnailMetadata = [...document.querySelectorAll('div#metadata-line > span.inline-metadata-item')];

        const viewMetadata = allThumbnailMetadata.filter((d) => d.textContent.includes(' views') && !d.textContent.includes('K') && !d.textContent.includes('M') && !d.textContent.includes('B'));
        const smallViewMetadata = viewMetadata.filter((d) => parseInt(d.textContent.replace(' views'), 10) < 1000 || d.textContent === 'No views' || d.textContent === '1 view');

        const smallViewYoutubeThumbEls = smallViewMetadata.map((el) => el.closest('ytd-rich-item-renderer') || el.closest('ytd-compact-video-renderer')).filter(el => el && el.style.display !== 'none');

        if (smallViewYoutubeThumbEls.length === 0) { return false; }
        smallViewYoutubeThumbEls.forEach((el) => { el.style.display = 'none' });
        return true;
    }

    const interval = setInterval(() => {
        // workaround for tampermonkey not catching youtube route change
        if (absoluteUrls.includes(window.location.href) || partialUrls.some(u => window.location.href.includes(u))) {
            removeSmallViews();
            return;
        }
    }, 1000);
})();