console
端口 = '19730';
function Ranking() {
return {
"userRank": "",
"userName": "",
"contribution": ""
};
};
function Chat() {
return {
"userName": "",
"content": "",
"giftName": "",
"quantity": ""
};
};
var id = null;
var rankingCache = [
{ "userName": "", "contribution": "" },
{ "userName": "", "contribution": "" },
{ "userName": "", "contribution": "" },
{ "userName": "", "contribution": "" },
{ "userName": "", "contribution": "" },
];
var ikTok = {
Call: function () {
ikTok.GetChatList();
},
GetChatList: function () {
var div = document.querySelector('.webcast-chatroom___items');
if (!div) return;
for (var i in div) {
if (/__reactProps\$/g.test(i)) {
var __reactProps = i;
break;
}
};
if (!__reactProps) return;
var children = div.firstChild.children
, _length = children.length - 1;
for (var i = _length, f = false; children.length > 0 && children.length > i; i) {
if (!f) {
children[i].dataset.id == id || !i ? (f = true, i++) : i--;
} else {
var {
"content": content,
"comboCount": comboCount,
"gift": gift,
"user": user
} = children[i][__reactProps].children.props.message.payload;
var userName = !user ? "" : user.nickname
, giftName = !gift ? "" : gift.name
, quantity = !comboCount ? "" : String(comboCount.low);
content = content || "";
client.send(JSON.stringify({
"chat": {
"userName": userName,
"content": content,
"giftName": giftName,
"quantity": quantity
}
}));
i++;
}
}
id = children[_length].dataset.id;
}
};
var bilibili = {
url: "",
GetRankingList: function () {
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', bilibili.url, true);
httpRequest.send(null);
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
var json = JSON.parse(httpRequest.responseText).data.OnlineRankItem;
if (!json) return;
for (var i = 0; i < 5 && i < json.length; i++) {
var ranking = Ranking();
ranking.userRank = json[i].userRank;
ranking.userName = json[i].name;
ranking.contribution = String(json[i].score);
if (rankingCache[i]["userName"] != ranking.userName || rankingCache[i]["contribution"] != ranking.contribution) {
rankingCache[i]["userName"] = ranking.userName;
rankingCache[i]["contribution"] = ranking.contribution;
client.send(JSON.stringify({ "ranking": ranking }));
}
}
}
}
},
GetChatList: function () {
var div = document.querySelector('.chat-items');
if (!div) return;
var children = div.children
, _length = children.length - 1;
for (var i = _length, f = false; children.length > 0 && children.length > i; i) {
if (!f) {
!!children[i].id || !i ? (f = true, i++) : i--;
} else {
var chat = Chat();
if (children[i].classList[1] == "danmaku-item") {
chat.userName = children[i].dataset.uname;
chat.content = children[i].dataset.danmaku;
} else if (children[i].classList[1] == "gift-item") {
chat.quantity = (children[i].querySelector('.gift-count') || children[i].querySelector('.gift-total-count')).innerText.replace(/[^\d]/g, "") || "1";
chat.giftName = children[i].querySelector('.gift-name').innerText;
chat.userName = children[i].querySelector('.username').innerText;
}
if (!!chat.userName) client.send(JSON.stringify({ "chat": chat }));
i++;
}
}
div.lastElementChild.id = '5555555555';
}
};
var kwai = {
Call: function () {
kwai.GetChatList();
kwai.GetRankingList();
},
GetRankingList: function () {
var div = document.querySelector('.liveroom-sidebar.dark');
if (!div) return;
var computedWatchingList = div.childNodes[2].__vue__.computedWatchingList;
for (var i = 0; i < 5 && i < computedWatchingList.length; i++) {
var { "name": userName, "displayKsCoin": contribution } = computedWatchingList[i];
contribution = String(contribution || "");
if (rankingCache[i]["userName"] != userName || rankingCache[i]["contribution"] != contribution) {
rankingCache[i]["userName"] = userName;
rankingCache[i]["contribution"] = contribution;
var userRank = String(i + 1);
client.send(JSON.stringify({
"ranking": {
"userRank": userRank,
"userName": userName,
"contribution": String(contribution)
}
}));
}
}
},
GetChatList: function () {
var div = document.querySelector(".chat-container.chat-history-container");
if (!div) return;
var children = div.__vue__.$children
, _length = children.length - 1;
for (var i = _length, f = false; children.length > 0 && children.length > i; i) {
if (!f) {
children[i].item.__ob__.dep.id == id || !i ? (f = true, i++) : i--;
} else {
var {
"user": {
"userName": userName
},
"content": content,
"giftId": giftId,
"batchSize": quantity
} = children[i].item;
userName = userName || "";
quantity = quantity || "";
content = !content ? !giftId ? "点亮了" : "" : content;
var giftName = !giftId ? "" : children[i].allGift[giftId].giftName;
client.send(JSON.stringify({
"chat": {
"userName": userName,
"content": content,
"giftName": giftName,
"quantity": String(quantity)
}
}));
i++;
}
}
id = children[_length].item.__ob__.dep.id;
},
};
var timer_0 = null
, timer_1 = null
, client = new WebSocket('ws://localhost:' + 端口);
client.onopen = function (e) {
console.log('链接成功');
switch (document.body.baseURI.match(/https:\/\/.+?\//g)[0]) {
case 'https://live.douyin.com/':
console.log("平台:抖音");
timer_0 = self.setInterval('ikTok.Call()', 1000);
break;
case 'https://live.bilibili.com/':
console.log("平台:B站");
var urid = !__NEPTUNE_IS_MY_WAIFU__ ? __initialState["pc-follow-new"][0].uid : __NEPTUNE_IS_MY_WAIFU__.roomInitRes.data.uid
, roomId = !__NEPTUNE_IS_MY_WAIFU__ ? __initialState["live-non-revenue-player"][0].defaultRoomId : __NEPTUNE_IS_MY_WAIFU__.roomInitRes.data.room_id;
bilibili.url = 'https://api.live.bilibili.com/xlive/general-interface/v1/rank/getOnlineGoldRank?ruid=' + urid + '&roomId=' + roomId + '&page=1&pageSize=50';
timer_0 = self.setInterval('bilibili.GetChatList()', 1000);
timer_1 = self.setInterval('bilibili.GetRankingList()', 5000);
break;
case 'https://live.kuaishou.com/':
console.log("平台:快手");
timer_0 = self.setInterval('kwai.Call()', 1000);
break;
default:
client.close();
}
};
client.onclose = function (e) {
console.log('链接断开');
timer_0 = self.clearInterval(timer_0);
timer_1 = self.clearInterval(timer_1);
};
<html>
<head>
</head>
<body>
</body>
</html>