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

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

As of 2020-07-04. See the latest version.

// ==UserScript==
// @name         哔哩哔哩(b站)播放页美化
// @namespace    http://tampermonkey.net/
// @version      0.2.6.2
// @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==

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("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)
        }
        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/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(){
        $(".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:20px")
        $(".share-pos").attr("style","width:480px")

        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()
        }
    },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)
        }
	},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'+
			'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 timer = setInterval(function(){
        if(window.jQuery)
        {
            clearInterval(timer)
            setTimeout(function(){
                v();
            },1500)
        }
    },100)
})();