Greasy Fork

Greasy Fork is available in English.

斗鱼清爽版【整合功能】

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

目前为 2019-10-02 提交的版本,查看 最新版本

// ==UserScript==
// @name           斗鱼清爽版【整合功能】
// @author         sam
// @namespace      http://greasyfork.icu/zh-CN/scripts/390452
// @version        1.0.4
// @description    douyu整合优化斗鱼功能脚本(斗鱼精简、斗鱼真实人数显示、斗鱼默认最高画质)
// @note           斗鱼精简 http://greasyfork.icu/zh-CN/scripts/386642
// @note           斗鱼真实人数显示 http://greasyfork.icu/zh-CN/scripts/388941
// @note           斗鱼默认最高画质  http://greasyfork.icu/zh-CN/scripts/384173
// @match          http*://www.douyu.com/*
// @icon           https://www.douyu.com/favicon.ico
// @require     https://code.jquery.com/jquery-2.2.4.min.js
// @run-at document-end
// ==/UserScript==


(function() {
    'use strict';
    window.onload = function(){
        var curent_url = window.location.href;
        console.log('[Neat Douyu Stream] url --> '+curent_url)
        loadStyle(css);//精简界面

        autoSwitch();//切换最高画质
        autoClickFullscreen();//窗口化全屏
        setTimeout(getRealViewer,3000);//真实人数
        setInterval(getRealViewer,10000);
    };
})();

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;}';

function loadStyle(css) {
    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);
    console.log('[Neat Douyu Stream]已完成:页面精简')

};


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 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 = '<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 = '<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>"
        document.querySelector(".AnchorAnnounce").innerHTML =  a.view + "  " + a.hot + '<span style="float:right">' + "开播时间:" + a.showtime + "</span>";
    });
};

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 autoClickFullscreen(){
    let click_times = 1
    var window_fullscreen = document.querySelector("div.wfs-2a8e83");
    if(window_fullscreen){
        window_fullscreen.click();
        console.log('[Neat Douyu Stream]已完成:页面全屏');
    }else{
        if(click_times++<20){
            setTimeout(()=>{
                autoClickFullscreen()
            },1000)
        };
    };
};

function autoSwitch(){
    const startTime = new Date().getTime()
    let count = 1
    let dom = Array.from(document.querySelectorAll('input')).find((item,index)=>{return item.value.includes('画质')});

    if(dom){

        const ul_dom = Array.from(dom.parentNode.childNodes).find((item)=>item.tagName=='UL')
        const li_dom = Array.from(ul_dom.childNodes)
        let seleteIndex = 0
        li_dom.forEach((item,index)=>{
            if(item.className!=''){
                seleteIndex = index
            }
        })
        if(seleteIndex==0){
            const endTime = new Date().getTime()
            console.log('默认为最高画质,无需切换')
            console.log(`脚本结束,耗时:${(endTime-startTime)/1000}秒`)
        }else{
            const endTime = new Date().getTime()
            const old_quality = li_dom[seleteIndex].innerText
            const new_quelity = li_dom[0].innerText
            li_dom[0].click()
            console.log(`已从${old_quality}切换到${new_quelity}`)
            console.log(`脚本结束,耗时:${(endTime-startTime)/1000}秒`)
            console.log('[Neat Douyu Stream]已完成:画质切换');
        }
    }else{
        if(count++<20){
            setTimeout(()=>{
                autoSwitch()
            },1000)
        }else{
            console.log('脚本结束,可能此网站不是直播间')
        }
    }
};