拉长B站合集列表

哔哩哔哩的推荐机制很差,但是很自信,所以我把合集列表高度拉长,把不相关的推荐视频挤到下面去。

// ==UserScript==
// @name         拉长B站合集列表
// @namespace    https://greasyfork.org/zh-CN/scripts/474447
// @version      0.4
// @description  哔哩哔哩的推荐机制很差,但是很自信,所以我把合集列表高度拉长,把不相关的推荐视频挤到下面去。
// @author       beibeibeibei
// @license      MIT
// @match        *.bilibili.com/video/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    let 最高合集列表高度 = 500;
    let 检测时间间隔 = 5000;

    let 外层容器 = document.querySelector("div.video-sections-content-list");
    let 中层容器 = document.querySelectorAll("div.video-section-title");
    let 所有子内容 = document.querySelectorAll("div.video-episode-card");

    let 外层容器2 = document.querySelector("div.cur-list");
    let 所有子内容2 = document.querySelectorAll("div.cur-list > ul > li");

    let timer = setInterval(function() {

        if (外层容器){
            let 待改高度 = parseFloat( window.getComputedStyle(外层容器 ,null).height );
            let 合集个数 = 所有子内容.length;
            let 中层容器个数 = 中层容器.length;
            if (合集个数 >= 4){
                let 单条高度 = parseFloat( window.getComputedStyle(所有子内容[0] ,null).height ) + parseFloat( window.getComputedStyle(所有子内容[0] ,null).marginBottom ) * 2;
                let 修正高度 = 合集个数 * 单条高度;
                if (修正高度 > 最高合集列表高度){
                    修正高度 = 最高合集列表高度;
                }

                let 修正高度2 = 0;
                if (中层容器个数 > 0){
                    let 单个中层容器高度 = parseFloat( window.getComputedStyle( 中层容器[0] ).height );
                    修正高度2 = 中层容器个数 * 单个中层容器高度;
                    if (修正高度2 > 最高合集列表高度){
                        修正高度2 = 最高合集列表高度;
                    }
                }

                修正高度 = 修正高度 > 修正高度2 ? 修正高度 : 修正高度2;

                if ( 待改高度 < 修正高度 ){
                    外层容器.style.maxHeight = 修正高度 + "px";
                    外层容器.style.height = 修正高度 + "px";
                }
            }
        }

        if (外层容器2){
            let 待改高度 = parseFloat( window.getComputedStyle(外层容器2 ,null).height );
            let 合集个数 = 所有子内容2.length;
            if (合集个数 >= 4){
                let 单条高度 = parseFloat( window.getComputedStyle(所有子内容2[0] ,null).height ) + parseFloat( window.getComputedStyle(所有子内容2[0] ,null).marginBottom );
                let 修正高度 = parseFloat( window.getComputedStyle(所有子内容2[0] ,null).marginTop ) + 合集个数 * 单条高度;
                if (修正高度 > 最高合集列表高度){
                    修正高度 = 最高合集列表高度;
                }

                if ( 待改高度 < 修正高度 ){
                    外层容器2.style.maxHeight = 修正高度 + "px";
                    外层容器2.style.height = 修正高度 + "px";
                }
            }
        }

    }, 检测时间间隔);
    // Your code here...
})();