B站视频页 - 视频合集样式

修改新版视频页的视频合集样式

当前为 2024-10-21 提交的版本,查看 最新版本

// ==UserScript==
// @name         B站视频页 - 视频合集样式
// @namespace    mscststs
// @version      0.4
// @license      ISC
// @description  修改新版视频页的视频合集样式
// @author       mscststs
// @match        https://www.bilibili.com/video/*
// @icon         https://www.bilibili.com/favicon.ico
// @require      https://gf.qytechs.cn/scripts/38220-mscststs-tools/code/MSCSTSTS-TOOLS.js?version=713767
// @run-at       document-body
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    StartVideoCollection();
    async function StartVideoCollection(){
        await mscststs.wait(".video-pod .video-pod__header .header-top .left .title");
        var article = document.querySelector("body");

        async function setVideoCollection() {

            var leftTitle = document.querySelector(".video-pod .video-pod__header .header-top .left .title");
            leftTitle.style.cssText += "font-size:16px!important; line-height:20px!important;";
            var videoPod = document.querySelector(".video-pod .video-pod__body");
            //alert(document.querySelectorAll(".simple-base-item.normal .title .title-txt")[0].innerHTML);

            var collectionMaxHeight = "205px";
            var videoMaxHeight = "348px";
            if(leftTitle.innerHTML != "视频选集" && videoPod.style.maxHeight != collectionMaxHeight){
                videoPod.style.cssText += "max-height:"+collectionMaxHeight+"!important;";
                //alert(0);
                let normals = document.querySelectorAll(".simple-base-item.normal");

                //let fontCSS = "font-size:14px; font-family:PingFang SC,HarmonyOS_Regular,Helvetica Neue,Microsoft YaHei,sans-serif;";
                let fontCSS = "font-size:14px; line-height:30px;";
                for(let i = 0; i < normals.length; i++) {
                    normals[i].style.margin = "5px 0";
                    normals[i].querySelector(".title").style.cssText += "height: 30px;";
                    normals[i].querySelector(".title .title-txt").style.cssText += fontCSS;
                    normals[i].querySelector(".stats").style.cssText += fontCSS;
                }

            } else if(leftTitle.innerHTML == "视频选集" && document.querySelectorAll(".simple-base-item.normal .title .title-txt")[0].innerHTML.search(/^P\d&nbsp;+/) == -1) {
                //alert(document.querySelectorAll(".simple-base-item.normal .title .title-num")[0]);
                videoPod.style.cssText += "max-height:"+videoMaxHeight+"!important;";
                let normals = document.querySelectorAll(".simple-base-item.normal");

                let fontCSS = "font-size:13.5px; line-height:30px;";
                for(let i = 0; i < normals.length; i++) {
                    normals[i].style.margin = "5px 0";
                    normals[i].querySelector(".title").style.cssText += "height: 30px;";
                    normals[i].querySelector(".title .title-txt").style.cssText += fontCSS;
                    normals[i].querySelector(".stats").style.cssText += fontCSS;

                    //normals[i].querySelector(".title .title-txt").insertAdjacentHTML("beforebegin", "<div class='title-num' style='"+fontCSS+" margin-right:10px;'>P"+(i+1)+"</div>");
                    normals[i].querySelector(".title .title-txt").innerHTML = "P"+(i+1)+"&nbsp;&nbsp;&nbsp;"+normals[i].querySelector(".title .title-txt").innerHTML;
                }
            }

        }

        var options = { 'childList': true, 'attributes':true };
        const callback = function(mutationsList, observer) {
            setVideoCollection();
        };
        const observer = new MutationObserver(callback);
        observer.observe(article, options);
        setVideoCollection();
        var time = 500;
        for(var i = 0; i < 20; i++) {
            setTimeout(function() {
                setVideoCollection();
                //alert(123);
            }, time);
            time += 500;
        }

    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址