-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
133 lines (111 loc) · 3.27 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>弹幕测试</title>
<style type="text/css">
html: {
height: 100%;
}
body{
height: 100%;
}
.barrage{
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow: hidden;
background: #ccc;
width: 900px;
}
.barrage-item{
position: absolute;
user-select: none;
white-space: nowrap;
display: inline-block;
text-shadow: #000 0 0 1px;
color: #fff;
font-size: 18px;
transition: transform 10s linear 0.1s;
}
.chat{
margin-left: 900px;
height: 510px;
padding-left: 20px;
position: relative;
}
.container{
position: absolute;
height: 510px;
width: 900px;
left: -920px;
}
.chat input {
width: 200px;
}
</style>
</head>
<body>
<div class="chat">
<div id="container" class="container"></div>
<div><input type="text" name="text" />
<button id="send">发送</button></div>
<div><input type="text" placeholder="哔哩哔哩房间ID" name="text" />
<button id="setRoomId">设置真实房间ID</button>
<button id="getRoomId">查看真实房间ID</button>
</div>
</div>
<p>相关博文:<a href="https://sobird.me/bilibili-live-barrage-websocket.htm">哔哩哔哩直播弹幕WebSocket协议编码解析</a></p>
<script type="text/javascript" src="barrager.js"></script>
<script type="text/javascript" src="https://unpkg.com/pako@2.0.3/dist/pako.min.js"></script>
<script type="text/javascript">
var roomId = getQuery('roomId') || 4350043;
var mockData = [
'666',
'喷子们气不气',
'卧槽,牛逼啊',
'这主播打的太菜了',
'人体描边大师',
'突然暴毙,哈哈哈~~',
'喜欢看的朋友记得点个关注哦',
'这谁顶的住啊',
'所谓富贵险中求',
'顶我上去',
'大吉大利,今晚吃鸡'
];
var barrager = new Barrager({
el: 'container'
});
// for (var i = 1; i < mockData.length; i++) {
// barrager.shoot(mockData[i]);
// }
var send = document.getElementById('send');
send.onclick = function() {
var text = document.getElementsByTagName('input')[0].value;
barrager.shoot(text);
}
var setRoomId = document.getElementById('setRoomId');
setRoomId.onclick = function() {
var roomId = document.getElementsByTagName('input')[1].value;
window.location.href = '?roomId=' + roomId;
}
var getRoomId = document.getElementById('getRoomId');
getRoomId.onclick = function() {
var roomId = document.getElementsByTagName('input')[1].value;
window.open('https://api.live.bilibili.com/room/v1/Room/room_init?id='+roomId);
}
function getQuery(variable){
let query = window.location.search.substring(1);
let vars = query.split("&");
for (let i=0;i<vars.length;i++) {
let pair = vars[i].split("=");
if(pair[0] == variable){return parseInt(pair[1]);}
}
return(false);
}
</script>
<script type="text/javascript" src="bilibili.js"></script>
</body>
</html>