Greasy Fork

Greasy Fork is available in English.

白piao斗鱼

douyu整合优化斗鱼功能脚本(斗鱼精简、斗鱼真实人数显示、斗鱼默认最高画质)

目前为 2021-06-14 提交的版本,查看 最新版本

// ==UserScript==
// @name        白piao斗鱼
// @author      Sam
// @namespace   http://greasyfork.icu/zh-CN/scripts/390452
// @version     2021.02.20
// @description douyu整合优化斗鱼功能脚本(斗鱼精简、斗鱼真实人数显示、斗鱼默认最高画质)
// @match       *://*.douyu.com/g_*
// @match       *://*.douyu.com/0*
// @match       *://*.douyu.com/1*
// @match       *://*.douyu.com/2*
// @match       *://*.douyu.com/3*
// @match       *://*.douyu.com/4*
// @match       *://*.douyu.com/5*
// @match       *://*.douyu.com/6*
// @match       *://*.douyu.com/7*
// @match       *://*.douyu.com/8*
// @match       *://*.douyu.com/9*
// @match       *://*.douyu.com/directory/myFollow
// @match       *://*.douyu.com/topic/*
// @icon        https://www.douyu.com/favicon.ico
// @require     https://code.jquery.com/jquery-2.2.4.min.js
// @run-at      document-end
// @note        斗鱼精简 http://greasyfork.icu/zh-CN/scripts/386642
// @note        斗鱼真实人数显示 http://greasyfork.icu/zh-CN/scripts/388941

/*
主要功能:
    1.精简douyu.com页面元素
    2.直播打开直播页面自动页面全屏,自动切换最高清晰度画质
    3.弹幕栏顶部增加真实人数显示
*/
// ==/UserScript==



(function () {

    'use strict';

    var current_url = window.location.href;
    printLog('url --> ' + current_url);

    window.onload = function () {
        loadStyle();//精简界面
        // removeDom();
    }

    autoBestQuality();//切换最高画质
    autoFullScreen();//窗口化全屏

    // setTimeout(getRealViewer, 3000);//真实人数,添加<我的关注>按钮
    // setInterval(getRealViewer, 10000);

})();

function removeDom() {
    let elem_selectors = [
        '.wm-general'

    ]

    elem_selectors.forEach((item, index, array) => {
        printLog(item)
        document.querySelector(item).remove()
        //执行代码
    })
};

function loadStyle() {

    var css = '{display:none !important;height:0 !important}';
    css += '.layout-Player-rank{display:none !important}';
    css += '.layout-Player-barrage{top:0px !important;}';
    css += '.layout-Player-video{bottom:0px !important}';
    css += '.layout-Player-toolbar{visibility:hidden !important;}';
    css += '.layout-Bottom{display:none !important;}';
    css += '.guessGameContainer.is-normalRoom{display:none !important;}';
    css += '.DropPane-ad{display:none !important}';
    css += '.SignBaseComponent-sign-ad{display:none !important}';
    //css += '.AnchorAnnounce{display:none !important;}';  //斗鱼真实人数显示
    //css += '.FansMedalPanel-enter{display:none !important;}'; //牌子
    css += '.layout-Aside{display:none !important;}';
    css += '.Header-download-wrap{display:none !important;}';
    css += '.Header-broadcast-wrap{display:none !important;}';
    css += '#js-header > div > div > div.Header-left > div > ul > li:nth-child(5){display:none !important;}';
    css += '.ChatNobleBarrage{display:none !important;}';
    css += '.ChatFansBarrage{display:none !important;}';
    css += '.Horn4Category{display:none !important;}';
    css += '.FirePower{display:none !important;}';
    css += '.TreasureDetail{display:none !important;}';
    css += '.SignChatAd-chat-ad-cls{display:none !important;}';
    css += '.Promotion-nobleRights{display:none !important;}';
    css += '.Task{display:none !important;}';
    css += '.UPlayerLotteryEnter.is-active{display:none !important;}';
    css += '.LotteryContainer{display:none !important;}';
    css += '.layout-Module-head.FollowList-head.is-fixed{display:none !important;}';
    css += '.layout-Banner-item{display:none !important;}';
    css += '.layout-Module-extra{display:none !important;}';
    css += '.Title-anchorPic{display:none !important;}';
    css += '.Title-roomOtherBottom{display:none !important;}';
    css += '.Act129684Bar-view1{display:none !important;}';
    css += '.Act129684Bar-content{display:none !important;}';
    css += '.Act129684-logo{display:none !important;}';
    css += '.ActBase-switch{display:none !important;}';
    css += '.HeaderNav{display:none !important;}';
    css += '.HeaderGif-left{display:none !important;}';
    css += '.HeaderGif-right{display:none !important;}';
    css += '.Prompt-container{display:none !important;}';
    css += '.SysSign-Ad{display:none !important;}';
    css += '.ActDayPay-toast{display:none !important;}';
    css += '.code_box-5cdf5a{display:none !important;}';
    css += '.normalDiv-8b686d{display:none !important;}';
    css += '.closeBg-998534{display:none !important;}';
    css += '.bg-d4758b{display:none !important;}';
    css += '.fireOpenRanking react-draggable react-draggable-dragged{display:none !important;}';
    css += '.vsFestival1908{display:none !important;}';
    css += '.ActSuperFansGroup-component.ActSuperFansGroupBar-normalBody{display:none !important;}';
    css += '.ActSuperFansGroup-component.ActSuperFansGroupBar-miniBody{display:none !important;}';
    css += '.ActSuperFansGroup-component.ActSuperFansGroupBar-plusBody{display:none !important;}';
    css += '.ActSuperFansGroup-logo{display:none !important;}';
    css += '.ActSuperFansGroup-switch{display:none !important;}';
    css += '.TitleSuperFansIcon{display:none !important;}';
    css += '.Act156581Bar{display:none !important;}';
    css += '.Act159742Bar-main--pre{display:none !important;}';
    css += '.Act159742-logo{display:none !important;}';
    css += '.Act159742Bar-wrap{display:none !important;}';
    css += '.Title-columnTag{display:none !important;}';
    css += '.Title-impress.clearFix{display:none !important;}';
    css += '#js-room-activity{display:none !important;}'; //活动 年度决赛 巅峰排行
    css += '.TBarrage-hiIcon{display:none !important;}';
    css += 'span.UserLevel{display:none !important;}';
    css += '.FansMedal{display:none !important;}';
    css += 'span.Motor{display:none !important;}';
    css += 'span.Barrage-hiIcon{display:none !important;}';
    css += 'span.RoomLevel{display:none !important;}';
    css += 'span.Barrage-icon{display:none !important;}';
    css += 'a.ChatAchievement{display:none !important;}';
    css += 'section.layout-Customize{display:none !important;}';

    

    var style = document.createElement('style');
    style.type = 'text/css';
    style.rel = 'stylesheet';
    style.appendChild(document.createTextNode(css));
    var head = document.getElementsByTagName('head')[0];
    head.appendChild(style);
    printLog('已加载CSS');
};

function modifiedMyFollow() {
    var current_url = window.location.pathname;
    if (current_url == "/directory/myFollow") {

        //移除‘我的关注’页面推广主播
        let dom_selector = "div.AthenaBoothPanel-wrapper";
        waitDom(dom_selector, function () {
			/*
            var cover_list = document.querySelectorAll("li.layout-Cover-item");
            var cover_0 = cover_list[0].querySelector('div.layout-Cover-card').getAttribute('class') == "layout-Cover-card",
                cover_1 = cover_list[1].querySelector('div.layout-Cover-card').getAttribute('class') == "layout-Cover-card dycard-first";
            if (cover_0 & cover_1) {
                cover_list[0].remove();
                printLog('移除‘我的关注’页面推广主播')
                // let parent = document.querySelector("#js-follow > section > div.layout-Module-container.layout-Cover.ScrollTabFrame-layoutContainer > ul")
            };
			*/
			var cover_list = document.querySelectorAll("li.layout-Cover-item");
            var cover_0 = cover_list[0].querySelector('div.layout-Cover-card').getAttribute('class') == "layout-Cover-card"
                
            if (cover_0) {
                cover_list[0].remove();
                printLog('移除‘我的关注’页面推广主播')
                // let parent = document.querySelector("#js-follow > section > div.layout-Module-container.layout-Cover.ScrollTabFrame-layoutContainer > ul")
            };

            //调整收藏页面,增加开播时间显示
            let css_stream = ".DyLiveCover-user {display: block;padding-right: 5px;overflow: hidden;-o-text-overflow: ellipsis;text-overflow: ellipsis;white-space: nowrap;color: #888;font-size: 10px;line-height: 24px;margin: 0;font-weight: 500}"
            loadStyle(css_stream);
            cover_list.forEach(each => {
                let cover_card = each.querySelector("div.DyLiveCover")
                if (cover_card) {
                    let stream_start_time = timeStampTurnTime(cover_card.getAttribute("showtime")),
                        stream_title = cover_card.querySelector("h2.DyLiveCover-user")
                    if (stream_start_time) {
                        
                        stream_title.innerText = stream_start_time
                        //stream_title.style.fontSize = 10;
                    }
                }
            });

        });
    };
};


function autoFullScreen() {
    let dom_selector = "div.wfs-2a8e83"
    waitDom(dom_selector, function () {
        document.querySelector(dom_selector).click();
        printLog('已自动全屏');
        modDom();//调整页面布局
    });
};


function modDom() {
    let dom_selector = "div.Barrage";
    waitDom(dom_selector, function () {
        document.querySelector('.VideoEntry').remove(); //移除主播视频入口
        document.querySelector(dom_selector).style.top = "38px";//调整弹幕区域高度       
        document.querySelector('.FullPageFollowGuide').remove(); //移除全屏状态下主播小头像
        printLog('已调整页面布局');
    });
};


function autoBestQuality() {
    waitDom('.rate-5c068c', function () {
        document.querySelector('div.tip-e3420a > ul > li').click();
        printLog('已切换最高画质');
    })
};


function formatNumber(fmt_num) {
    let num_tmp = Number(fmt_num)
    //console.log('num_tmp ->',num_tmp)
    if (num_tmp == void 0) {
        return '0'
    } else {
        if (num_tmp > 10000) {
            return String((num_tmp / 10000).toFixed(1)) + '万'
        } else {
            return String(fmt_num)
        }
    }
};

function genIcon(label, message, color) {
    if (label !== '') {
        label = encodeURI(label)
    }
    message = encodeURI(message)
    if (color === '') {
        color = 'E61A1A'
    }
    let img_src = 'https://img.shields.io/badge/' + label + '-' + message + '-' + color
    let icon = '<img src="' + img_src + '"></img>';
    return icon
};

function getRealViewer() {
    let viewIcon = '<svg style="width:16px;height:16px" t="1566119680547" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3494" width="128" height="128"><path d="M712.820909 595.224609C807.907642 536.686746 870.40537 437.74751 870.40537 325.549212 870.400378 145.753547 709.943392 0 511.997503 0 314.055363 0 153.599626 145.753547 153.599626 325.549212 153.599626 437.74751 216.092361 536.686746 311.179092 595.219615 149.961841 657.72608 31.268214 793.205446 5.334335 955.968198 1.926253 962.195123 0 969.212275 0 976.638899 0 1002.324352 22.919038 1023.151098 51.198627 1023.151098 79.476967 1023.151098 102.396005 1002.324352 102.396005 976.638899L102.396005 1023.151098C102.396005 817.669984 285.787009 651.099674 511.997503 651.099674 738.212992 651.099674 921.602746 817.669984 921.602746 1023.151098L921.602746 976.638899C921.602746 1002.324352 944.523034 1023.151098 972.801376 1023.151098 1001.07472 1023.151098 1024 1002.324352 1024 976.638899 1024 969.212275 1022.073747 962.195123 1018.659424 955.968198 992.731789 793.205446 874.038157 657.72608 712.820909 595.224609ZM511.997503 558.080262C370.618285 558.080262 256.000624 453.967732 256.000624 325.545467 256.000624 197.121954 370.618285 93.009424 511.997503 93.009424 653.386707 93.009424 767.993133 197.121954 767.993133 325.545467 767.993133 453.972726 653.386707 558.080262 511.997503 558.080262L511.997503 558.080262Z" p-id="3495"></path></svg>'
    let hotIcon = '<svg style="width:16px;height:16px" t="1566119430182" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3302" width="128" height="128"><path d="M255.83 338.84C93.092 480.356 75.837 726.967 217.317 889.716s388.08 179.926 550.863 38.514 179.948-388.08 38.469-550.83S519.257 94.96 521.197 0c-56.964 84.64-228.94 267.227-148.224 491.091-82.7-22.871-99.888-101.624-117.143-152.25z" fill="#F96A6A" p-id="3303"></path></svg>'
    let a = {
        view: "",
        showtime: "",
        hot: ""
    }

    let myFollow_icon = '<svg style="width:18px;height:18px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"  width="100%" height="100%"><title>我的关注</title><path d="M20.801 3.2c5.371 0.002 9.597 4.082 9.597 9.6 0 6.126-4.669 11.381-13.686 15.835-0.447 0.221-0.97 0.221-1.417 0-9.023-4.454-13.695-9.709-13.695-15.835 0-5.524 4.244-9.6 9.598-9.6 1.757 0 3.343 0.559 4.811 1.596 0.346-0.241 0.695-0.456 1.051-0.644 1.078-0.595 2.335-0.952 3.74-0.952h0.001zM13.926 7.248c-0.878-0.566-1.769-0.848-2.726-0.848-3.615 0-6.398 2.673-6.398 6.4 0 4.509 3.637 8.733 11.203 12.609 7.561-3.875 11.195-8.1 11.195-12.609 0-3.726-2.77-6.4-6.4-6.4-0.897 0-1.75 0.263-2.614 0.794-0.405 0.31-0.764 0.695-1.083 1.141-0.685 0.96-1.103 2.213-1.103 2.864 0 0.884-0.716 1.6-1.6 1.6s-1.6-0.716-1.6-1.6c0-1.306 0.395-2.7 1.126-3.952z"></path></svg>'
    let myFollow = "<a href='/directory/myFollow' target='_blank'>" + myFollow_icon + "  " + "</a>";
    //let myFollow = genIcon('我的收藏',10,'E61A1A')
    let url = document.getElementsByTagName('html')[0].innerHTML;
    let urlLen = ("$ROOM.room_id =").length;
    let ridPos = url.indexOf('$ROOM.room_id =');
    let rid = url.substring(ridPos + urlLen, url.indexOf(';', ridPos + urlLen));
    rid = rid.trim();

    if (document.querySelector(".MatchSystemChatRoomEntry") != null) {
        document.querySelector(".MatchSystemChatRoomEntry").style.display = "none";
    }
    $.get("https://www.douyu.com/swf_api/h5room/" + rid, function (retData) {

        /*
        a.view = retData.data.online;
        a.view = formatNumber(a.view)
        a.view = '<span style="color:red">' + a.view + "</span>"
        a.view = "<div style='display: inline-block;' title='观看人数'>" + viewIcon + a.view + "</div>"
        */
        a.hot = document.querySelector(".Title-anchorText").innerHTML;
        a.hot = formatNumber(a.hot)
        a.hot = '<span style="color:blue">' + a.hot + "</span>"
        a.showtime = timeStampTurnTime(retData.data.show_time);
        a.hot = "<div style='display: inline-block;' title='热度'>" + hotIcon + a.hot + "</div>"


        /*
        a.view = retData.data.online;
        a.view = genIcon('人数',formatThousand(a.view),'')

        a.hot = document.querySelector(".Title-anchorText").innerHTML;
        a.hot = genIcon('人气',formatThousand(a.hot),'')
        */
        document.querySelector(".AnchorAnnounce").innerHTML = myFollow + a.view + "  " + a.hot + '<span style="float:right">' + "开播时间:" + a.showtime + "</span>";
    });
};


/*
    功能:等待dom加载后执行函数
    dom_selector :选择器参数  待加载的dom = document.querySelector(dom_selector)
    func:待执行函数体,用匿名函数传参
*/
//方式1:
/*
function waitDom(dom_selector, func) {
    let is_DomExist = false;
    for (var i = 0; i < 100; i++) {
        (function (i) {
            setTimeout(function () {
                if (document.querySelector(dom_selector)) {
                    if (!is_DomExist) {
                        func()
                        is_DomExist = true
                    }
                }
            }, (i + 1) * 200);
        })(i)
    }
};
*/
//方式2:无限次数检测dom,防止后台打开页面未及时加载
function waitDom(dom_selector, func) {
    let is_DomExist = false;
    let interval = 100;//时间间隔
    var int_checkDom = setInterval(() => {
        if (document.querySelector(dom_selector)) {
            is_DomExist = true;
            func();
        };
        if (is_DomExist) {
            clearInterval(int_checkDom);
        }
    }, interval);
};


function timeStampTurnTime(timeStamp) {
    if (timeStamp > 0) {
        let date = new Date();
        date.setTime(timeStamp * 1000);
        let y = date.getFullYear();
        let m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        let d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        let h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        let minute = date.getMinutes();
        let second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
    } else {
        return "";
    }

};

function printLog(msg) {
    const scriptName = '[ Simple Douyu ]';
    console.log(scriptName + '  ' + msg);
};