Skip to content

Instantly share code, notes, and snippets.

@KaitoHH
Last active October 1, 2017 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KaitoHH/f26f43a7e698c5f5610996b2689149b8 to your computer and use it in GitHub Desktop.
Save KaitoHH/f26f43a7e698c5f5610996b2689149b8 to your computer and use it in GitHub Desktop.
count gift in douyu
// paste these code snippets into browser console of anyone of anchor and you will get live statistic of received gift
// some function can be used to adjust behaviour, see the code below
var giftCnt = {};
var msgMonitor;
var showTableFlag = true;
var req = require("shark/lang/observer").on("mod.chat.msg.msg", function(e) {
if (!e) return;
var msg = jQuery(e).find(".chat-msg-item").text();
var gift = jQuery(e).find(".gift-name").text();
var combo = jQuery(e).find(".hy-org").text();
var count = 1;
if (combo && combo.indexOf("连击") != -1) {
count = parseInt(combo);
if (count == 10) count--;
else if (combo % 10 == 0) count = 10;
}
if (gift.length == 0) gift = "other_msg";
if (msgMonitor && msg == msgMonitor) gift = msgMonitor;
if (giftCnt[gift] == undefined) {
giftCnt[gift] = count;
} else {
giftCnt[gift] += count;
}
if (showTableFlag) {
console.clear();
console.table(giftCnt);
}
});
function clearTable() {
Object.keys(giftCnt).forEach(function(k, i) {
giftCnt[k] = 0;
});
}
function showTable() {
showTableFlag = true;
}
function hideTable() {
showTableFlag = false;
}
function printTable() {
console.table(giftCnt);
}
function setMonitor(keyword) {
msgMonitor = keyword;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment