斗鱼显示真实人数

显示斗鱼真实直播观众人数

// ==UserScript==
// @name         斗鱼显示真实人数
// @namespace    https://github.com/qianjiachun
// @version      0.9
// @description  显示斗鱼真实直播观众人数
// @author       小淳
// @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/topic/*
// @grant        none
// @require     https://code.jquery.com/jquery-2.2.4.min.js

// ==/UserScript==
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 danmuIcon = '<svg t="1576951281876" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6314" width="16" height="16"><path d="M500.622222 324.266667s0 5.688889-5.688889 5.688889v62.577777h91.022223v-56.888889H506.311111c-5.688889-17.066667-5.688889-17.066667-5.688889-11.377777zM733.866667 324.266667c5.688889 0 0-5.688889 0 0h-91.022223v56.888889h91.022223v-56.888889zM494.933333 523.377778c0 5.688889 0 5.688889 5.688889 5.688889 0 0 5.688889 0 5.688889 5.688889h79.644445v-56.888889H494.933333v45.511111zM733.866667 529.066667v-51.2h-91.022223v56.888889h85.333334c5.688889 0 5.688889 0 5.688889-5.688889z" p-id="6315" fill="#1296db"></path><path d="M796.444444 0H227.555556C102.4 0 0 102.4 0 227.555556v568.888888c0 125.155556 102.4 227.555556 227.555556 227.555556h568.888888c125.155556 0 227.555556-102.4 227.555556-227.555556V227.555556c0-125.155556-102.4-227.555556-227.555556-227.555556zM381.155556 711.111111c-5.688889 34.133333-11.377778 56.888889-22.755556 73.955556-11.377778 17.066667-22.755556 34.133333-34.133333 39.822222s-28.444444 11.377778-45.511111 11.377778c-17.066667 0-39.822222-5.688889-62.577778-22.755556-17.066667-11.377778-28.444444-17.066667-34.133334-28.444444-5.688889-11.377778-5.688889-22.755556 5.688889-39.822223 5.688889-11.377778 11.377778-17.066667 22.755556-17.066666s22.755556 0 34.133333 11.377778c11.377778 5.688889 17.066667 11.377778 22.755556 17.066666 5.688889 0 11.377778 5.688889 17.066666 0 5.688889 0 11.377778-5.688889 11.377778-5.688889 5.688889-5.688889 5.688889-11.377778 11.377778-17.066666 5.688889-11.377778 5.688889-22.755556 5.688889-39.822223 0-17.066667 5.688889-39.822222 5.688889-73.955555 0-11.377778 0-22.755556-5.688889-22.755556 0-5.688889-11.377778 0-11.377778 0H210.488889c-5.688889 0-17.066667-5.688889-22.755556-11.377777-5.688889-5.688889-5.688889-11.377778-11.377777-22.755556v-39.822222l11.377777-91.022222c0-11.377778 5.688889-22.755556 5.688889-34.133334 0-11.377778 5.688889-17.066667 11.377778-22.755555 5.688889-5.688889 11.377778-11.377778 17.066667-11.377778 5.688889 0 17.066667-5.688889 28.444444-5.688889h51.2c5.688889 0 11.377778 0 11.377778-5.688889 0 0 5.688889-5.688889 5.688889-17.066667v-39.822222s0-11.377778-5.688889-17.066666l-11.377778-11.377778H210.488889c-11.377778 0-22.755556 0-28.444445-5.688889-5.688889-5.688889-5.688889-17.066667-5.688888-28.444445 0-17.066667 5.688889-22.755556 11.377777-28.444444 5.688889-5.688889 17.066667-5.688889 28.444445-22.755556h108.088889c22.755556 11.377778 39.822222 17.066667 45.511111 34.133334 11.377778 11.377778 5.688889 56.888889 5.688889 56.888889V341.333333c0 28.444444-5.688889 51.2-17.066667 62.577778-11.377778 11.377778-22.755556 17.066667-45.511111 17.066667h-56.888889c-5.688889 0-11.377778 0-17.066667 5.688889 0 0-5.688889 5.688889-5.688889 11.377777l-5.688888 56.888889v11.377778h91.022222s22.755556 5.688889 28.444444 5.688889c5.688889 0 17.066667 5.688889 17.066667 11.377778s11.377778 11.377778 11.377778 22.755555 5.688889 22.755556 5.688889 39.822223c5.688889 51.2 5.688889 91.022222 0 125.155555z m455.111111 17.066667c-5.688889 5.688889-22.755556 11.377778-34.133334 17.066666h-125.155555v62.577778c-17.066667 17.066667-22.755556 28.444444-28.444445 34.133334-5.688889 5.688889-17.066667 11.377778-34.133333 11.377777-11.377778 0-22.755556-5.688889-28.444444-11.377777-5.688889-5.688889-11.377778-17.066667 0-34.133334v-62.577778H420.977778c-5.688889-11.377778-11.377778-11.377778-11.377778-11.377777-5.688889 0-5.688889-5.688889-5.688889-11.377778v-22.755556c-5.688889-17.066667-5.688889-28.444444 5.688889-34.133333 5.688889-5.688889 17.066667-5.688889 34.133333-11.377778h142.222223v-56.888889H500.622222c-22.755556 0-45.511111-5.688889-51.2-17.066666-11.377778-11.377778-11.377778-28.444444-11.377778-56.888889V312.888889c0-28.444444 5.688889-45.511111 17.066667-56.888889 11.377778-11.377778 28.444444-17.066667 51.2-17.066667 0 0 0-5.688889-5.688889-5.688889L494.933333 227.555556c-11.377778-17.066667-11.377778-22.755556-11.377777-34.133334 0-11.377778 5.688889-17.066667 17.066666-28.444444 11.377778-5.688889 22.755556-11.377778 34.133334-11.377778 11.377778 0 22.755556 11.377778 28.444444 22.755556 5.688889 11.377778 5.688889 22.755556 11.377778 34.133333 5.688889 11.377778 11.377778 17.066667 11.377778 28.444444h79.644444c11.377778-11.377778 17.066667-17.066667 17.066667-28.444444 5.688889-11.377778 11.377778-17.066667 11.377777-28.444445 5.688889-17.066667 17.066667-22.755556 22.755556-28.444444 11.377778-5.688889 17.066667 0 28.444444 5.688889s17.066667 17.066667 22.755556 22.755555c5.688889 11.377778 0 22.755556-5.688889 34.133334 0 5.688889-5.688889 5.688889-5.688889 11.377778s-5.688889 5.688889-5.688889 11.377777c22.755556 0 39.822222 5.688889 51.2 17.066667 11.377778 11.377778 11.377778 28.444444 11.377778 56.888889v204.8c0 28.444444-5.688889 45.511111-11.377778 56.888889s-28.444444 17.066667-51.2 17.066666h-85.333333v56.888889h125.155556c17.066667 0 28.444444 5.688889 34.133333 11.377778 5.688889 5.688889 11.377778 17.066667 11.377778 28.444445 11.377778 22.755556 11.377778 34.133333 0 39.822222z" p-id="6316" fill="#1296db"></path></svg>'
let giftIcon = '<svg t="1576950815993" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3618" width="16" height="16"><path d="M554.957 829.848l-85.905 0 0-463.89c0-18.978 15.384-34.363 34.362-34.363l17.182 0c18.978 0 34.362 15.38499999 34.362 34.363l0 463.89z" fill="#d4237a" p-id="3619"></path><path d="M889.985 494.814l-755.97 0c-37.902 0-68.724-30.82999999-68.724-68.725L65.291 323.003c0-56.846 46.241-103.087 103.087-103.087l687.245 0c56.846 0 103.087 46.24 103.087 103.087l0 103.086c-0.001 37.894-30.823 68.725-68.725 68.725z m0-68.725l0 34.363 0.016-34.363-0.016 0zM168.377 288.64c-18.94300001 0-34.363 15.412-34.363 34.364l0 103.086 755.87 0 0.1-103.086c0-18.952-15.42-34.363-34.363-34.363L168.377 288.641z" fill="#d4237a" p-id="3620"></path><path d="M821.26 958.712L202.74 958.712c-37.903 0-68.725-30.838-68.725-68.732L134.015 494.814c0-37.89400001 30.822-68.725 68.724-68.725l618.522 0c37.902 0 68.724 30.82999999 68.724 68.725L889.985 889.98c0 37.89400001-30.822 68.73199999-68.724 68.732z m0-68.732l0 34.362 0.017-34.362-0.016 0zM202.74 494.814L202.74 889.98l618.42 0 0.1-395.166L202.74 494.814z m281.358-240.537c-9.93399999 0-19.78200001-4.278-26.578-12.55L358.728 121.46c-12.03-14.664-9.916-36.317 4.748-48.363 14.648-12.038 36.326-9.924 48.373 4.74l98.79199999 120.268c12.03 14.664 9.916 36.317-4.74799999 48.363a34.213 34.213 0 0 1-21.795 7.81z" fill="#d4237a" p-id="3621"></path><path d="M539.902 254.277a34.212 34.212 0 0 1-21.795-7.81c-14.664-12.047-16.778-33.7-4.748-48.363L612.15 77.836c12.047-14.664 33.708-16.77799999 48.373-4.74 14.664 12.047 16.778 33.7 4.748 48.363l-98.792 120.268c-6.795 8.272-16.644 12.55-26.577 12.55z" fill="#d4237a" p-id="3622"></path></svg>'
let a = {
	view: "",
	showtime: "",
	hot: "",
	danmu_person_count: "",
	gift_person_count: "",
	
}

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();

function getRealViewer() {
	if(document.querySelector(".MatchSystemChatRoomEntry") != null){
		document.querySelector(".MatchSystemChatRoomEntry").style.display = "none";
	}
	$.get("https://bojianger.com/data/api/common/search.do?keyword=" + rid,function(retData){
		a.view = retData.data.anchorVo.audience_count;
		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.anchorVo.update_time);
		a.danmu_person_count = retData.data.anchorVo.danmu_person_count;
		a.gift_person_count = retData.data.anchorVo.gift_person_count;
		a.danmu_person_count = "<div style='display: inline-block;' title='弹幕人数'>" + danmuIcon + a.danmu_person_count + "</div>"
		a.gift_person_count = "<div style='display: inline-block;' title='送礼人数'>" + giftIcon + a.gift_person_count + "</div>"
		// a.hot = "<div style='display: inline-block;' title='热度'>" + hotIcon + a.hot + "</div>"
		
		
		document.querySelector(".AnchorAnnounce").innerHTML =  a.view + " " + a.danmu_person_count + " " + a.gift_person_count + '<span style="float:right">' + " " + a.showtime + "</span>";
	  });
	
}


function timeStampTurnTime(timeStamp){
    if(timeStamp > 0){
        let date = new Date();  
        date.setTime(timeStamp);  
        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() {
	setTimeout(getRealViewer,3000);
	
	setInterval(getRealViewer,10000);
})()