Last active
October 1, 2017 08:20
-
-
Save KaitoHH/f26f43a7e698c5f5610996b2689149b8 to your computer and use it in GitHub Desktop.
count gift in douyu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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