逻辑优化
parent
d22a0acf1b
commit
ea7a0d2555
93
js/handle.js
93
js/handle.js
|
@ -77,21 +77,6 @@ function getFirstEventKeyword(name) {
|
|||
return event
|
||||
}
|
||||
|
||||
// 设置领舞 name=姓名 time=有效期 单位秒
|
||||
function setLeader(name, time) {
|
||||
sessionStorage.setItem('leader', name)
|
||||
sessionStorage.setItem('leader_end_at', (new Date).getTime()/1000 + time)
|
||||
}
|
||||
|
||||
// 获取领舞人信息
|
||||
function getLeader() {
|
||||
let res = []
|
||||
res['name'] = sessionStorage.getItem('leader') ? sessionStorage.getItem('leader') : ''
|
||||
res['time'] = sessionStorage.getItem('leader_end_at') ? sessionStorage.getItem('leader_end_at') : 0
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
function music() {
|
||||
$.get(musicUrl, function (res) {
|
||||
musicList = res
|
||||
|
@ -139,23 +124,37 @@ function delExpireDiv() {
|
|||
// 接受消息处理
|
||||
function receiveMessage(event)
|
||||
{
|
||||
// console.log(event.data, '接受弹幕')
|
||||
// 我们能信任信息来源吗?
|
||||
// 来源检测
|
||||
if (event.origin !== "https://live.bilibili.com") {
|
||||
return false
|
||||
}
|
||||
|
||||
// 解析消息
|
||||
let dataList = JSON.parse(event.data)
|
||||
// 弹幕消息
|
||||
let data = dataList.dm
|
||||
// 舰长
|
||||
let adminList = dataList.admin
|
||||
// 高能榜top3
|
||||
let highList = dataList.high
|
||||
// 房间号
|
||||
let roomId = dataList.roomId
|
||||
// 当前获取榜单类型 高能榜|大航海列表
|
||||
let activeType = dataList.activeType
|
||||
|
||||
// 目前硬编码大航海列表
|
||||
//
|
||||
// let highList = ['流域_墨绿绿'];
|
||||
// highList = ['内有猛犬小心'];
|
||||
// 保存高能榜
|
||||
if (activeType == 'high') {
|
||||
sessionStorage.setItem(roomId+':highList', dataList.high)
|
||||
}
|
||||
|
||||
// 保存大航海列表
|
||||
if (activeType == 'admin') {
|
||||
sessionStorage.setItem(roomId+':adminList', dataList.admin)
|
||||
}
|
||||
|
||||
// 舰长
|
||||
let adminList = sessionStorage.getItem(roomId+':adminList') ? sessionStorage.getItem(roomId+':adminList').split(',') : []
|
||||
// 高能榜top3
|
||||
let highList = sessionStorage.getItem(roomId+':highList') ? sessionStorage.getItem(roomId+':highList').split(',') : []
|
||||
|
||||
// console.log(adminList, '舰长列表')
|
||||
// console.log(highList, '高能榜列表')
|
||||
|
||||
if (data.length <= 0) {
|
||||
return false
|
||||
|
@ -166,62 +165,36 @@ function receiveMessage(event)
|
|||
return false
|
||||
}
|
||||
|
||||
// 领舞信息 目前为领舞名称
|
||||
let leaderInfo = ''
|
||||
|
||||
console.log(highList, '获取的高能榜单')
|
||||
// 高能榜列表
|
||||
// 高能榜第一位设为领舞
|
||||
if (highList.length > 0) {
|
||||
leaderInfo = highList[0]
|
||||
// 获取当前领舞人
|
||||
// let currentLeader = getLeader()
|
||||
// let now = (new Date).getTime()/1000
|
||||
// if (currentLeader['name'] === '') {
|
||||
// setLeader(highList[0], leaderTime)
|
||||
// } else {
|
||||
// //领舞人存在 检查过期时间
|
||||
// if (currentLeader['time'] === 0 || currentLeader['time'] < now) {
|
||||
// // 切换领舞
|
||||
|
||||
// // 当前领舞人
|
||||
// let leaderIndex = highList.indexOf(currentLeader['name'])
|
||||
// let newLeader
|
||||
// if (leaderIndex == -1) {
|
||||
// newLeader = highList[0]
|
||||
// } else {
|
||||
// let newIndex = leaderIndex + 1
|
||||
// if (newIndex >= highList.length) {
|
||||
// newIndex = 0
|
||||
// }
|
||||
// newLeader = highList[newIndex]
|
||||
// }
|
||||
|
||||
// setLeader(newLeader, leaderTime)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// uid是否存在 不存在则存入uidObj
|
||||
let isNew = 0
|
||||
// console.log(uidObj[data.uid],'uidObj[data.uid]');
|
||||
|
||||
// 最近发弹幕时间
|
||||
let speakTime = uidObj[data.uid];
|
||||
if (!speakTime) {
|
||||
isNew = 1
|
||||
} else if (autoDel && speakTime < parseInt(new Date().getTime()/1000) - speakExpireTime){
|
||||
//存在 但是最近弹幕时间已在过期时间外。
|
||||
//最近弹幕时间太久 则标注为新用户
|
||||
isNew = 1;
|
||||
}
|
||||
// 记录uid最近弹幕时间
|
||||
uidObj[data.uid] = data.ts
|
||||
|
||||
// 更新[记录]uid最近弹幕时间
|
||||
uidObj[data.uid] = data.ts
|
||||
|
||||
// custom.js中 每条弹幕的处理 放到了此处
|
||||
// -------------------- 每条弹幕处理 begin -----------------------
|
||||
// 获取领舞信息
|
||||
// let leaderInfo = sessionStorage.getItem('leader')
|
||||
|
||||
let eventName = getEvent(data.danmaku)
|
||||
let isLeader = data.uname == leaderInfo ? 1 : 0
|
||||
let isAdmin = adminList.indexOf(data.uname) == -1 ? 0 : 1
|
||||
// isAdmin = Math.floor(Math.random() * 30) //随机大宝剑
|
||||
let dm = {text: data.danmaku, uid: data.uid, uname: data.uname,
|
||||
event: eventName,
|
||||
is_new: isNew, is_admin: isAdmin, is_leader: isLeader,active_time: data.ts}
|
||||
|
@ -343,4 +316,6 @@ function receiveMessage(event)
|
|||
}
|
||||
|
||||
music();
|
||||
// 清理缓存
|
||||
sessionStorage.clear()
|
||||
window.addEventListener("message", receiveMessage, false);
|
Loading…
Reference in New Issue