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

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

As of 2020-06-12 08:00:28 UTC. See the latest version.

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

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 () {
        var uid = $.cookie("DedeUserID")
        if($.cookie('registration_id')==undefined)
            $.cookie('registration_id', uid, { expires: 365, path: "/", domain: "bilibili.com" });

        if(window.location.href.indexOf("member.bilibili.com") > -1) //创作中心
        {
            var timer = setInterval(function(){
                if($(".tips-calendar_wrap").length>0)
                {
                    var s =$(".tips-calendar_wrap").wrap("<div />").parent().html()
                    console.log(s)
                    if(s.indexOf("第")>-1)
                    {
                        var start = s.indexOf("第")+1;
                        var end = s.indexOf("天")
                        var registration_days= s.substring(start,end)
                        console.log(registration_days)
                        var today = new Date()
                        var d=today.getDate()
                        d=d-registration_days
                        var theday=new Date(today.getFullYear(),today.getMonth(),d);
                        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)
            }

        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/v2#/home" 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+" ")
                    }
                })
            }
        })
    });

    setInterval(function(){
        if($("#v_desc > div.btn").text().indexOf("展开更多") > -1)
            $("#v_desc > div.btn").click()
        $(".ops span").attr("style","margin-right:20px")
        $(".share-pos").attr("style","width:480px")

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

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

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

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

    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)
        }

        setInterval(function(){

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

    },500)

    
}


(function() {
    'use strict';
    var timer = setInterval(function(){
        if(window.jQuery)
        {
            console.log($.fn.jquery)
            clearInterval(timer)
            v();
        }
    },100)
})();