Greasy Fork

Greasy Fork is available in English.

B站视频详情页优化

调整B站网页版视频详情页右侧的合集列表,使得可以根据窗口大小上下铺满;去除两处广告;去除页面右侧底部的直播banner位

当前为 2024-03-24 提交的版本,查看 最新版本

// ==UserScript==
// @name         B站视频详情页优化
// @license      MIT
// @namespace    https://sumver.cn
// @version      1.0.1
// @description  调整B站网页版视频详情页右侧的合集列表,使得可以根据窗口大小上下铺满;去除两处广告;去除页面右侧底部的直播banner位
// @author       lonelylizard
// @match        https://www.bilibili.com/video/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';
    // 去除右侧广告
    GM_addStyle(`#slide_ad{display:none`);
    GM_addStyle(`.ad-report[data-v-e79faaca] {display:none !important;min-width:0px !important;min-height:0px !important}`);
    // 去除简介下广告
    GM_addStyle(`#activity_vote{display:none !important}`);
    // 去除右下角直播窗口
    GM_addStyle(`.pop-live-small-mode{display:none !important}`);
    // 去除右侧游戏广告卡片
    GM_addStyle(`.video-page-game-card-small{display:none !important}`);

    // 第一次进入页面时,调整右侧视频合集列表
    if(document.querySelector(".base-video-sections-v1")){
    let res_height = window.innerHeight;
    var right_content_top_heigt = document.querySelector(".base-video-sections-v1").offsetHeight;
    var dif_height = res_height - right_content_top_heigt - 100;
    //GM_addStyle(`.video-sections-content-list{height: ${dif_height}px !important;max-height:1000px !important}`);

    // 计算列表高度,如果达不到一屏就不铺满
    var list_height = document.querySelector(".video-section-list").scrollHeight;
    console.log(list_height);
    if(list_height > dif_height){
        GM_addStyle(`.video-sections-content-list{height: ${dif_height}px !important;max-height:1000px !important}`)
    }else{
        let temp_height = list_height + 10
        GM_addStyle(`.video-sections-content-list{height: ${temp_height}px !important;max-height:1000px !important}`)
    }


    // 窗口大小变化时调整合集列表大小
    const getWindowInfo = () => {
        let hight = window.innerHeight
        // console.log("监听到窗口变化");
        // let right_content_top_heigt = document.querySelector(".base-video-sections-v1").offsetHeight;
        // console.log("距离顶部的高度:"+right_content_top_heigt);
        let dif_height2 = hight - right_content_top_heigt - 100;
        let temp_heigt2 = list_height + 10;
        // 计算列表高度,如果达不到一屏就不铺满
        if(list_height > dif_height2){
            GM_addStyle(`.video-sections-content-list{height: ${dif_height2}px !important;max-height:1000px !important}`);
        }else{
            // console.log("现在的高度差为:"+dif_height2);
            GM_addStyle(`.video-sections-content-list{height: ${temp_heigt2}px !important;max-height:1000px !important}`);
        }
    };

    const debounce = (fn, delay) => {
        let timer;
        return function() {
            if (timer) {
                clearTimeout(timer);
            }
            timer = setTimeout(() => {
                fn();
            }, delay);
        }
    };
    const cancalDebounce = debounce(getWindowInfo, 500);

    window.addEventListener('resize', cancalDebounce);
    }
})();