Greasy Fork is available in English.

B站♥首页视频标记

用播放量和弹幕数做统计,标记互动比例低于1500,和互动比例高于200的的视频。

// ==UserScript==
// @name         B站♥首页视频标记
// @namespace    http://tampermonkey.net/
// @version      0.7.1
// @description  用播放量和弹幕数做统计,标记互动比例低于1500,和互动比例高于200的的视频。
// @author       Zola
// @match        *://www.bilibili.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to convert view count to a number
    function convertViewCount(viewCount) {
        if (viewCount.includes('万')) {
            return parseFloat(viewCount.replace('万', '')) * 10000;
        } else if (viewCount.includes('亿')) {
            return parseFloat(viewCount.replace('亿', '')) * 100000000;
        } else {
            return parseInt(viewCount.replace(/[^0-9]/g, ''), 10);
        }
    }

    // Function to highlight divs based on the ratio of views to comments
    function highlightDivs() {
        const divs = document.querySelectorAll('div.bili-video-card__mask');
        divs.forEach(div => {
            // Skip if the div is inside a floor-single-card
            if (div.closest('.floor-single-card')) {
                return;
            }

            const statsItems = div.querySelectorAll('.bili-video-card__stats--item');

            if (statsItems.length >= 2) {
                const views = convertViewCount(statsItems[0].innerText);
                let comments = parseInt(statsItems[1].innerText.replace(/[^0-9]/g, ''), 10);

                // If comments are zero, set it to 1 to avoid division by zero
                if (comments === 0) {
                    comments = 1;
                }

                const ratio = views / comments;

                if (ratio > 1500) {
                    div.style.border = '10px solid #fcc6cf';
                } else if (ratio < 200) {
                    div.style.border = '10px solid #b8ddf3';
                } else {
                    div.style.border = ''; // No border if the ratio is in between
                }
            }
        });
    }

    // Run the function when the page loads
    window.addEventListener('load', highlightDivs);

    // Optional: Run the function when the DOM is updated (e.g., for infinite scrolling)
    const observer = new MutationObserver(highlightDivs);
    observer.observe(document.body, { childList: true, subtree: true });
})();