Last active
June 3, 2017 04:08
-
-
Save hcccc/bd73745ce876c55a920ceb30a925df43 to your computer and use it in GitHub Desktop.
bilibili_danmu.js
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
(function () { | |
const messageList = [ | |
'这是在哪里?', '非常棒', '抽奖小哥呢?', '小电视暗中观察', '为什么我还没中', | |
'我要当欧皇', '中了直播开机哦', '求奇迹出现', '呜呜呜不中啊'] | |
const roomId = window.location.href.match(/\.com\/(\d+)/)[1]; | |
const bilibiliSendDanmuPost = 'http://live.bilibili.com/msg/send'; | |
const secInHr = 1000 * 60 * 60; | |
const sendTiming = 1000 * 60 * 50; | |
var count = 0; | |
setInterval(function () { | |
if ((Date.now()) % secInHr > sendTiming) { | |
if (count < 10) { | |
var message = messageList[parseInt(Math.random() * (messageList.length - 1))] || '小米很棒!!'; | |
console.log('准备发送: ' + message); | |
$.post(bilibiliSendDanmuPost, { | |
color: 0xffffff.toString(), | |
fontsize: 25, | |
mode: 1, | |
msg: message, | |
rnd: window.DANMU_RND, | |
roomid: roomId, | |
}, (response) => { | |
var parsedResponse = JSON.parse(response); | |
if (parsedResponse.code == 0) { | |
console.info('发送成功'); | |
++count; | |
} | |
}) | |
} else { | |
count = 0; | |
} | |
} else { | |
var d = new Date(); | |
console.info('还没到时间!' + d.toString()); | |
} | |
}, 1000 * 60) | |
return '开始计时'; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment