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

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

// ==UserScript==
// @name         哔哩哔哩(b站)播放页美化
// @namespace    http://tampermonkey.net/
// @version      0.3.5
// @description  播放页显示UID和注册时间,显示屏蔽设定和高级弹幕选项
// @author       AN drew
// @match        https://game.bilibili.com/*
// @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/*
// @grant        none
// ==/UserScript==

var openbarrage=0;

function v()
{
    var scriptsArray = new Array();
    $.cachedScript = function (url, options) {
        //循环script标记数组
        for (var s in scriptsArray) {
            console.log(scriptsArray[s]);
            //如果某个数组已经下载到了本地
            if (scriptsArray[s]==url) {
                return { //则返回一个对象字面量,其中的done之所以叫做done是为了与下面$.ajax中的done相对应
                    done: function (method) {
                        if (typeof method == 'function'){ //如果传入参数为一个方法
                            method();
                        }
                    }
                };
            }
        }
        //这里是jquery官方提供类似getScript实现的方法,也就是说getScript其实也就是对ajax方法的一个拓展
        options = $.extend(options || {}, {
            dataType: "script",
            url: url,
            cache:true //其实现在这缓存加与不加没多大区别
        });
        scriptsArray.push(url); //将url地址放入script标记数组中
        return $.ajax(options);
    };


    $.cachedScript('https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js').done(function () {

        console.log("加载成功")

        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($(".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+" ")
                    }
                })
            }
        })
    });

    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);
        }
        return 'av' + String((r - add) ^ xor);
    }
    function enc(x)
    {
        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)
                $("#viewbox_report").children().eq(1).append($avid)
            }
            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"))
                $("#viewbox_report").children().eq(1).append($bvid)
            }
        }
        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)
                $("#viewbox_report").children().eq(1).append($avid)
            }
            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"))
                $("#viewbox_report").children().eq(1).append($bvid)
            }
        }

        $(".nav-search-keyword").attr("placeholder"," ");
        if($(".user-card-m").length > 0)
        {
            if($(".user-card-m .uuid").length==0)
            {
                var $uuid = $("<span class='uuid'></span>");
                $uuid.attr("style","background: rgb(124, 212, 242); color: white; font-size: 10px; vertical-align:middle; margin-left:4px; padding-left:2px; padding-right:5px; border-radius:4px; font-weight:normal ")
                $uuid.text("  UID: "+$(".user .name").attr("href").substring($(".user .name").attr("href").lastIndexOf("/")+1)+"  ")
                $(".user-card-m .user").append($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: 10px; vertical-align:middle; margin-left:4px; padding-left:2px; padding-right:5px; border-radius:4px; font-weight:normal ")
                $uuid.text("  UID: "+$(this).find(".user .name").attr("href").substring($(this).find(".user .name").attr("href").lastIndexOf("/")+1)+"  ")
                $(this).find(".user").append($uuid)
            }
        })
    },1)

    setInterval(function(){
        if($("#v_desc > div.btn").text().indexOf("展开更多") > -1)
            $("#v_desc > div.btn").click()
        $(".ops span").attr("style","margin-right:30px")
        $(".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
        }

    },10)


    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 t1=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(t1)
        }
    },500)

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

    var t3=setInterval(function(){
        if($(".player-auxiliary-filter").length>0 )
        {
            $(".player-auxiliary-filter").find("i").hide()
            $(".player-auxiliary-filter").find("i").before($('<span class="player-auxiliary-filter-title" style="margin-left:10px">屏蔽设定</span>'))
            $(".player-auxiliary-filter").find("i").before($('<span class="player-auxiliary-filter-title" style="margin-left:10px">高级弹幕</span>'))
            $(".player-auxiliary-filter-title").css({"height":"35px","border-bottom": "none","text-decoration":"none", "z-index":"1000"})
            $(".player-auxiliary-filter span:first-child").addClass("on")
            $(".player-auxiliary-filter span:first-child").css({"border-bottom": "2px solid #32AAFF"})
            $(".player-auxiliary-filter-title").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;
            })

            $(".player-auxiliary-filter-title:nth-of-type(1)").click(function(){
                event.preventDefault()
                event.stopPropagation();
                return false
            })

            $(".player-auxiliary-filter-title:nth-of-type(2)").click(function(){
                event.preventDefault()
                event.stopPropagation();
                $(".player-auxiliary-filter-title").fadeOut(300)

                var text = $(this).text()
                $(".player-auxiliary-setting-menu-wrap").children().each(function(){
                    if($(this).text() == text)
                        $(this).click()
                })
                $(".player-auxiliary-filter-title").fadeIn(300)
                $(".player-auxiliary-setting-menu-wrap").hide()
                $(".player-auxiliary-filter-title").removeClass("on")
                $(this).parent().children().eq(0).addClass("on")
                if($(".bui-collapse-arrow-text").text().indexOf("展开") > -1)
                    $(".bui-collapse-arrow-text").click()
                $("#danmukuBox").attr("style","height: 493px;")
                return false
            })
            $(".player-auxiliary-filter-title:nth-of-type(3)").click(function(){
                event.preventDefault()
                event.stopPropagation();
                $(".player-auxiliary-filter-title").fadeOut(300)
                var text = $(this).text()
                $(".player-auxiliary-setting-menu-wrap").children().each(function(){
                    if($(this).text() == text)
                        $(this).click()
                })
                $(".player-auxiliary-filter-title").fadeIn(300)
                $(".player-auxiliary-setting-menu-wrap").hide()
                $(".player-auxiliary-filter-title").removeClass("on")
                $(this).parent().children().eq(0).addClass("on")
                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;")

                $(".player-auxiliary-filter").each(function(){

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

                })

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

            },10)
            clearInterval(t3)
        }
	},100)

	setInterval(function(){
        $("#bannerAd").remove();
			$(".gg-floor-module").hide()
            $("#slide_ad").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'+
			'aWNzL1NWRy8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)
		$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 timer = setInterval(function(){
        if(window.jQuery)
        {
            clearInterval(timer)
            setTimeout(function(){
                v();
            },1500)
        }
    },100)
})();