Greasy Fork is available in English.

哔哩哔哩(b站)播放页美化

播放页显示UID和注册时间,显示屏蔽设定和高级弹幕选项

// ==UserScript==
// @name         哔哩哔哩(b站)播放页美化
// @namespace    http://tampermonkey.net/
// @version      0.4.3.4
// @description  播放页显示UID和注册时间,显示屏蔽设定和高级弹幕选项
// @author       AN drew
// @match        https://www.bilibili.com/video/*
// @match        https://www.bilibili.com/bangumi/*
// @match        https://www.bilibili.com/cinema/*
// @match        https://www.bilibili.com/documentary/*
// @match        https://www.bilibili.com/tv/*
// @match        https://www.bilibili.com/variety/*
// @match        https://member.bilibili.com/*
// @require      https://lib.baomitu.com/jquery/3.6.3/jquery.min.js
// @require      https://lib.baomitu.com/jquery-cookie/1.4.1/jquery.cookie.min.js
// @grant        GM_setClipboard
// ==/UserScript==

var openbarrage=0;

function v()
{

    var uid = $.cookie("DedeUserID")
    if($.cookie('registration_id')==undefined)
        $.cookie('registration_id', uid, { expires: 365, path: "/", domain: "bilibili.com" });

    if(window.location.href.indexOf("https://member.bilibili.com/x2/creative/h5/calendar/event?ts=0") > -1) //注册信息
    {
        var timer = setInterval(function(){
            if($("pre").length>0)
            {
                var str =$("pre").html()
                var json=JSON.parse(str);
                var unix =json['data']['pfs']['profile']['jointime']

                var theday=new Date(unix*1000);
                var ly = parseInt(theday.getFullYear());
                var lm = parseInt(1+theday.getMonth());
                var ld = parseInt(theday.getDate());
                clearInterval(timer)

                if($.cookie('registration_days')==undefined || $.cookie('registration_id')!=uid)
                {
                    $.cookie('registration_days', ly+"-"+lm+"-"+ld, { expires: 365, path: "/", domain: "bilibili.com" });
                    $.cookie('registration_id', uid, { expires: 365, path: "/", domain: "bilibili.com" });
                }
            }
        },100)
        }
    else if(window.location.href.indexOf("bangumi") > -1) //番剧
    {
        var t0 = setInterval(function(){
            if($(".coin-info").length > 0)
            {
                var coininfo = $(".coin-info").find("span").text()
                if(coininfo != "--")
                {
                    $(".coin-info").find("span").attr("style","width:85px")
                    $(".coin-info").find("span").text("投币 "+coininfo)
                    $(".coin-info").attr("style","margin-right:20px")
                    clearInterval(t0)
                }
            }
        },100)
        }

    var u ='<span><span id="uid">&nbsp;UID:&nbsp;</span><span id="id">xxx&nbsp;</span></span>'
    var $uid =$(u)
    $uid.css({"background":"#7CD4F2",
              "color":"white",
              "font-size":"10px",
              "margin-right":"30px",
              "padding":"1px 1px 1px 1px",
              "width": "28px",
              "height": "14px"})
    var t ='<span><span id="registration-time"><a href="https://member.bilibili.com/x2/creative/h5/calendar/event?ts=0" target="_blank" style="color:#00A1D6;text-decoration: underline">查看注册天数</a></span><span id="time"></span></span>'
    var $time=$(t)
    $time.css({"font-size":"10px",
               "margin-left":"20px",
               "padding":"1px 1px 1px 1px",
               "width": "56px",
               "height": "14px"})

    var t2 ='<span><span id="registration-time">&nbsp;注册时间:&nbsp;</span><span id="time">xxxx-xx-xx</span></span>'
    var $time2=$(t2)
    $time2.css({"background":"#6DC781",
                "color":"white",
                "font-size":"10px",
                "margin-left":"20px",
                "padding":"1px 1px 1px 1px",
                "width": "56px",
                "height": "14px"})

    setInterval(function(){

        if($('.bili-header .header-avatar-wrap').length > 0 && $('.bili-avatar').length > 0) //新版avatar
        {
            $('.bili-avatar').hover(function () {
                if ($('.myinfo').length == 0) {
                    var $div = $('.coins-item').clone(true);
                    $div.empty();
                    $div.attr('class', 'myinfo');
                    $div.css({ 'vertical-align': 'top', 'margin': '5px 0px 5px 0px' });
                    $div.append($uid);
                    let $time22=$time2.clone();
                    $time22.css('margin-left','5px');
                    if ($.cookie('registration_days') != null && $.cookie('registration_id') == uid) {
                        $div.append($time22);
                        $('.coins-item').before($div);
                        $('#time').text($.cookie('registration_days') + '\u00a0');
                    }
                    else {
                        $div.append($time);
                        $('.coins-item').before($div);
                    }
                    if (uid != undefined) { $('#id').text(uid + ' '); }
                }
            });
        }
        else
        {
            if($(".mini-avatar").length>0)
            {
                $(".mini-avatar").hover(function(){
                    if($(".myinfo").length==0)
                    {
                        var $div = $(".coins").clone(true)
                        $div.empty()
                        $div.attr("class","myinfo")
                        $div.css({"vertical-align":"top","margin-top":"5px"})
                        $div.append($uid)
                        if($.cookie("registration_days")!=undefined && $.cookie('registration_id')==uid)
                        {
                            $div.append($time2)
                            $(".level-content").before($div)
                            $("#time").text($.cookie("registration_days")+'\u00a0')
                        }
                        else
                        {
                            $div.append($time)
                            $(".level-content").before($div)
                        }
                        if(uid!=undefined)
                            $("#id").text(uid+" ")
                    }
                })
            }
        }
    },1000)

    var table = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF';
    var tr = {};
    for (var i = 0; i < 58; ++i) {
        tr[table[i]] = i;
    }

    var s = [11,10,3,8,4,6];
    var xor = 177451812;
    var add = 8728348608;


    //AV、BV互转方法来自知乎:https://www.zhihu.com/question/381784377/answer/1099438784

    function dec(x)
    {
        let r = 0;
        for (var i = 0; i < 6; i++)
        {
            r += tr[x[s[i]]] * (58 ** i);
        }
        let aid=(r - add) ^ xor;
        if(aid < 0)
        {
            aid += 2147483648;
        }
        return 'av' + aid;
    }
    function enc(x)
    {
        if(x.length>=10)
        {
            x-=2147483648;
        }
        x=(x^xor)+add;
        let r=['B','V',1, , ,4, ,1, ,7, , ];
        for (var i = 0; i < 6; i++)
        {
            r[s[i]]=table[parseInt(x/58**i)%58];
        }
        return r.join("");
    }

    setInterval(function(){
        if(window.location.pathname.indexOf("BV") > -1 || window.location.pathname.indexOf("bv") > -1)
        {
            let pathname=window.location.pathname;
            let bv;
            if(pathname.indexOf("BV")>-1)
                bv=pathname.substring(window.location.pathname.lastIndexOf("/BV")+1).replace("/","");
            else
                bv=pathname.substring(window.location.pathname.lastIndexOf("/bv")+1).replace("/","");
            let av = dec(bv);

            if($("#avid").length==0)
            {
                var $avid = $("<span id='avid'></span>");
                $avid.attr("style","background: #FB7299; color: white; font-size: 13px; vertical-align:middle; margin-left:10px; padding: 5px; border-radius:5px; ")
                $avid.text(av)
                $avid.click(function(){
                    GM_setClipboard($('#avid').text(),'text');
                    alert('av号已复制')
                })
                $('.video-info-detail-list').append($avid)
            }
            else
            {
                if($('#avid').text()!=av)
                {
                    $('#avid').text(av)
                }
            }


            if($("#bvid").length==0)
            {
                var $bvid = $("<span id='bvid'></span>");
                $bvid.attr("style","background: #00A1D6; color: white; font-size: 13px; vertical-align:middle; margin-left:10px; padding: 5px; border-radius:5px; ")
                $bvid.text(bv.replace("BV","bv"))
                $bvid.click(function(){
                    GM_setClipboard($('#bvid').text(),'text');
                    alert('bv号已复制')
                })
                $('.video-info-detail-list').append($bvid)
            }
            else
            {
                if($('#bvid').text()!=bv)
                {
                    $('#bvid').text(bv)
                }
            }
        }
        else if(window.location.pathname.indexOf("av") > -1)
        {
            let av=window.location.pathname.substring(window.location.pathname.lastIndexOf("/av")+1).replace("/","");
            let bv = enc(av.substring(2));

            if($("#avid").length==0)
            {
                let $avid = $("<span id='avid'></span>");
                $avid.attr("style","background: #FB7299; color: white; font-size: 13px; vertical-align:middle; margin-left:10px; padding: 5px; border-radius:5px; ")
                $avid.text(av)
                $avid.click(function(){
                    GM_setClipboard($('#avid').text(),'text');
                    alert('av号已复制')
                })
                $('.video-info-detail-list').append($avid)
            }
            else
            {
                if($('#avid').text()!=av)
                {
                    $('#avid').text(av)
                }
            }


            if($("#bvid").length==0)
            {
                let $bvid = $("<span id='bvid'></span>");
                $bvid.attr("style","background: #00A1D6; color: white; font-size: 13px; vertical-align:middle; margin-left:10px; padding: 5px; border-radius:5px; ")
                $bvid.text(bv.replace("BV","bv"))
                $bvid.click(function(){
                    GM_setClipboard($('#bvid').text(),'text');
                    alert('bv号已复制')
                })
                $('.video-info-detail-list').append($bvid)
            }
            else
            {
                if($('#bvid').text()!=bv)
                {
                    $('#bvid').text(bv)
                }
            }
        }

        $(".nav-search-keyword").attr("placeholder"," ");
        $(".user-card-m").each(function(){
            if($(this).find(".uuid").length==0)
            {
                var $uuid = $("<span class='uuid'></span>");
                $uuid.attr("style","background: rgb(124, 212, 242); color: white; font-size: 12px; vertical-align:middle; margin-right:180px; padding-left:4px; padding-right:4px; border-radius:4px; font-weight:normal;")
                let url=$(this).find(".card-user-name").attr("href");
                if(url!= undefined)
                {
                    $uuid.text("  UID: "+url.substring(url.lastIndexOf("/")+1)+"  ")
                    $(this).find('.card-social-info').before($uuid)
                }
            }
        })
        $(".user-card-m-exp").each(function(){
            if($(this).find(".uuid").length==0)
            {
                var $uuid = $("<span class='uuid'></span>");
                $uuid.attr("style","background: rgb(124, 212, 242); color: white; font-size: 12px; vertical-align:middle; margin-right:180px; padding-left:4px; padding-right:4px; border-radius:4px; font-weight:normal;")
                let url=$(this).find(".card-user-name").attr("href");
                if(url!= undefined)
                {
                    $uuid.text("  UID: "+url.substring(url.lastIndexOf("/")+1)+"  ")
                    $(this).find('.card-social-info').before($uuid)
                }
            }
        })
        $(".user-card").each(function(){
            if($(this).find(".uuid").length==0)
            {
                var $uuid = $("<span class='uuid'></span>");
                $uuid.attr("style","background: rgb(124, 212, 242); color: white; font-size: 12px; vertical-align:middle; margin-right:180px; padding-left:4px; padding-right:4px; border-radius:4px; font-weight:normal;")
                let url=$(this).find(".card-user-name").attr("href");
                if(url!= undefined)
                {
                    $uuid.text("  UID: "+url.substring(url.lastIndexOf("/")+1)+"  ")
                    $(this).find('.card-social-info').before($uuid)
                }
            }
        })
    },1)

    setInterval(function(){
        if($(".toggle-btn").text().indexOf("展开更多") > -1)
            $(".toggle-btn").click();
        $(".ops span").attr("style","margin-right:25px"); //按钮间距
        $(".appeal-text").attr("style","margin-right:5px"); //稿件投诉
        $(".note-btn").attr("style","margin-right:0px"); //记笔记
        $(".share-pos").attr("style","width:520px"); //分享框

        if($(".ops .like").length > 0)
        {
            var liketext = $(".ops .like").contents().eq(-1).get(0).textContent
            if(liketext.indexOf("点赞")==-1)
                $(".ops .like").contents().eq(-1).get(0).textContent="点赞 "+liketext
        }

        if($(".ops .collect").length > 0)
        {
            var collecttext = $(".ops .collect").contents().eq(-1).get(0).nodeValue
            if(collecttext.indexOf("收藏")==-1)
                $(".ops .collect").contents().eq(-1).get(0).nodeValue="收藏 "+collecttext
        }

        if($(".ops .coin").length > 0)
        {
            var cointext = $(".ops .coin").contents().eq(-1).get(0).textContent
            if(cointext.indexOf("投币")==-1)
                $(".ops .coin").contents().eq(-1).get(0).textContent="投币 "+cointext
        }

        if($(".ops .share").length > 0)
        {
            var sharetext = $(".ops .share").contents().eq(1).get(0).nodeValue
            if(sharetext.indexOf("分享")==-1)
                $(".ops .share").contents().eq(1).get(0).nodeValue="分享 "+sharetext
        }


        $(".toolbar-left > span:not(:last-of-type)").attr("style","margin-right:25px"); //按钮间距
        $(".manuscript-report").attr("style","margin-right:5px"); //稿件投诉
        $('.video-toolbar-v1 .toolbar-left > span .info-text ').attr("style","overflow:visible!important"); //文本不省略

        if($(".toolbar-left .like .info-text").length > 0)
        {
            let new_liketext = $(".toolbar-left .like .info-text").text();
            if(new_liketext.indexOf("点赞")==-1)
                $(".toolbar-left .like .info-text").text("点赞 "+new_liketext);
        }

        if($(".toolbar-left .collect .info-text").length > 0)
        {
            let new_collecttext = $(".toolbar-left .collect .info-text").text();
            if(new_collecttext.indexOf("收藏")==-1)
                $(".toolbar-left .collect .info-text").text("收藏 "+new_collecttext);
        }

        if($(".toolbar-left .coin .info-text").length > 0)
        {
            let new_cointext = $(".toolbar-left .coin .info-text").text();
            if(new_cointext.indexOf("投币")==-1)
                $(".toolbar-left .coin .info-text").text("投币 "+new_cointext);
        }

        if($(".toolbar-left .share .info-text").length > 0)
        {
            let new_sharetext = $(".toolbar-left .share .info-text").text();
            if(new_sharetext.indexOf("分享")==-1)
                $(".toolbar-left .share .info-text").text("分享 "+new_sharetext);
        }


    },1000)


    setInterval(function(){
        if($("#activity_vote").length>0)
        {
            $("#activity_vote").hide()
        }
        $(".video-page-game-card").hide()
    },10)


    setInterval(function(){
        if($(".pop-live.report-wrap-module.report-scroll-module").length>0)
        {
            $(".pop-live.report-wrap-module.report-scroll-module").hide()
        }
    },500)

    var timer1=setInterval(function(){
        if($(".members-info__header").find(".btn").length>0 && $(".members-info__header").find(".btn").text().indexOf("展开") > -1)
        {
            $(".members-info__header").find(".btn").click()
            clearInterval(timer1)
        }
    },500)

    if(openbarrage==1)
    {
        var timer2=setInterval(function(){
            if($(".bui-collapse-arrow-text").length>0 && $(".bui-collapse-arrow-text").text().indexOf("展开") > -1)
            {
                $(".bui-collapse-arrow-text").click()
                clearInterval(timer2)
            }
        },500)
        }

    var timer3=setInterval(function(){
        if($(".bpx-player-filter").length>0 )
        {
            $(".bpx-player-filter").find(".bui-dropdown-icon").hide()
            $(".bpx-player-filter").find(".bui-dropdown-display").append($('<span class="bui-dropdown-name" style="margin-left:10px">屏蔽设定</span>'))
            $(".bpx-player-filter").find(".bui-dropdown-display").append($('<span class="bui-dropdown-name" style="margin-left:10px">高级弹幕</span>'))
            $(".bui-dropdown-name").css({"height":"35px","border-bottom": "none","text-decoration":"none", "z-index":"1000"})
            $(".bpx-player-filter span:first-child").addClass("on")
            $(".bpx-player-filter span:first-child").css({"border-bottom": "2px solid #32AAFF"})
            $(".bui-dropdown-name").hover(function(){
                $(this).addClass("hover")
                $(this).css({"height":"35px","border-bottom": "2px solid #32AAFF","text-decoration":"none"})
            },function(){
                $(this).removeClass("hover")
                if(!$(this).hasClass("on"))
                    $(this).css({"height":"35px","border-bottom": "none","text-decoration":"none"})
            })

            $(".bui-collapse-body").on('toggle',function(){
                return false;
            })

            $(".bui-dropdown-name").eq(0).click(function(){
                event.preventDefault()
                event.stopPropagation();
                return false
            })

            $(".bui-dropdown-name").eq(1).click(function(){
                event.preventDefault()
                event.stopPropagation();
                $(".bui-dropdown-name").fadeOut(300)

                var text = $(this).text()
                $(".bui-dropdown-items").children().each(function(){
                    if($(this).text() == text)
                        $(this).click()
                })
                $(".bui-dropdown-name").fadeIn(300)
                //$(".bui-dropdown-items").hide()
                $(".bui-dropdown-name").removeClass("on")
                $('.bui-dropdown-name').eq(0).addClass("on")

                if($(".arrow-icon").length > 0)
                {
                    setTimeout(function(){
                        $(".svgicon-r").click()
                    },500);
                }
                else if($(".bui-collapse-arrow-text").text().indexOf("展开") > -1)
                {
                    $(".bui-collapse-arrow-text").click()
                }

                //$("#danmukuBox").attr("style","height: 493px;")
                return false
            })
            $(".bui-dropdown-name").eq(2).click(function(){
                event.preventDefault()
                event.stopPropagation();
                $(".bui-dropdown-name").fadeOut(300)
                var text = $(this).text()
                $(".bui-dropdown-items").children().each(function(){
                    if($(this).text() == text)
                        $(this).click()
                })
                $(".bui-dropdown-name").fadeIn(300)
                //$(".bui-dropdown-items").hide()
                $(".bui-dropdown-name").removeClass("on")
                $('.bui-dropdown-name').eq(0).addClass("on")

                if($(".arrow-icon").length > 0)
                {
                    setTimeout(function(){
                        $(".svgicon-r").click()
                    },500);
                }
                else if($(".bui-collapse-arrow-text").text().indexOf("展开") > -1)
                {
                    $(".bui-collapse-arrow-text").click()
                }

                //$("#danmukuBox").attr("style","height: 493px;")
                return false;
            })
            setInterval(function(){

                if($(".bui-collapse-arrow-text").text().indexOf("收起") > -1)
                    $("#danmukuBox").attr("style","height: auto;")


                $(".bui-dropdown-display").each(function(){
                    if($(this).children().eq(0).text().indexOf("弹幕列表") > -1)
                    {
                        if($(this).children().eq(2).text().indexOf("屏蔽设定") == -1)
                            $(this).children().eq(2).text("屏蔽设定")
                        if($(this).children().eq(3).text().indexOf("高级弹幕") == -1)
                            $(this).children().eq(3).text("高级弹幕")
                    }
                    else if($(this).children().eq(0).text().indexOf("屏蔽设定") > -1)
                    {
                        if($(this).children().eq(2).text().indexOf("弹幕列表") == -1)
                            $(this).children().eq(2).text("弹幕列表")
                        if($(this).children().eq(3).text().indexOf("高级弹幕") == -1)
                            $(this).children().eq(3).text("高级弹幕")
                    }
                    else if($(this).children().eq(0).text().indexOf("高级弹幕") > -1)
                    {
                        if($(this).children().eq(2).text().indexOf("弹幕列表") == -1)
                            $(this).children().eq(2).text("弹幕列表")
                        if($(this).children().eq(3).text().indexOf("屏蔽设定") == -1)
                            $(this).children().eq(3).text("屏蔽设定")
                    }

                })

                $(".bui-dropdown-name").each(function(){
                    if($(this).hasClass("on") || $(this).hasClass("hover"))
                        $(this).css({"border-bottom": "2px solid #32AAFF"})
                    else
                        $(this).css({"border-bottom": "none"})
                })

            },300)
            clearInterval(timer3)
        }
    },100)

    setInterval(function(){
        $("#bannerAd").remove();
        $(".gg-floor-module").hide()
        $("#slide_ad").hide()
        $(".video-ad-creative-card").hide()
        $('.ad-report').hide()
        $(".bilibili-player-video-danmaku-setting-left-block-title").attr("style","color:#FF0000; font-weight:bold")

        var ban ='<img class="ban" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/'+
            'PjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBo'+
            'aWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyB0PSIxNTkxNjkyMzAyOTAzIiBjbGFzcz0iaWNvbiIgdmlld0JveD0i'+
            'MCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjI4'+
            'NjkiIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMTYiIGhlaWdodD0iMTYiPjxk'+
            'ZWZzPjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+QGZvbnQtZmFjZSB7IGZvbnQtZmFtaWx5OiBlbGVtZW50LWljb25zOyBzcmM6'+
            'IHVybCgiY2hyb21lLWV4dGVuc2lvbjovL2JiYWtobm1ma2plbmZiaGpkZGRpcGNlZm5ocGlramJqL2ZvbnRzL2VsZW1lbnQt'+
            'aWNvbnMud29mZiIpIGZvcm1hdCgid29mZiIpLCB1cmwoImNocm9tZS1leHRlbnNpb246Ly9iYmFraG5tZmtqZW5mYmhqZGRk'+
            'aXBjZWZuaHBpa2piai9mb250cy9lbGVtZW50LWljb25zLnR0ZiAiKSBmb3JtYXQoInRydWV0eXBlIik7IH0KPC9zdHlsZT48'+
            'L2RlZnM+PHBhdGggZD0iTTUxMiAwYTUxMiA1MTIgMCAxIDAgNTEyIDUxMiA1MTIgNTEyIDAgMCAwLTUxMi01MTJ6IG0zODQg'+
            'NTEyYTM4NCAzODQgMCAwIDEtNzEuMDQgMjIyLjA4TDI4OS45MiAxOTkuMDRBMzg0IDM4NCAwIDAgMSA4OTYgNTEyek0xMjgg'+
            'NTEyYTM4NCAzODQgMCAwIDEgNzEuMDQtMjIyLjA4bDUzNS4wNCA1MzUuMDRBMzg0IDM4NCAwIDAgMSAxMjggNTEyeiIgZmls'+
            'bD0iI0ZGMDAwMCIgcC1pZD0iMjg3MCI+PC9wYXRoPjwvc3ZnPg==">'
        var $ban = $(ban)
        $ban.css({"position":"absolute", "top":"17px", "left":"18px", "height":"10px", "width":"10px"})
        $(".bilibili-player-block-filter-type.disabled").find("svg").after($ban)
    },100)

}


(function() {
    'use strict';
    var css = '.player-auxiliary-area .bpx-player-filter:not(.bpx-player-filter-playlist){display:block!important}'+
        '.player-auxiliary-area .bui-dropdown-name.on{padding-bottom:3px}'+
        '.player-auxiliary-area .bui-dropdown-name:hover{padding-bottom:3px}'+
        '.user-card-m .info .user{margin-bottom:0px!important}'+
        '.user-card-m-exp .user-info-wrapper .info .user{margin-bottom:0px!important}'+
        '.user-card .info .user{margin-bottom:0px!important}';
    var head = document.getElementsByTagName('head')[0];
    var style = document.createElement('style');
    style.type = 'text/css';
    if (style.styleSheet) {
        style.styleSheet.cssText = css;
    }
    else {
        style.appendChild(document.createTextNode(css));
    }
    head.appendChild(style);

    var timer = setInterval(function(){
        if(window.jQuery)
        {
            clearInterval(timer)
            setTimeout(function(){
                v();
            },5000)
        }
    },100)
    })();