@xpadev-net/niconicomments 0.2.21 → 0.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +699 -568
- package/dist/dts/types.d.ts +208 -137
- package/package.json +25 -9
package/dist/bundle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
niconicomments.js v0.2.
|
|
2
|
+
niconicomments.js v0.2.22
|
|
3
3
|
(c) 2021 xpadev-net https://xpadev.net
|
|
4
4
|
Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -24,45 +24,80 @@
|
|
|
24
24
|
|
|
25
25
|
return _assign.apply(this, arguments);
|
|
26
26
|
};
|
|
27
|
+
function __spreadArray(to, from, pack) {
|
|
28
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
29
|
+
if (ar || !(i in from)) {
|
|
30
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
31
|
+
ar[i] = from[i];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
35
|
+
}
|
|
27
36
|
|
|
28
37
|
var typeGuard = {
|
|
29
38
|
formatted: {
|
|
30
39
|
comment: function (i) {
|
|
31
|
-
return typeVerify(i, [
|
|
40
|
+
return typeVerify(i, [
|
|
41
|
+
"id",
|
|
42
|
+
"vpos",
|
|
43
|
+
"content",
|
|
44
|
+
"date",
|
|
45
|
+
"date_usec",
|
|
46
|
+
"owner",
|
|
47
|
+
"premium",
|
|
48
|
+
"mail",
|
|
49
|
+
"user_id",
|
|
50
|
+
"layer",
|
|
51
|
+
]);
|
|
32
52
|
},
|
|
33
53
|
comments: function (i) {
|
|
34
54
|
if (typeof i !== "object")
|
|
35
55
|
return false;
|
|
36
|
-
for (var _i = 0,
|
|
37
|
-
var item =
|
|
56
|
+
for (var _i = 0, _a = i; _i < _a.length; _i++) {
|
|
57
|
+
var item = _a[_i];
|
|
38
58
|
if (!typeGuard.formatted.comment(item))
|
|
39
59
|
return false;
|
|
40
60
|
}
|
|
41
61
|
return true;
|
|
42
62
|
},
|
|
43
63
|
legacyComment: function (i) {
|
|
44
|
-
return typeVerify(i, [
|
|
64
|
+
return typeVerify(i, [
|
|
65
|
+
"id",
|
|
66
|
+
"vpos",
|
|
67
|
+
"content",
|
|
68
|
+
"date",
|
|
69
|
+
"owner",
|
|
70
|
+
"premium",
|
|
71
|
+
"mail",
|
|
72
|
+
]);
|
|
45
73
|
},
|
|
46
74
|
legacyComments: function (i) {
|
|
47
75
|
if (typeof i !== "object")
|
|
48
76
|
return false;
|
|
49
|
-
for (var _i = 0,
|
|
50
|
-
var item =
|
|
77
|
+
for (var _i = 0, _a = i; _i < _a.length; _i++) {
|
|
78
|
+
var item = _a[_i];
|
|
51
79
|
if (!typeGuard.formatted.legacyComment(item))
|
|
52
80
|
return false;
|
|
53
81
|
}
|
|
54
82
|
return true;
|
|
55
|
-
}
|
|
83
|
+
},
|
|
56
84
|
},
|
|
57
85
|
legacy: {
|
|
58
86
|
rawApiResponses: function (i) {
|
|
59
87
|
if (typeof i !== "object")
|
|
60
88
|
return false;
|
|
61
|
-
for (var _i = 0,
|
|
62
|
-
var itemWrapper =
|
|
63
|
-
for (var
|
|
64
|
-
var
|
|
65
|
-
|
|
89
|
+
for (var _i = 0, _a = i; _i < _a.length; _i++) {
|
|
90
|
+
var itemWrapper = _a[_i];
|
|
91
|
+
for (var _b = 0, _c = Object.keys(itemWrapper); _b < _c.length; _b++) {
|
|
92
|
+
var key = _c[_b];
|
|
93
|
+
var item = itemWrapper[key];
|
|
94
|
+
if (!item)
|
|
95
|
+
continue;
|
|
96
|
+
if (!(typeGuard.legacy.apiChat(item) ||
|
|
97
|
+
typeGuard.legacy.apiGlobalNumRes(item) ||
|
|
98
|
+
typeGuard.legacy.apiLeaf(item) ||
|
|
99
|
+
typeGuard.legacy.apiPing(item) ||
|
|
100
|
+
typeGuard.legacy.apiThread(item))) {
|
|
66
101
|
return false;
|
|
67
102
|
}
|
|
68
103
|
}
|
|
@@ -70,51 +105,87 @@
|
|
|
70
105
|
return true;
|
|
71
106
|
},
|
|
72
107
|
apiChat: function (i) {
|
|
73
|
-
return
|
|
108
|
+
return typeof i === "object" &&
|
|
109
|
+
typeVerify(i, [
|
|
110
|
+
"content",
|
|
111
|
+
"date",
|
|
112
|
+
"date_usec",
|
|
113
|
+
"no",
|
|
114
|
+
"thread",
|
|
115
|
+
"vpos",
|
|
116
|
+
]);
|
|
74
117
|
},
|
|
75
118
|
apiGlobalNumRes: function (i) {
|
|
76
119
|
return typeVerify(i, ["num_res", "thread"]);
|
|
77
120
|
},
|
|
78
|
-
apiLeaf: function (i) {
|
|
79
|
-
|
|
80
|
-
},
|
|
81
|
-
apiPing: function (i) {
|
|
82
|
-
return typeVerify(i, ["content"]);
|
|
83
|
-
},
|
|
121
|
+
apiLeaf: function (i) { return typeVerify(i, ["count", "thread"]); },
|
|
122
|
+
apiPing: function (i) { return typeVerify(i, ["content"]); },
|
|
84
123
|
apiThread: function (i) {
|
|
85
|
-
return typeVerify(i, [
|
|
124
|
+
return typeVerify(i, [
|
|
125
|
+
"resultcode",
|
|
126
|
+
"revision",
|
|
127
|
+
"server_time",
|
|
128
|
+
"thread",
|
|
129
|
+
"ticket",
|
|
130
|
+
]);
|
|
86
131
|
},
|
|
87
132
|
},
|
|
88
133
|
niconicome: {
|
|
89
134
|
xmlDocument: function (i) {
|
|
90
|
-
if (!i.documentElement ||
|
|
135
|
+
if (!i.documentElement ||
|
|
136
|
+
i.documentElement.nodeName !== "packet")
|
|
91
137
|
return false;
|
|
92
138
|
if (!i.documentElement.children)
|
|
93
139
|
return false;
|
|
94
|
-
for (var index
|
|
140
|
+
for (var index = 0; index < i.documentElement.children.length; index++) {
|
|
95
141
|
var value = i.documentElement.children[index];
|
|
96
|
-
if (
|
|
97
|
-
|
|
142
|
+
if (!value)
|
|
143
|
+
continue;
|
|
144
|
+
if (index === 0) {
|
|
145
|
+
if (value.nodeName !== "thread" ||
|
|
146
|
+
!typeAttributeVerify(value, [
|
|
147
|
+
"resultcode",
|
|
148
|
+
"thread",
|
|
149
|
+
"server_time",
|
|
150
|
+
"last_res",
|
|
151
|
+
"revision",
|
|
152
|
+
]))
|
|
98
153
|
return false;
|
|
99
154
|
}
|
|
100
155
|
else {
|
|
101
|
-
if (value.nodeName !== "chat" ||
|
|
156
|
+
if (value.nodeName !== "chat" ||
|
|
157
|
+
!typeAttributeVerify(value, [
|
|
158
|
+
"thread",
|
|
159
|
+
"no",
|
|
160
|
+
"vpos",
|
|
161
|
+
"date",
|
|
162
|
+
"date_usec",
|
|
163
|
+
"anonymity",
|
|
164
|
+
"user_id",
|
|
165
|
+
"mail",
|
|
166
|
+
"leaf",
|
|
167
|
+
"premium",
|
|
168
|
+
"score",
|
|
169
|
+
]))
|
|
102
170
|
return false;
|
|
103
171
|
}
|
|
104
172
|
}
|
|
105
173
|
return true;
|
|
106
|
-
}
|
|
174
|
+
},
|
|
107
175
|
},
|
|
108
176
|
legacyOwner: {
|
|
109
177
|
comments: function (i) {
|
|
178
|
+
if (typeof i !== "string")
|
|
179
|
+
return false;
|
|
110
180
|
var lists = i.split("\n");
|
|
111
|
-
for (var
|
|
181
|
+
for (var _i = 0, lists_1 = lists; _i < lists_1.length; _i++) {
|
|
182
|
+
var list = lists_1[_i];
|
|
112
183
|
if (list.split(":").length < 3) {
|
|
113
184
|
return false;
|
|
114
185
|
}
|
|
115
186
|
}
|
|
116
187
|
return true;
|
|
117
|
-
}
|
|
188
|
+
},
|
|
118
189
|
},
|
|
119
190
|
owner: {
|
|
120
191
|
comment: function (i) {
|
|
@@ -123,24 +194,38 @@
|
|
|
123
194
|
comments: function (i) {
|
|
124
195
|
if (typeof i !== "object")
|
|
125
196
|
return false;
|
|
126
|
-
for (var _i = 0,
|
|
127
|
-
var item =
|
|
197
|
+
for (var _i = 0, _a = i; _i < _a.length; _i++) {
|
|
198
|
+
var item = _a[_i];
|
|
128
199
|
if (!typeGuard.owner.comment(item))
|
|
129
200
|
return false;
|
|
130
201
|
}
|
|
131
202
|
return true;
|
|
132
|
-
}
|
|
203
|
+
},
|
|
133
204
|
},
|
|
134
205
|
v1: {
|
|
135
206
|
comment: function (i) {
|
|
136
|
-
return typeVerify(i, [
|
|
207
|
+
return typeVerify(i, [
|
|
208
|
+
"id",
|
|
209
|
+
"no",
|
|
210
|
+
"vposMs",
|
|
211
|
+
"body",
|
|
212
|
+
"commands",
|
|
213
|
+
"userId",
|
|
214
|
+
"isPremium",
|
|
215
|
+
"score",
|
|
216
|
+
"postedAt",
|
|
217
|
+
"nicoruCount",
|
|
218
|
+
"nicoruId",
|
|
219
|
+
"source",
|
|
220
|
+
"isMyPost",
|
|
221
|
+
]);
|
|
137
222
|
},
|
|
138
223
|
thread: function (i) {
|
|
139
224
|
if (!typeVerify(i, ["id", "fork", "commentCount", "comments"]))
|
|
140
225
|
return false;
|
|
141
|
-
for (var _i = 0, _a = i.comments; _i < _a.length; _i++) {
|
|
226
|
+
for (var _i = 0, _a = Object.keys(i.comments); _i < _a.length; _i++) {
|
|
142
227
|
var item = _a[_i];
|
|
143
|
-
if (!typeGuard.v1.comment(item))
|
|
228
|
+
if (!typeGuard.v1.comment(i.comments[item]))
|
|
144
229
|
return false;
|
|
145
230
|
}
|
|
146
231
|
return true;
|
|
@@ -148,24 +233,57 @@
|
|
|
148
233
|
threads: function (i) {
|
|
149
234
|
if (typeof i !== "object")
|
|
150
235
|
return false;
|
|
151
|
-
for (var _i = 0,
|
|
152
|
-
var item =
|
|
236
|
+
for (var _i = 0, _a = i; _i < _a.length; _i++) {
|
|
237
|
+
var item = _a[_i];
|
|
153
238
|
if (!typeGuard.v1.thread(item))
|
|
154
239
|
return false;
|
|
155
240
|
}
|
|
156
241
|
return true;
|
|
157
242
|
},
|
|
158
|
-
}
|
|
243
|
+
},
|
|
244
|
+
nicoScript: {
|
|
245
|
+
range: {
|
|
246
|
+
target: function (i) {
|
|
247
|
+
return typeof i === "string" && !!i.match(/^コメ|投コメ|全$/);
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
replace: {
|
|
251
|
+
range: function (i) {
|
|
252
|
+
return typeof i === "string" && !!i.match(/^単|全$/);
|
|
253
|
+
},
|
|
254
|
+
target: function (i) {
|
|
255
|
+
return typeof i === "string" && !!i.match(/^コメ|投コメ|全|含む|含まない$/);
|
|
256
|
+
},
|
|
257
|
+
condition: function (i) {
|
|
258
|
+
return typeof i === "string" && !!i.match(/^部分一致|完全一致$/);
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
comment: {
|
|
263
|
+
font: function (i) {
|
|
264
|
+
return typeof i === "string" && !!i.match(/^gothic|mincho|defont$/);
|
|
265
|
+
},
|
|
266
|
+
loc: function (i) {
|
|
267
|
+
return typeof i === "string" && !!i.match(/^ue|naka|shita$/);
|
|
268
|
+
},
|
|
269
|
+
size: function (i) {
|
|
270
|
+
return typeof i === "string" && !!i.match(/^big|medium|small$/);
|
|
271
|
+
},
|
|
272
|
+
},
|
|
159
273
|
};
|
|
160
274
|
var typeVerify = function (item, keys) {
|
|
275
|
+
if (typeof item !== "object" || !item)
|
|
276
|
+
return false;
|
|
161
277
|
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
162
278
|
var key = keys_1[_i];
|
|
163
|
-
if (item
|
|
279
|
+
if (!Object.prototype.hasOwnProperty.call(item, key))
|
|
164
280
|
return false;
|
|
165
281
|
}
|
|
166
282
|
return true;
|
|
167
283
|
};
|
|
168
284
|
var typeAttributeVerify = function (item, keys) {
|
|
285
|
+
if (typeof item !== "object" || !item)
|
|
286
|
+
return false;
|
|
169
287
|
for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
|
|
170
288
|
var key = keys_2[_i];
|
|
171
289
|
if (item.getAttribute(key) === null)
|
|
@@ -176,19 +294,19 @@
|
|
|
176
294
|
|
|
177
295
|
var convert2formattedComment = function (data, type) {
|
|
178
296
|
var result = [];
|
|
179
|
-
if (typeGuard.niconicome.xmlDocument(data)
|
|
297
|
+
if (type === "niconicome" && typeGuard.niconicome.xmlDocument(data)) {
|
|
180
298
|
result = fromNiconicome(data);
|
|
181
299
|
}
|
|
182
|
-
else if (typeGuard.formatted.legacyComments(data)
|
|
300
|
+
else if (type === "formatted" && typeGuard.formatted.legacyComments(data)) {
|
|
183
301
|
result = fromFormatted(data);
|
|
184
302
|
}
|
|
185
|
-
else if (typeGuard.legacy.rawApiResponses(data)
|
|
303
|
+
else if (type === "legacy" && typeGuard.legacy.rawApiResponses(data)) {
|
|
186
304
|
result = fromLegacy(data);
|
|
187
305
|
}
|
|
188
|
-
else if (typeGuard.owner.comments(data)
|
|
306
|
+
else if (type === "owner" && typeGuard.owner.comments(data)) {
|
|
189
307
|
result = fromOwner(data);
|
|
190
308
|
}
|
|
191
|
-
else if (typeGuard.v1.threads(data)
|
|
309
|
+
else if (type === "v1" && typeGuard.v1.threads(data)) {
|
|
192
310
|
result = fromV1(data);
|
|
193
311
|
}
|
|
194
312
|
else {
|
|
@@ -197,9 +315,10 @@
|
|
|
197
315
|
return sort(result);
|
|
198
316
|
};
|
|
199
317
|
var fromNiconicome = function (data) {
|
|
318
|
+
var _a;
|
|
200
319
|
var data_ = [], userList = [];
|
|
201
|
-
for (var _i = 0,
|
|
202
|
-
var item =
|
|
320
|
+
for (var _i = 0, _b = Array.from(data.documentElement.children); _i < _b.length; _i++) {
|
|
321
|
+
var item = _b[_i];
|
|
203
322
|
if (item.nodeName !== "chat")
|
|
204
323
|
continue;
|
|
205
324
|
var tmpParam = {
|
|
@@ -212,18 +331,19 @@
|
|
|
212
331
|
premium: item.getAttribute("premium") === "1",
|
|
213
332
|
mail: [],
|
|
214
333
|
user_id: -1,
|
|
215
|
-
layer: -1
|
|
334
|
+
layer: -1,
|
|
216
335
|
};
|
|
217
336
|
if (item.getAttribute("mail")) {
|
|
218
|
-
tmpParam.mail = item.getAttribute("mail").split(
|
|
337
|
+
tmpParam.mail = ((_a = item.getAttribute("mail")) === null || _a === void 0 ? void 0 : _a.split(/\s+/g)) || [];
|
|
219
338
|
}
|
|
220
339
|
if (tmpParam.content.startsWith("/") && tmpParam.owner) {
|
|
221
340
|
tmpParam.mail.push("invisible");
|
|
222
341
|
}
|
|
223
|
-
var
|
|
342
|
+
var userId = item.getAttribute("user_id") || "";
|
|
343
|
+
var isUserExist = userList.indexOf(userId);
|
|
224
344
|
if (isUserExist === -1) {
|
|
225
345
|
tmpParam.user_id = userList.length;
|
|
226
|
-
userList.push(
|
|
346
|
+
userList.push(userId);
|
|
227
347
|
}
|
|
228
348
|
else {
|
|
229
349
|
tmpParam.user_id = isUserExist;
|
|
@@ -235,11 +355,12 @@
|
|
|
235
355
|
var fromFormatted = function (data) {
|
|
236
356
|
var tmpData = data;
|
|
237
357
|
if (!typeGuard.formatted.comments(data)) {
|
|
238
|
-
for (var
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
358
|
+
for (var _i = 0, tmpData_1 = tmpData; _i < tmpData_1.length; _i++) {
|
|
359
|
+
var item = tmpData_1[_i];
|
|
360
|
+
item.layer = -1;
|
|
361
|
+
item.user_id = 0;
|
|
362
|
+
if (!item.date_usec)
|
|
363
|
+
item.date_usec = 0;
|
|
243
364
|
}
|
|
244
365
|
}
|
|
245
366
|
return tmpData;
|
|
@@ -248,78 +369,79 @@
|
|
|
248
369
|
var data_ = [], userList = [];
|
|
249
370
|
for (var i = 0; i < data.length; i++) {
|
|
250
371
|
var val = data[i];
|
|
251
|
-
if (!val)
|
|
372
|
+
if (!val || !typeGuard.legacy.apiChat(val === null || val === void 0 ? void 0 : val.chat))
|
|
252
373
|
continue;
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
tmpParam.user_id = isUserExist;
|
|
281
|
-
}
|
|
282
|
-
data_.push(tmpParam);
|
|
374
|
+
var value = val.chat;
|
|
375
|
+
if (value.deleted !== 1) {
|
|
376
|
+
var tmpParam = {
|
|
377
|
+
id: value.no,
|
|
378
|
+
vpos: value.vpos,
|
|
379
|
+
content: value.content,
|
|
380
|
+
date: value.date,
|
|
381
|
+
date_usec: value.date_usec || 0,
|
|
382
|
+
owner: !value.user_id,
|
|
383
|
+
premium: value.premium === 1,
|
|
384
|
+
mail: [],
|
|
385
|
+
user_id: -1,
|
|
386
|
+
layer: -1,
|
|
387
|
+
};
|
|
388
|
+
if (value.mail) {
|
|
389
|
+
tmpParam.mail = value.mail.split(/\s+/g);
|
|
390
|
+
}
|
|
391
|
+
if (value.content.startsWith("/") && !value.user_id) {
|
|
392
|
+
tmpParam.mail.push("invisible");
|
|
393
|
+
}
|
|
394
|
+
var isUserExist = userList.indexOf(value.mail);
|
|
395
|
+
if (isUserExist === -1) {
|
|
396
|
+
tmpParam.user_id = userList.length;
|
|
397
|
+
userList.push(value.user_id);
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
tmpParam.user_id = isUserExist;
|
|
283
401
|
}
|
|
402
|
+
data_.push(tmpParam);
|
|
284
403
|
}
|
|
285
404
|
}
|
|
286
405
|
return data_;
|
|
287
406
|
};
|
|
288
407
|
var fromOwner = function (data) {
|
|
289
408
|
var data_ = [];
|
|
290
|
-
|
|
291
|
-
var value = data[i];
|
|
409
|
+
data.forEach(function (value, index) {
|
|
292
410
|
var tmpParam = {
|
|
293
|
-
id:
|
|
411
|
+
id: index,
|
|
294
412
|
vpos: time2vpos(value.time),
|
|
295
413
|
content: value.comment,
|
|
296
|
-
date:
|
|
414
|
+
date: index,
|
|
297
415
|
date_usec: 0,
|
|
298
416
|
owner: true,
|
|
299
417
|
premium: true,
|
|
300
418
|
mail: [],
|
|
301
419
|
user_id: -1,
|
|
302
|
-
layer: -1
|
|
420
|
+
layer: -1,
|
|
303
421
|
};
|
|
304
422
|
if (value.command) {
|
|
305
|
-
tmpParam.mail = value.command.split(
|
|
423
|
+
tmpParam.mail = value.command.split(/\s+/g);
|
|
306
424
|
}
|
|
307
425
|
if (tmpParam.content.startsWith("/")) {
|
|
308
426
|
tmpParam.mail.push("invisible");
|
|
309
427
|
}
|
|
310
428
|
data_.push(tmpParam);
|
|
311
|
-
}
|
|
429
|
+
});
|
|
312
430
|
return data_;
|
|
313
431
|
};
|
|
314
432
|
var fromV1 = function (data) {
|
|
315
433
|
var data_ = [], userList = [];
|
|
316
|
-
for (var
|
|
317
|
-
var
|
|
318
|
-
|
|
434
|
+
for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {
|
|
435
|
+
var item = data_1[_i];
|
|
436
|
+
var val = item.comments, forkName = item.fork;
|
|
437
|
+
for (var _a = 0, _b = Object.keys(val); _a < _b.length; _a++) {
|
|
438
|
+
var key = _b[_a];
|
|
319
439
|
var value = val[key];
|
|
440
|
+
if (!value)
|
|
441
|
+
continue;
|
|
320
442
|
var tmpParam = {
|
|
321
443
|
id: value.no,
|
|
322
|
-
vpos: Math.floor(value.vposMs
|
|
444
|
+
vpos: Math.floor(value.vposMs / 10),
|
|
323
445
|
content: value.body,
|
|
324
446
|
date: date2time(value.postedAt),
|
|
325
447
|
date_usec: 0,
|
|
@@ -327,7 +449,7 @@
|
|
|
327
449
|
premium: value.isPremium,
|
|
328
450
|
mail: value.commands,
|
|
329
451
|
user_id: -1,
|
|
330
|
-
layer: -1
|
|
452
|
+
layer: -1,
|
|
331
453
|
};
|
|
332
454
|
if (tmpParam.content.startsWith("/") && tmpParam.owner) {
|
|
333
455
|
tmpParam.mail.push("invisible");
|
|
@@ -366,14 +488,18 @@
|
|
|
366
488
|
var time2vpos = function (time_str) {
|
|
367
489
|
var time = time_str.match(/^(\d+):(\d+)\.(\d+)|(\d+):(\d+)|(\d+)\.(\d+)|(\d+)$/);
|
|
368
490
|
if (time) {
|
|
369
|
-
if (time[1] !== undefined &&
|
|
370
|
-
|
|
491
|
+
if (time[1] !== undefined &&
|
|
492
|
+
time[2] !== undefined &&
|
|
493
|
+
time[3] !== undefined) {
|
|
494
|
+
return ((Number(time[1]) * 60 + Number(time[2])) * 100 +
|
|
495
|
+
Number(time[3]) / Math.pow(10, time[3].length - 2));
|
|
371
496
|
}
|
|
372
497
|
else if (time[4] !== undefined && time[5] !== undefined) {
|
|
373
498
|
return (Number(time[4]) * 60 + Number(time[5])) * 100;
|
|
374
499
|
}
|
|
375
500
|
else if (time[6] !== undefined && time[7] !== undefined) {
|
|
376
|
-
return Number(time[6]) * 100 +
|
|
501
|
+
return (Number(time[6]) * 100 +
|
|
502
|
+
Number(time[7]) / Math.pow(10, time[7].length - 2));
|
|
377
503
|
}
|
|
378
504
|
else if (time[8] !== undefined) {
|
|
379
505
|
return Number(time[8]) * 100;
|
|
@@ -385,24 +511,94 @@
|
|
|
385
511
|
return Math.floor(new Date(date).getTime() / 1000);
|
|
386
512
|
};
|
|
387
513
|
|
|
514
|
+
var colors = {
|
|
515
|
+
white: "#FFFFFF",
|
|
516
|
+
red: "#FF0000",
|
|
517
|
+
pink: "#FF8080",
|
|
518
|
+
orange: "#FFC000",
|
|
519
|
+
yellow: "#FFFF00",
|
|
520
|
+
green: "#00FF00",
|
|
521
|
+
cyan: "#00FFFF",
|
|
522
|
+
blue: "#0000FF",
|
|
523
|
+
purple: "#C000FF",
|
|
524
|
+
black: "#000000",
|
|
525
|
+
white2: "#CCCC99",
|
|
526
|
+
niconicowhite: "#CCCC99",
|
|
527
|
+
red2: "#CC0033",
|
|
528
|
+
truered: "#CC0033",
|
|
529
|
+
pink2: "#FF33CC",
|
|
530
|
+
orange2: "#FF6600",
|
|
531
|
+
passionorange: "#FF6600",
|
|
532
|
+
yellow2: "#999900",
|
|
533
|
+
madyellow: "#999900",
|
|
534
|
+
green2: "#00CC66",
|
|
535
|
+
elementalgreen: "#00CC66",
|
|
536
|
+
cyan2: "#00CCCC",
|
|
537
|
+
blue2: "#3399FF",
|
|
538
|
+
marinblue: "#3399FF",
|
|
539
|
+
purple2: "#6633CC",
|
|
540
|
+
nobleviolet: "#6633CC",
|
|
541
|
+
black2: "#666666",
|
|
542
|
+
};
|
|
543
|
+
var commentYPaddingTop = 0.08;
|
|
544
|
+
var commentYMarginBottom = 0.24;
|
|
545
|
+
var fontSize = {
|
|
546
|
+
small: {
|
|
547
|
+
default: 47,
|
|
548
|
+
resized: 26.1,
|
|
549
|
+
},
|
|
550
|
+
medium: {
|
|
551
|
+
default: 74,
|
|
552
|
+
resized: 38.7,
|
|
553
|
+
},
|
|
554
|
+
big: {
|
|
555
|
+
default: 110,
|
|
556
|
+
resized: 61,
|
|
557
|
+
},
|
|
558
|
+
};
|
|
559
|
+
var lineHeight = {
|
|
560
|
+
small: {
|
|
561
|
+
default: 1,
|
|
562
|
+
resized: 1,
|
|
563
|
+
},
|
|
564
|
+
medium: {
|
|
565
|
+
default: 1,
|
|
566
|
+
resized: 1,
|
|
567
|
+
},
|
|
568
|
+
big: {
|
|
569
|
+
default: 1.03,
|
|
570
|
+
resized: 1.01,
|
|
571
|
+
},
|
|
572
|
+
};
|
|
573
|
+
var doubleResizeMaxWidth = {
|
|
574
|
+
full: {
|
|
575
|
+
legacy: 3020,
|
|
576
|
+
default: 3550,
|
|
577
|
+
},
|
|
578
|
+
normal: {
|
|
579
|
+
legacy: 2540,
|
|
580
|
+
default: 2650,
|
|
581
|
+
},
|
|
582
|
+
};
|
|
583
|
+
var defaultOptions = {
|
|
584
|
+
drawAllImageOnLoad: false,
|
|
585
|
+
format: "default",
|
|
586
|
+
formatted: false,
|
|
587
|
+
debug: false,
|
|
588
|
+
enableLegacyPiP: false,
|
|
589
|
+
keepCA: false,
|
|
590
|
+
showCollision: false,
|
|
591
|
+
showCommentCount: false,
|
|
592
|
+
showFPS: false,
|
|
593
|
+
useLegacy: false,
|
|
594
|
+
video: undefined,
|
|
595
|
+
};
|
|
596
|
+
|
|
388
597
|
var isDebug = false;
|
|
389
598
|
var NiconiComments = (function () {
|
|
390
599
|
function NiconiComments(canvas, data, initOptions) {
|
|
391
600
|
if (initOptions === void 0) { initOptions = {}; }
|
|
392
601
|
var _this = this;
|
|
393
|
-
var defaultOptions = {
|
|
394
|
-
drawAllImageOnLoad: false,
|
|
395
|
-
format: "default",
|
|
396
|
-
formatted: false,
|
|
397
|
-
debug: false,
|
|
398
|
-
enableLegacyPiP: false,
|
|
399
|
-
keepCA: false,
|
|
400
|
-
showCollision: false,
|
|
401
|
-
showCommentCount: false,
|
|
402
|
-
showFPS: false,
|
|
403
|
-
useLegacy: false,
|
|
404
|
-
video: null,
|
|
405
|
-
};
|
|
406
602
|
var options = Object.assign(defaultOptions, initOptions);
|
|
407
603
|
isDebug = options.debug;
|
|
408
604
|
var constructorStart = performance.now();
|
|
@@ -415,46 +611,6 @@
|
|
|
415
611
|
this.context.textAlign = "start";
|
|
416
612
|
this.context.textBaseline = "alphabetic";
|
|
417
613
|
this.context.lineWidth = 4;
|
|
418
|
-
this.commentYPaddingTop = 0.08;
|
|
419
|
-
this.commentYMarginBottom = 0.24;
|
|
420
|
-
this.fontSize = {
|
|
421
|
-
"small": {
|
|
422
|
-
"default": 47,
|
|
423
|
-
"resized": 26.1
|
|
424
|
-
},
|
|
425
|
-
"medium": {
|
|
426
|
-
"default": 74,
|
|
427
|
-
"resized": 38.7
|
|
428
|
-
},
|
|
429
|
-
"big": {
|
|
430
|
-
"default": 110,
|
|
431
|
-
"resized": 61
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
this.lineHeight = {
|
|
435
|
-
"small": {
|
|
436
|
-
"default": 1,
|
|
437
|
-
"resized": 1
|
|
438
|
-
},
|
|
439
|
-
"medium": {
|
|
440
|
-
"default": 1,
|
|
441
|
-
"resized": 1
|
|
442
|
-
},
|
|
443
|
-
"big": {
|
|
444
|
-
"default": 1.03,
|
|
445
|
-
"resized": 1.01
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
this.doubleResizeMaxWidth = {
|
|
449
|
-
full: {
|
|
450
|
-
legacy: 3020,
|
|
451
|
-
default: 3550
|
|
452
|
-
},
|
|
453
|
-
normal: {
|
|
454
|
-
legacy: 2540,
|
|
455
|
-
default: 2650
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
614
|
var formatType = options.format;
|
|
459
615
|
if (options.formatted) {
|
|
460
616
|
console.warn("Deprecated: options.formatted is no longer recommended. Please use options.format");
|
|
@@ -463,7 +619,7 @@
|
|
|
463
619
|
formatType = options.formatted ? "formatted" : "legacy";
|
|
464
620
|
}
|
|
465
621
|
var parsedData = convert2formattedComment(data, formatType);
|
|
466
|
-
this.video = options.video
|
|
622
|
+
this.video = options.video || undefined;
|
|
467
623
|
this.showCollision = options.showCollision;
|
|
468
624
|
this.showFPS = options.showFPS;
|
|
469
625
|
this.showCommentCount = options.showCommentCount;
|
|
@@ -471,10 +627,10 @@
|
|
|
471
627
|
this.keepCA = options.keepCA;
|
|
472
628
|
this.timeline = {};
|
|
473
629
|
this.nicoScripts = { reverse: [], default: [], replace: [], ban: [] };
|
|
474
|
-
this.
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
630
|
+
this.collision = ["ue", "shita", "right", "left"].reduce(function (pv, value) {
|
|
631
|
+
pv[value] = [];
|
|
632
|
+
return pv;
|
|
633
|
+
}, {});
|
|
478
634
|
this.data = [];
|
|
479
635
|
this.lastVpos = -1;
|
|
480
636
|
this.useLegacy = options.useLegacy;
|
|
@@ -488,6 +644,7 @@
|
|
|
488
644
|
logger("constructor complete: ".concat(performance.now() - constructorStart, "ms"));
|
|
489
645
|
}
|
|
490
646
|
NiconiComments.prototype.preRendering = function (rawData, drawAll) {
|
|
647
|
+
var _this = this;
|
|
491
648
|
var preRenderingStart = performance.now();
|
|
492
649
|
if (this.keepCA) {
|
|
493
650
|
rawData = changeCALayer(rawData);
|
|
@@ -495,34 +652,35 @@
|
|
|
495
652
|
var parsedData = this.getCommentPos(this.getCommentSize(this.getFont(rawData)));
|
|
496
653
|
this.data = this.sortComment(parsedData);
|
|
497
654
|
if (drawAll) {
|
|
498
|
-
|
|
499
|
-
this.getTextImage(Number(i), true);
|
|
500
|
-
}
|
|
655
|
+
parsedData.forEach(function (_, key) { return _this.getTextImage(Number(key), true); });
|
|
501
656
|
}
|
|
502
657
|
logger("preRendering complete: ".concat(performance.now() - preRenderingStart, "ms"));
|
|
503
658
|
};
|
|
504
659
|
NiconiComments.prototype.getFont = function (parsedData) {
|
|
505
660
|
var getFontStart = performance.now();
|
|
506
661
|
var result = [];
|
|
507
|
-
for (var
|
|
508
|
-
var value =
|
|
509
|
-
if (!value)
|
|
510
|
-
continue;
|
|
662
|
+
for (var _i = 0, parsedData_1 = parsedData; _i < parsedData_1.length; _i++) {
|
|
663
|
+
var value = parsedData_1[_i];
|
|
511
664
|
value.content = value.content.replace(/\t/g, "\u2003\u2003");
|
|
512
|
-
result
|
|
665
|
+
result.push(this.parseCommandAndNicoscript(value));
|
|
513
666
|
}
|
|
514
667
|
logger("getFont complete: ".concat(performance.now() - getFontStart, "ms"));
|
|
515
668
|
return result;
|
|
516
669
|
};
|
|
517
670
|
NiconiComments.prototype.getCommentSize = function (parsedData) {
|
|
518
671
|
var getCommentSizeStart = performance.now();
|
|
519
|
-
var
|
|
672
|
+
var groupedData = groupBy(parsedData);
|
|
520
673
|
var result = [];
|
|
521
|
-
for (var
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
674
|
+
for (var _i = 0, _a = Object.keys(groupedData); _i < _a.length; _i++) {
|
|
675
|
+
var font = _a[_i];
|
|
676
|
+
for (var _b = 0, _c = Object.keys(groupedData[font]); _b < _c.length; _b++) {
|
|
677
|
+
var fontSize_1 = _c[_b];
|
|
678
|
+
var value = groupedData[font][fontSize_1];
|
|
679
|
+
if (!value)
|
|
680
|
+
continue;
|
|
681
|
+
this.context.font = parseFont(font, fontSize_1, this.useLegacy);
|
|
682
|
+
for (var _d = 0, value_1 = value; _d < value_1.length; _d++) {
|
|
683
|
+
var comment = value_1[_d];
|
|
526
684
|
if (comment.invisible) {
|
|
527
685
|
continue;
|
|
528
686
|
}
|
|
@@ -535,7 +693,7 @@
|
|
|
535
693
|
size.lineHeight = measure.lineHeight;
|
|
536
694
|
if (measure.resized) {
|
|
537
695
|
size.fontSize = measure.fontSize;
|
|
538
|
-
this.context.font = parseFont(
|
|
696
|
+
this.context.font = parseFont(font, fontSize_1, this.useLegacy);
|
|
539
697
|
}
|
|
540
698
|
result[comment.index] = size;
|
|
541
699
|
}
|
|
@@ -544,207 +702,161 @@
|
|
|
544
702
|
logger("getCommentSize complete: ".concat(performance.now() - getCommentSizeStart, "ms"));
|
|
545
703
|
return result;
|
|
546
704
|
};
|
|
547
|
-
NiconiComments.prototype.getCommentPos = function (
|
|
705
|
+
NiconiComments.prototype.getCommentPos = function (data) {
|
|
706
|
+
var _this = this;
|
|
548
707
|
var getCommentPosStart = performance.now();
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
for (var j = 0; j < comment.long * 4 / 3 + 100; j++) {
|
|
556
|
-
if (!this.timeline[comment.vpos + j]) {
|
|
557
|
-
this.timeline[comment.vpos + j] = [];
|
|
708
|
+
data.forEach(function (comment, index) {
|
|
709
|
+
if (comment.invisible)
|
|
710
|
+
return;
|
|
711
|
+
for (var j = 0; j < (comment.long * 4) / 3 + 100; j++) {
|
|
712
|
+
if (!_this.timeline[comment.vpos + j]) {
|
|
713
|
+
_this.timeline[comment.vpos + j] = [];
|
|
558
714
|
}
|
|
559
|
-
if (!
|
|
560
|
-
|
|
715
|
+
if (!_this.collision.right[comment.vpos + j]) {
|
|
716
|
+
_this.collision.right[comment.vpos + j] = [];
|
|
561
717
|
}
|
|
562
|
-
if (!
|
|
563
|
-
|
|
718
|
+
if (!_this.collision.left[comment.vpos + j]) {
|
|
719
|
+
_this.collision.left[comment.vpos + j] = [];
|
|
564
720
|
}
|
|
565
|
-
if (!
|
|
566
|
-
|
|
721
|
+
if (!_this.collision.ue[comment.vpos + j]) {
|
|
722
|
+
_this.collision.ue[comment.vpos + j] = [];
|
|
567
723
|
}
|
|
568
|
-
if (!
|
|
569
|
-
|
|
724
|
+
if (!_this.collision.shita[comment.vpos + j]) {
|
|
725
|
+
_this.collision.shita[comment.vpos + j] = [];
|
|
570
726
|
}
|
|
571
727
|
}
|
|
572
728
|
if (comment.loc === "naka") {
|
|
573
|
-
var posY = 0,
|
|
729
|
+
var posY = 0, isBreak = false, isChanged = true, count = 0;
|
|
730
|
+
var beforeVpos = Math.round(-240 / ((1680 + comment.width_max) / (comment.long + 125))) - 100;
|
|
574
731
|
if (1080 < comment.height) {
|
|
575
732
|
posY = (comment.height - 1080) / -2;
|
|
576
733
|
}
|
|
577
734
|
else {
|
|
578
|
-
while (
|
|
579
|
-
|
|
735
|
+
while (isChanged && count < 10) {
|
|
736
|
+
isChanged = false;
|
|
580
737
|
count++;
|
|
581
738
|
for (var j = beforeVpos; j < comment.long; j++) {
|
|
582
739
|
var vpos = comment.vpos + j;
|
|
583
|
-
var left_pos = 1680 - (1680 + comment.width_max) / (comment.long + 125) * j;
|
|
740
|
+
var left_pos = 1680 - ((1680 + comment.width_max) / (comment.long + 125)) * j;
|
|
584
741
|
if (left_pos + comment.width_max >= 1880) {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
is_change = true;
|
|
591
|
-
}
|
|
592
|
-
if (posY + comment.height > 1080) {
|
|
593
|
-
if (1080 < comment.height) {
|
|
594
|
-
posY = (comment.height - 1080) / -2;
|
|
595
|
-
}
|
|
596
|
-
else {
|
|
597
|
-
posY = Math.floor(Math.random() * (1080 - comment.height));
|
|
598
|
-
}
|
|
599
|
-
is_break = true;
|
|
600
|
-
break;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
if (is_break) {
|
|
742
|
+
var result = getPosY(posY, comment, _this.collision.right[vpos], data);
|
|
743
|
+
posY = result.currentPos;
|
|
744
|
+
isChanged = result.isChanged;
|
|
745
|
+
isBreak = result.isBreak;
|
|
746
|
+
if (isBreak)
|
|
605
747
|
break;
|
|
606
|
-
}
|
|
607
748
|
}
|
|
608
749
|
if (left_pos <= 40) {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
is_change = true;
|
|
615
|
-
}
|
|
616
|
-
if (posY + comment.height > 1080) {
|
|
617
|
-
if (1080 < comment.height) {
|
|
618
|
-
posY = 0;
|
|
619
|
-
}
|
|
620
|
-
else {
|
|
621
|
-
posY = Math.random() * (1080 - comment.height);
|
|
622
|
-
}
|
|
623
|
-
is_break = true;
|
|
624
|
-
break;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
if (is_break) {
|
|
750
|
+
var result = getPosY(posY, comment, _this.collision.left[vpos], data);
|
|
751
|
+
posY = result.currentPos;
|
|
752
|
+
isChanged = result.isChanged;
|
|
753
|
+
isBreak = result.isBreak;
|
|
754
|
+
if (isBreak)
|
|
629
755
|
break;
|
|
630
|
-
}
|
|
631
756
|
}
|
|
632
757
|
}
|
|
633
|
-
if (
|
|
758
|
+
if (isBreak) {
|
|
634
759
|
break;
|
|
635
760
|
}
|
|
636
761
|
}
|
|
637
762
|
}
|
|
638
763
|
for (var j = beforeVpos; j < comment.long + 125; j++) {
|
|
639
764
|
var vpos = comment.vpos + j;
|
|
640
|
-
var left_pos = 1680 - (1680 + comment.width_max) / (comment.long + 125) * j;
|
|
641
|
-
arrayPush(
|
|
765
|
+
var left_pos = 1680 - ((1680 + comment.width_max) / (comment.long + 125)) * j;
|
|
766
|
+
arrayPush(_this.timeline, vpos, index);
|
|
642
767
|
if (left_pos + comment.width_max >= 1880) {
|
|
643
|
-
arrayPush(
|
|
768
|
+
arrayPush(_this.collision.right, vpos, index);
|
|
644
769
|
}
|
|
645
770
|
if (left_pos <= 40) {
|
|
646
|
-
arrayPush(
|
|
771
|
+
arrayPush(_this.collision.left, vpos, index);
|
|
647
772
|
}
|
|
648
773
|
}
|
|
649
|
-
|
|
774
|
+
comment.posY = posY;
|
|
650
775
|
}
|
|
651
776
|
else {
|
|
652
|
-
var posY = 0,
|
|
777
|
+
var posY = 0, isChanged = true, count = 0, collision = void 0;
|
|
653
778
|
if (comment.loc === "ue") {
|
|
654
|
-
collision =
|
|
779
|
+
collision = _this.collision.ue;
|
|
655
780
|
}
|
|
656
|
-
else
|
|
657
|
-
collision =
|
|
781
|
+
else {
|
|
782
|
+
collision = _this.collision.shita;
|
|
658
783
|
}
|
|
659
|
-
while (
|
|
660
|
-
|
|
784
|
+
while (isChanged && count < 10) {
|
|
785
|
+
isChanged = false;
|
|
661
786
|
count++;
|
|
662
787
|
for (var j = 0; j < comment.long; j++) {
|
|
663
|
-
var
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
if (data[l].posY + data[l].height > posY) {
|
|
668
|
-
posY = data[l].posY + data[l].height;
|
|
669
|
-
is_change = true;
|
|
670
|
-
}
|
|
671
|
-
if (posY + comment.height > 1080) {
|
|
672
|
-
if (1000 <= comment.height) {
|
|
673
|
-
posY = 0;
|
|
674
|
-
}
|
|
675
|
-
else {
|
|
676
|
-
posY = Math.floor(Math.random() * (1080 - comment.height));
|
|
677
|
-
}
|
|
678
|
-
is_break = true;
|
|
679
|
-
break;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
if (is_break) {
|
|
788
|
+
var result = getPosY(posY, comment, collision[comment.vpos + j], data);
|
|
789
|
+
posY = result.currentPos;
|
|
790
|
+
isChanged = result.isChanged;
|
|
791
|
+
if (result.isBreak)
|
|
684
792
|
break;
|
|
685
|
-
}
|
|
686
793
|
}
|
|
687
794
|
}
|
|
688
795
|
for (var j = 0; j < comment.long; j++) {
|
|
689
796
|
var vpos = comment.vpos + j;
|
|
690
|
-
arrayPush(
|
|
797
|
+
arrayPush(_this.timeline, vpos, index);
|
|
798
|
+
if (j > comment.long - 20)
|
|
799
|
+
continue;
|
|
691
800
|
if (comment.loc === "ue") {
|
|
692
|
-
arrayPush(
|
|
801
|
+
arrayPush(_this.collision.ue, vpos, index);
|
|
693
802
|
}
|
|
694
803
|
else {
|
|
695
|
-
arrayPush(
|
|
804
|
+
arrayPush(_this.collision.shita, vpos, index);
|
|
696
805
|
}
|
|
697
806
|
}
|
|
698
|
-
|
|
807
|
+
comment.posY = posY;
|
|
699
808
|
}
|
|
700
|
-
}
|
|
809
|
+
});
|
|
701
810
|
logger("getCommentPos complete: ".concat(performance.now() - getCommentPosStart, "ms"));
|
|
702
|
-
return
|
|
811
|
+
return data;
|
|
703
812
|
};
|
|
704
813
|
NiconiComments.prototype.sortComment = function (parsedData) {
|
|
814
|
+
var _a;
|
|
705
815
|
var sortCommentStart = performance.now();
|
|
706
|
-
for (var
|
|
707
|
-
|
|
816
|
+
for (var _i = 0, _b = Object.keys(this.timeline); _i < _b.length; _i++) {
|
|
817
|
+
var vpos = _b[_i];
|
|
818
|
+
var item = this.timeline[Number(vpos)];
|
|
819
|
+
if (!item)
|
|
708
820
|
continue;
|
|
709
821
|
var owner = [], user = [];
|
|
710
|
-
for (var
|
|
711
|
-
var
|
|
712
|
-
if (parsedData[
|
|
713
|
-
owner.push(
|
|
822
|
+
for (var _c = 0, item_1 = item; _c < item_1.length; _c++) {
|
|
823
|
+
var index = item_1[_c];
|
|
824
|
+
if ((_a = parsedData[index]) === null || _a === void 0 ? void 0 : _a.owner) {
|
|
825
|
+
owner.push(index);
|
|
714
826
|
}
|
|
715
827
|
else {
|
|
716
|
-
user.push(
|
|
828
|
+
user.push(index);
|
|
717
829
|
}
|
|
718
830
|
}
|
|
719
|
-
this.timeline[vpos] = owner.concat(user);
|
|
831
|
+
this.timeline[Number(vpos)] = owner.concat(user);
|
|
720
832
|
}
|
|
721
833
|
logger("parseData complete: ".concat(performance.now() - sortCommentStart, "ms"));
|
|
722
834
|
return parsedData;
|
|
723
835
|
};
|
|
724
836
|
NiconiComments.prototype.measureText = function (comment) {
|
|
725
|
-
var
|
|
837
|
+
var width_arr = [], lines = comment.content.split("\n");
|
|
726
838
|
if (!comment.lineHeight)
|
|
727
|
-
comment.lineHeight =
|
|
839
|
+
comment.lineHeight = lineHeight[comment.size].default;
|
|
728
840
|
if (!comment.resized && !comment.ender) {
|
|
729
841
|
if (comment.size === "big" && lines.length > 2) {
|
|
730
|
-
comment.fontSize =
|
|
731
|
-
comment.lineHeight =
|
|
842
|
+
comment.fontSize = fontSize.big.resized;
|
|
843
|
+
comment.lineHeight = lineHeight.big.resized;
|
|
732
844
|
comment.resized = true;
|
|
733
|
-
comment.
|
|
845
|
+
comment.resizedY = true;
|
|
734
846
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
735
847
|
}
|
|
736
848
|
else if (comment.size === "medium" && lines.length > 4) {
|
|
737
|
-
comment.fontSize =
|
|
738
|
-
comment.lineHeight =
|
|
849
|
+
comment.fontSize = fontSize.medium.resized;
|
|
850
|
+
comment.lineHeight = lineHeight.medium.resized;
|
|
739
851
|
comment.resized = true;
|
|
740
|
-
comment.
|
|
852
|
+
comment.resizedY = true;
|
|
741
853
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
742
854
|
}
|
|
743
855
|
else if (comment.size === "small" && lines.length > 6) {
|
|
744
|
-
comment.fontSize =
|
|
745
|
-
comment.lineHeight =
|
|
856
|
+
comment.fontSize = fontSize.small.resized;
|
|
857
|
+
comment.lineHeight = lineHeight.small.resized;
|
|
746
858
|
comment.resized = true;
|
|
747
|
-
comment.
|
|
859
|
+
comment.resizedY = true;
|
|
748
860
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
749
861
|
}
|
|
750
862
|
}
|
|
@@ -752,80 +864,90 @@
|
|
|
752
864
|
var measure = this.context.measureText(lines[i]);
|
|
753
865
|
width_arr.push(measure.width);
|
|
754
866
|
}
|
|
755
|
-
width = width_arr.reduce(function (p, c) { return p + c; }, 0) / width_arr.length
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
867
|
+
var width = width_arr.reduce(function (p, c) { return p + c; }, 0) / width_arr.length, width_max = Math.max.apply(Math, width_arr), width_min = Math.min.apply(Math, width_arr), height = comment.fontSize *
|
|
868
|
+
comment.lineHeight *
|
|
869
|
+
(1 + commentYPaddingTop) *
|
|
870
|
+
lines.length +
|
|
871
|
+
commentYMarginBottom * comment.fontSize;
|
|
872
|
+
if (comment.loc !== "naka" && !comment.resizedY) {
|
|
873
|
+
if ((comment.full && width_max > 1930) ||
|
|
874
|
+
(!comment.full && width_max > 1440)) {
|
|
761
875
|
comment.fontSize -= 2;
|
|
762
876
|
comment.resized = true;
|
|
763
|
-
comment.
|
|
764
|
-
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
765
|
-
return this.measureText(comment);
|
|
766
|
-
}
|
|
767
|
-
else if (!comment.full && width_max > 1440) {
|
|
768
|
-
comment.fontSize -= 1;
|
|
769
|
-
comment.resized = true;
|
|
770
|
-
comment.yokoResized = true;
|
|
877
|
+
comment.resizedX = true;
|
|
771
878
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
772
879
|
return this.measureText(comment);
|
|
773
880
|
}
|
|
774
881
|
}
|
|
775
|
-
else if (comment.loc !== "naka" &&
|
|
776
|
-
comment.
|
|
777
|
-
comment.
|
|
882
|
+
else if (comment.loc !== "naka" &&
|
|
883
|
+
comment.resizedY &&
|
|
884
|
+
((comment.full && width_max > 2120) ||
|
|
885
|
+
(!comment.full && width_max > 1440)) &&
|
|
886
|
+
!comment.resizedX) {
|
|
887
|
+
comment.fontSize = fontSize[comment.size].default;
|
|
888
|
+
comment.lineHeight = lineHeight[comment.size].default * 1.05;
|
|
778
889
|
comment.resized = true;
|
|
779
|
-
comment.
|
|
890
|
+
comment.resizedX = true;
|
|
780
891
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
781
892
|
return this.measureText(comment);
|
|
782
893
|
}
|
|
783
|
-
else if (comment.loc !== "naka" && comment.
|
|
784
|
-
if (comment.full &&
|
|
894
|
+
else if (comment.loc !== "naka" && comment.resizedY && comment.resizedX) {
|
|
895
|
+
if (comment.full &&
|
|
896
|
+
width_max >
|
|
897
|
+
doubleResizeMaxWidth.full[this.useLegacy ? "legacy" : "default"]) {
|
|
785
898
|
comment.fontSize -= 1;
|
|
786
899
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
787
900
|
return this.measureText(comment);
|
|
788
901
|
}
|
|
789
|
-
else if (!comment.full &&
|
|
902
|
+
else if (!comment.full &&
|
|
903
|
+
width_max >
|
|
904
|
+
doubleResizeMaxWidth.normal[this.useLegacy ? "legacy" : "default"]) {
|
|
790
905
|
comment.fontSize -= 1;
|
|
791
906
|
this.context.font = parseFont(comment.font, comment.fontSize, this.useLegacy);
|
|
792
907
|
return this.measureText(comment);
|
|
793
908
|
}
|
|
794
909
|
}
|
|
795
910
|
return {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
911
|
+
width: width,
|
|
912
|
+
width_max: width_max,
|
|
913
|
+
width_min: width_min,
|
|
914
|
+
height: height,
|
|
915
|
+
resized: !!comment.resized,
|
|
916
|
+
fontSize: comment.fontSize,
|
|
917
|
+
lineHeight: comment.lineHeight,
|
|
803
918
|
};
|
|
804
919
|
};
|
|
805
920
|
NiconiComments.prototype.drawText = function (comment, vpos) {
|
|
921
|
+
var _this = this;
|
|
806
922
|
var reverse = false;
|
|
807
|
-
for (var
|
|
808
|
-
var range =
|
|
809
|
-
if ((range.target === "コメ" && comment.owner) ||
|
|
923
|
+
for (var _i = 0, _a = this.nicoScripts.reverse; _i < _a.length; _i++) {
|
|
924
|
+
var range = _a[_i];
|
|
925
|
+
if ((range.target === "コメ" && comment.owner) ||
|
|
926
|
+
(range.target === "投コメ" && !comment.owner))
|
|
810
927
|
break;
|
|
811
|
-
}
|
|
812
928
|
if (range.start < vpos && vpos < range.end) {
|
|
813
929
|
reverse = true;
|
|
814
930
|
}
|
|
815
931
|
}
|
|
816
|
-
for (var
|
|
817
|
-
var range =
|
|
818
|
-
if (range.start < vpos && vpos < range.end)
|
|
932
|
+
for (var _b = 0, _c = this.nicoScripts.ban; _b < _c.length; _b++) {
|
|
933
|
+
var range = _c[_b];
|
|
934
|
+
if (range.start < vpos && vpos < range.end)
|
|
819
935
|
return;
|
|
820
|
-
}
|
|
821
936
|
}
|
|
822
937
|
var posX = (1920 - comment.width_max) / 2, posY = comment.posY;
|
|
823
938
|
if (comment.loc === "naka") {
|
|
824
939
|
if (reverse) {
|
|
825
|
-
posX =
|
|
940
|
+
posX =
|
|
941
|
+
240 +
|
|
942
|
+
((1680 + comment.width_max) / (comment.long + 125)) *
|
|
943
|
+
(vpos - comment.vpos + 100) -
|
|
944
|
+
comment.width_max;
|
|
826
945
|
}
|
|
827
946
|
else {
|
|
828
|
-
posX =
|
|
947
|
+
posX =
|
|
948
|
+
1680 -
|
|
949
|
+
((1680 + comment.width_max) / (comment.long + 125)) *
|
|
950
|
+
(vpos - comment.vpos + 100);
|
|
829
951
|
}
|
|
830
952
|
}
|
|
831
953
|
else if (comment.loc === "shita") {
|
|
@@ -838,15 +960,25 @@
|
|
|
838
960
|
this.context.strokeStyle = "rgba(0,255,255,1)";
|
|
839
961
|
this.context.strokeRect(posX, posY, comment.width_max, comment.height);
|
|
840
962
|
var lines = comment.content.split("\n");
|
|
841
|
-
|
|
842
|
-
var linePosY = (Number(
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
963
|
+
lines.forEach(function (_, index) {
|
|
964
|
+
var linePosY = (Number(index) + 1) *
|
|
965
|
+
(comment.fontSize * comment.lineHeight) *
|
|
966
|
+
(1 + commentYPaddingTop);
|
|
967
|
+
_this.context.strokeStyle = "rgba(255,255,0,0.5)";
|
|
968
|
+
_this.context.strokeRect(posX, posY + linePosY, comment.width_max, comment.fontSize * comment.lineHeight * -1);
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
if (isDebug) {
|
|
972
|
+
var font = this.context.font;
|
|
973
|
+
var fillStyle = this.context.fillStyle;
|
|
974
|
+
this.context.font = parseFont("defont", 30, false);
|
|
975
|
+
this.context.fillStyle = "#ff00ff";
|
|
976
|
+
this.context.fillText(comment.mail.join(","), posX, posY + 30);
|
|
977
|
+
this.context.font = font;
|
|
978
|
+
this.context.fillStyle = fillStyle;
|
|
846
979
|
}
|
|
847
980
|
};
|
|
848
981
|
NiconiComments.prototype.getTextImage = function (i, preRendering) {
|
|
849
|
-
var _this = this;
|
|
850
982
|
if (preRendering === void 0) { preRendering = false; }
|
|
851
983
|
var value = this.data[i];
|
|
852
984
|
if (!value || value.invisible)
|
|
@@ -873,225 +1005,157 @@
|
|
|
873
1005
|
context.strokeStyle = "rgba(255,255,255,0.7)";
|
|
874
1006
|
}
|
|
875
1007
|
var lines = value.content.split("\n");
|
|
876
|
-
|
|
877
|
-
var
|
|
878
|
-
|
|
1008
|
+
lines.forEach(function (line, index) {
|
|
1009
|
+
var posY = (Number(index) + 1) *
|
|
1010
|
+
(value.fontSize * value.lineHeight) *
|
|
1011
|
+
(1 + commentYPaddingTop);
|
|
879
1012
|
context.strokeText(line, 0, posY);
|
|
880
1013
|
context.fillText(line, 0, posY);
|
|
881
|
-
}
|
|
882
|
-
|
|
1014
|
+
});
|
|
1015
|
+
value.image = image;
|
|
883
1016
|
if (preRendering)
|
|
884
1017
|
return;
|
|
885
1018
|
setTimeout(function () {
|
|
886
|
-
if (
|
|
887
|
-
delete
|
|
1019
|
+
if (value.image)
|
|
1020
|
+
delete value.image;
|
|
888
1021
|
}, 5000);
|
|
889
1022
|
};
|
|
890
1023
|
NiconiComments.prototype.parseCommand = function (comment) {
|
|
891
|
-
var metadata = comment.mail
|
|
892
|
-
|
|
893
|
-
|
|
1024
|
+
var metadata = comment.mail;
|
|
1025
|
+
var result = {
|
|
1026
|
+
loc: undefined,
|
|
1027
|
+
size: undefined,
|
|
1028
|
+
fontSize: undefined,
|
|
1029
|
+
color: undefined,
|
|
1030
|
+
font: undefined,
|
|
1031
|
+
full: false,
|
|
1032
|
+
ender: false,
|
|
1033
|
+
_live: false,
|
|
1034
|
+
invisible: false,
|
|
1035
|
+
long: undefined,
|
|
1036
|
+
};
|
|
1037
|
+
var isKey = function (i) {
|
|
1038
|
+
return typeof i === "string" && !!i.match(/^full|ender|_live|invisible$/);
|
|
1039
|
+
};
|
|
1040
|
+
for (var _i = 0, metadata_1 = metadata; _i < metadata_1.length; _i++) {
|
|
1041
|
+
var command = metadata_1[_i];
|
|
1042
|
+
command = command.toLowerCase();
|
|
894
1043
|
var match = command.match(/^@([0-9.]+)/);
|
|
895
|
-
if (match) {
|
|
896
|
-
long = match[1];
|
|
1044
|
+
if (match && match[1]) {
|
|
1045
|
+
result.long = Number(match[1]);
|
|
897
1046
|
}
|
|
898
|
-
if (loc ===
|
|
899
|
-
|
|
900
|
-
case "ue":
|
|
901
|
-
loc = "ue";
|
|
902
|
-
break;
|
|
903
|
-
case "shita":
|
|
904
|
-
loc = "shita";
|
|
905
|
-
break;
|
|
906
|
-
}
|
|
1047
|
+
else if (result.loc === undefined && typeGuard.comment.loc(command)) {
|
|
1048
|
+
result.loc = command;
|
|
907
1049
|
}
|
|
908
|
-
if (size ===
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
size = "big";
|
|
912
|
-
fontSize = this.fontSize.big.default;
|
|
913
|
-
break;
|
|
914
|
-
case "small":
|
|
915
|
-
size = "small";
|
|
916
|
-
fontSize = this.fontSize.small.default;
|
|
917
|
-
break;
|
|
918
|
-
}
|
|
1050
|
+
else if (result.size === undefined && typeGuard.comment.size(command)) {
|
|
1051
|
+
result.size = command;
|
|
1052
|
+
result.fontSize = fontSize[command].default;
|
|
919
1053
|
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
case "pink":
|
|
929
|
-
color = "#FF8080";
|
|
930
|
-
break;
|
|
931
|
-
case "orange":
|
|
932
|
-
color = "#FFC000";
|
|
933
|
-
break;
|
|
934
|
-
case "yellow":
|
|
935
|
-
color = "#FFFF00";
|
|
936
|
-
break;
|
|
937
|
-
case "green":
|
|
938
|
-
color = "#00FF00";
|
|
939
|
-
break;
|
|
940
|
-
case "cyan":
|
|
941
|
-
color = "#00FFFF";
|
|
942
|
-
break;
|
|
943
|
-
case "blue":
|
|
944
|
-
color = "#0000FF";
|
|
945
|
-
break;
|
|
946
|
-
case "purple":
|
|
947
|
-
color = "#C000FF";
|
|
948
|
-
break;
|
|
949
|
-
case "black":
|
|
950
|
-
color = "#000000";
|
|
951
|
-
break;
|
|
952
|
-
case "white2":
|
|
953
|
-
case "niconicowhite":
|
|
954
|
-
color = "#CCCC99";
|
|
955
|
-
break;
|
|
956
|
-
case "red2":
|
|
957
|
-
case "truered":
|
|
958
|
-
color = "#CC0033";
|
|
959
|
-
break;
|
|
960
|
-
case "pink2":
|
|
961
|
-
color = "#FF33CC";
|
|
962
|
-
break;
|
|
963
|
-
case "orange2":
|
|
964
|
-
case "passionorange":
|
|
965
|
-
color = "#FF6600";
|
|
966
|
-
break;
|
|
967
|
-
case "yellow2":
|
|
968
|
-
case "madyellow":
|
|
969
|
-
color = "#999900";
|
|
970
|
-
break;
|
|
971
|
-
case "green2":
|
|
972
|
-
case "elementalgreen":
|
|
973
|
-
color = "#00CC66";
|
|
974
|
-
break;
|
|
975
|
-
case "cyan2":
|
|
976
|
-
color = "#00CCCC";
|
|
977
|
-
break;
|
|
978
|
-
case "blue2":
|
|
979
|
-
case "marineblue":
|
|
980
|
-
color = "#3399FF";
|
|
981
|
-
break;
|
|
982
|
-
case "purple2":
|
|
983
|
-
case "nobleviolet":
|
|
984
|
-
color = "#6633CC";
|
|
985
|
-
break;
|
|
986
|
-
case "black2":
|
|
987
|
-
color = "#666666";
|
|
988
|
-
break;
|
|
989
|
-
default:
|
|
1054
|
+
else {
|
|
1055
|
+
if (result.color === undefined) {
|
|
1056
|
+
var color = colors[command];
|
|
1057
|
+
if (color) {
|
|
1058
|
+
result.color = color;
|
|
1059
|
+
continue;
|
|
1060
|
+
}
|
|
1061
|
+
else {
|
|
990
1062
|
var match_1 = command.match(/#[0-9a-z]{3,6}/);
|
|
991
|
-
if (match_1 && comment.premium) {
|
|
992
|
-
color = match_1[0].toUpperCase();
|
|
1063
|
+
if (match_1 && match_1[0] && comment.premium) {
|
|
1064
|
+
result.color = match_1[0].toUpperCase();
|
|
1065
|
+
continue;
|
|
993
1066
|
}
|
|
994
|
-
|
|
1067
|
+
}
|
|
995
1068
|
}
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
break;
|
|
1002
|
-
case "mincho":
|
|
1003
|
-
font = "mincho";
|
|
1004
|
-
break;
|
|
1069
|
+
if (result.font === undefined && typeGuard.comment.font(command)) {
|
|
1070
|
+
result.font = command;
|
|
1071
|
+
}
|
|
1072
|
+
else if (isKey(command)) {
|
|
1073
|
+
result[command] = true;
|
|
1005
1074
|
}
|
|
1006
|
-
}
|
|
1007
|
-
switch (command) {
|
|
1008
|
-
case "full":
|
|
1009
|
-
full = true;
|
|
1010
|
-
break;
|
|
1011
|
-
case "ender":
|
|
1012
|
-
ender = true;
|
|
1013
|
-
break;
|
|
1014
|
-
case "_live":
|
|
1015
|
-
_live = true;
|
|
1016
|
-
break;
|
|
1017
|
-
case "invisible":
|
|
1018
|
-
invisible = true;
|
|
1019
|
-
break;
|
|
1020
1075
|
}
|
|
1021
1076
|
}
|
|
1022
|
-
return
|
|
1077
|
+
return result;
|
|
1023
1078
|
};
|
|
1024
1079
|
NiconiComments.prototype.parseCommandAndNicoscript = function (comment) {
|
|
1025
|
-
var data = this.parseCommand(comment),
|
|
1080
|
+
var data = this.parseCommand(comment), string = comment.content, nicoscript = string.match(/^(?:@|@)(デフォルト|置換|逆|コメント禁止|シーク禁止|ジャンプ)/);
|
|
1026
1081
|
if (nicoscript) {
|
|
1082
|
+
var reverse = comment.content.match(/^@逆 ?(全|コメ|投コメ)?/);
|
|
1083
|
+
var content = comment.content.split(""), result = [];
|
|
1084
|
+
var quote = "", last_i = "", string_1 = "";
|
|
1027
1085
|
switch (nicoscript[1]) {
|
|
1028
1086
|
case "デフォルト":
|
|
1029
|
-
this.nicoScripts.default.
|
|
1087
|
+
this.nicoScripts.default.unshift({
|
|
1030
1088
|
start: comment.vpos,
|
|
1031
|
-
long: data.long ===
|
|
1089
|
+
long: data.long === undefined ? undefined : Math.floor(data.long * 100),
|
|
1032
1090
|
color: data.color,
|
|
1033
1091
|
size: data.size,
|
|
1034
1092
|
font: data.font,
|
|
1035
|
-
loc: data.loc
|
|
1093
|
+
loc: data.loc,
|
|
1036
1094
|
});
|
|
1037
1095
|
break;
|
|
1038
1096
|
case "逆":
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
reverse
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
}
|
|
1045
|
-
if (data.long === null) {
|
|
1097
|
+
if (!reverse ||
|
|
1098
|
+
!reverse[1] ||
|
|
1099
|
+
!typeGuard.nicoScript.range.target(reverse[1]))
|
|
1100
|
+
break;
|
|
1101
|
+
if (data.long === undefined) {
|
|
1046
1102
|
data.long = 30;
|
|
1047
1103
|
}
|
|
1048
|
-
this.nicoScripts.reverse.
|
|
1104
|
+
this.nicoScripts.reverse.unshift({
|
|
1049
1105
|
start: comment.vpos,
|
|
1050
|
-
end: comment.vpos +
|
|
1051
|
-
target: reverse[1]
|
|
1106
|
+
end: comment.vpos + data.long * 100,
|
|
1107
|
+
target: reverse[1],
|
|
1052
1108
|
});
|
|
1053
1109
|
break;
|
|
1054
1110
|
case "コメント禁止":
|
|
1055
|
-
if (data.long ===
|
|
1111
|
+
if (data.long === undefined) {
|
|
1056
1112
|
data.long = 30;
|
|
1057
1113
|
}
|
|
1058
|
-
this.nicoScripts.
|
|
1114
|
+
this.nicoScripts.ban.unshift({
|
|
1059
1115
|
start: comment.vpos,
|
|
1060
|
-
end: comment.vpos +
|
|
1116
|
+
end: comment.vpos + data.long * 100,
|
|
1061
1117
|
});
|
|
1062
1118
|
break;
|
|
1063
1119
|
case "置換":
|
|
1064
|
-
var content = comment.content.split(""), quote = "", last_i = "", string = "", result = [];
|
|
1065
1120
|
for (var _i = 0, _a = content.slice(4); _i < _a.length; _i++) {
|
|
1066
1121
|
var i = _a[_i];
|
|
1067
1122
|
if (i.match(/["'「]/) && quote === "") {
|
|
1068
1123
|
quote = i;
|
|
1069
1124
|
}
|
|
1070
1125
|
else if (i.match(/["']/) && quote === i && last_i !== "\\") {
|
|
1071
|
-
result.push(replaceAll(
|
|
1126
|
+
result.push(replaceAll(string_1, "\\n", "\n"));
|
|
1072
1127
|
quote = "";
|
|
1073
|
-
|
|
1128
|
+
string_1 = "";
|
|
1074
1129
|
}
|
|
1075
1130
|
else if (i.match(/」/) && quote === "「") {
|
|
1076
|
-
result.push(
|
|
1131
|
+
result.push(string_1);
|
|
1077
1132
|
quote = "";
|
|
1078
|
-
|
|
1133
|
+
string_1 = "";
|
|
1079
1134
|
}
|
|
1080
|
-
else if (quote === "" && i.match(
|
|
1081
|
-
if (
|
|
1082
|
-
result.push(
|
|
1083
|
-
|
|
1135
|
+
else if (quote === "" && i.match(/\s+/)) {
|
|
1136
|
+
if (string_1) {
|
|
1137
|
+
result.push(string_1);
|
|
1138
|
+
string_1 = "";
|
|
1084
1139
|
}
|
|
1085
1140
|
}
|
|
1086
1141
|
else {
|
|
1087
|
-
|
|
1142
|
+
string_1 += i;
|
|
1088
1143
|
}
|
|
1089
1144
|
last_i = i;
|
|
1090
1145
|
}
|
|
1091
|
-
result.push(
|
|
1092
|
-
|
|
1146
|
+
result.push(string_1);
|
|
1147
|
+
if (result[0] === undefined ||
|
|
1148
|
+
result[1] === undefined ||
|
|
1149
|
+
(result[2] !== undefined &&
|
|
1150
|
+
!typeGuard.nicoScript.replace.range(result[2])) ||
|
|
1151
|
+
(result[3] !== undefined &&
|
|
1152
|
+
!typeGuard.nicoScript.replace.target(result[3])) ||
|
|
1153
|
+
(result[4] !== undefined &&
|
|
1154
|
+
!typeGuard.nicoScript.replace.condition(result[4])))
|
|
1155
|
+
break;
|
|
1156
|
+
this.nicoScripts.replace.unshift({
|
|
1093
1157
|
start: comment.vpos,
|
|
1094
|
-
long: data.long ===
|
|
1158
|
+
long: data.long === undefined ? undefined : Math.floor(data.long * 100),
|
|
1095
1159
|
keyword: result[0],
|
|
1096
1160
|
replace: result[1] || "",
|
|
1097
1161
|
range: result[2] || "単",
|
|
@@ -1100,40 +1164,63 @@
|
|
|
1100
1164
|
color: data.color,
|
|
1101
1165
|
size: data.size,
|
|
1102
1166
|
font: data.font,
|
|
1103
|
-
loc: data.loc
|
|
1167
|
+
loc: data.loc,
|
|
1168
|
+
no: comment.id,
|
|
1169
|
+
});
|
|
1170
|
+
this.nicoScripts.replace.sort(function (a, b) {
|
|
1171
|
+
if (a.start < b.start)
|
|
1172
|
+
return -1;
|
|
1173
|
+
if (a.start > b.start)
|
|
1174
|
+
return 1;
|
|
1175
|
+
if (a.no < b.no)
|
|
1176
|
+
return -1;
|
|
1177
|
+
if (a.no > b.no)
|
|
1178
|
+
return 1;
|
|
1179
|
+
return 0;
|
|
1104
1180
|
});
|
|
1105
1181
|
break;
|
|
1106
1182
|
}
|
|
1107
1183
|
data.invisible = true;
|
|
1108
1184
|
}
|
|
1109
|
-
var color =
|
|
1110
|
-
for (var i
|
|
1111
|
-
|
|
1185
|
+
var color = undefined, size = undefined, font = undefined, loc = undefined;
|
|
1186
|
+
for (var i = 0; i < this.nicoScripts.default.length; i++) {
|
|
1187
|
+
var item = this.nicoScripts.default[i];
|
|
1188
|
+
if (!item)
|
|
1189
|
+
continue;
|
|
1190
|
+
if (item.long !== undefined && item.start + item.long < comment.vpos) {
|
|
1112
1191
|
this.nicoScripts.default = this.nicoScripts.default.splice(Number(i), 1);
|
|
1113
1192
|
continue;
|
|
1114
1193
|
}
|
|
1115
|
-
if (
|
|
1116
|
-
loc =
|
|
1194
|
+
if (item.loc) {
|
|
1195
|
+
loc = item.loc;
|
|
1117
1196
|
}
|
|
1118
|
-
if (
|
|
1119
|
-
color =
|
|
1197
|
+
if (item.color) {
|
|
1198
|
+
color = item.color;
|
|
1120
1199
|
}
|
|
1121
|
-
if (
|
|
1122
|
-
size =
|
|
1200
|
+
if (item.size) {
|
|
1201
|
+
size = item.size;
|
|
1123
1202
|
}
|
|
1124
|
-
if (
|
|
1125
|
-
font =
|
|
1203
|
+
if (item.font) {
|
|
1204
|
+
font = item.font;
|
|
1126
1205
|
}
|
|
1206
|
+
if (loc && color && size && font)
|
|
1207
|
+
break;
|
|
1127
1208
|
}
|
|
1128
|
-
for (var i
|
|
1129
|
-
|
|
1209
|
+
for (var i = 0; i < this.nicoScripts.replace.length; i++) {
|
|
1210
|
+
var item = this.nicoScripts.replace[i];
|
|
1211
|
+
if (!item)
|
|
1212
|
+
continue;
|
|
1213
|
+
if (item.long !== undefined && item.start + item.long < comment.vpos) {
|
|
1130
1214
|
this.nicoScripts.default = this.nicoScripts.default.splice(Number(i), 1);
|
|
1131
1215
|
continue;
|
|
1132
1216
|
}
|
|
1133
|
-
|
|
1134
|
-
|
|
1217
|
+
if ((item.target === "コメ" && comment.owner) ||
|
|
1218
|
+
(item.target === "投コメ" && !comment.owner) ||
|
|
1219
|
+
(item.target === "含まない" && comment.owner))
|
|
1135
1220
|
continue;
|
|
1136
|
-
if ((item.condition === "完全一致" && comment.content === item.keyword) ||
|
|
1221
|
+
if ((item.condition === "完全一致" && comment.content === item.keyword) ||
|
|
1222
|
+
(item.condition === "部分一致" &&
|
|
1223
|
+
comment.content.indexOf(item.keyword) !== -1)) {
|
|
1137
1224
|
if (item.range === "単") {
|
|
1138
1225
|
comment.content = replaceAll(comment.content, item.keyword, item.replace);
|
|
1139
1226
|
}
|
|
@@ -1141,31 +1228,31 @@
|
|
|
1141
1228
|
comment.content = item.replace;
|
|
1142
1229
|
}
|
|
1143
1230
|
if (item.loc) {
|
|
1144
|
-
loc = item.loc;
|
|
1231
|
+
data.loc = item.loc;
|
|
1145
1232
|
}
|
|
1146
1233
|
if (item.color) {
|
|
1147
|
-
color = item.color;
|
|
1234
|
+
data.color = item.color;
|
|
1148
1235
|
}
|
|
1149
1236
|
if (item.size) {
|
|
1150
|
-
size = item.size;
|
|
1237
|
+
data.size = item.size;
|
|
1151
1238
|
}
|
|
1152
1239
|
if (item.font) {
|
|
1153
|
-
font = item.font;
|
|
1240
|
+
data.font = item.font;
|
|
1154
1241
|
}
|
|
1155
1242
|
}
|
|
1156
1243
|
}
|
|
1157
1244
|
if (!data.loc) {
|
|
1158
|
-
data.loc = loc;
|
|
1245
|
+
data.loc = loc || "naka";
|
|
1159
1246
|
}
|
|
1160
1247
|
if (!data.color) {
|
|
1161
|
-
data.color = color;
|
|
1248
|
+
data.color = color || "#FFFFFF";
|
|
1162
1249
|
}
|
|
1163
1250
|
if (!data.size) {
|
|
1164
|
-
data.size = size;
|
|
1165
|
-
data.fontSize =
|
|
1251
|
+
data.size = size || "medium";
|
|
1252
|
+
data.fontSize = fontSize[data.size].default;
|
|
1166
1253
|
}
|
|
1167
1254
|
if (!data.font) {
|
|
1168
|
-
data.font = font;
|
|
1255
|
+
data.font = font || "defont";
|
|
1169
1256
|
}
|
|
1170
1257
|
if (!data.long) {
|
|
1171
1258
|
data.long = 300;
|
|
@@ -1183,23 +1270,22 @@
|
|
|
1183
1270
|
this.fpsCount++;
|
|
1184
1271
|
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
1185
1272
|
if (this.video) {
|
|
1186
|
-
var
|
|
1273
|
+
var scale = void 0;
|
|
1274
|
+
var height = this.canvas.height / this.video.videoHeight, width = this.canvas.width / this.video.videoWidth;
|
|
1187
1275
|
if (this.enableLegacyPiP ? height > width : height < width) {
|
|
1188
1276
|
scale = width;
|
|
1189
1277
|
}
|
|
1190
1278
|
else {
|
|
1191
1279
|
scale = height;
|
|
1192
1280
|
}
|
|
1193
|
-
offsetX = (this.canvas.width - this.video.videoWidth * scale) * 0.5;
|
|
1194
|
-
offsetY = (this.canvas.height - this.video.videoHeight * scale) * 0.5;
|
|
1281
|
+
var offsetX = (this.canvas.width - this.video.videoWidth * scale) * 0.5, offsetY = (this.canvas.height - this.video.videoHeight * scale) * 0.5;
|
|
1195
1282
|
this.context.drawImage(this.video, offsetX, offsetY, this.video.videoWidth * scale, this.video.videoHeight * scale);
|
|
1196
1283
|
}
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1284
|
+
var timelineRange = this.timeline[vpos];
|
|
1285
|
+
if (timelineRange) {
|
|
1286
|
+
for (var _i = 0, timelineRange_1 = timelineRange; _i < timelineRange_1.length; _i++) {
|
|
1287
|
+
var index = timelineRange_1[_i];
|
|
1200
1288
|
var comment = this.data[index];
|
|
1201
|
-
if (vpos > 23000 && vpos < 23100)
|
|
1202
|
-
console.log(comment);
|
|
1203
1289
|
if (!comment || comment.invisible) {
|
|
1204
1290
|
continue;
|
|
1205
1291
|
}
|
|
@@ -1218,16 +1304,16 @@
|
|
|
1218
1304
|
this.context.font = parseFont("defont", 60, this.useLegacy);
|
|
1219
1305
|
this.context.fillStyle = "#00FF00";
|
|
1220
1306
|
this.context.strokeStyle = "rgba(0,0,0,0.7)";
|
|
1221
|
-
this.context.strokeText("FPS:"
|
|
1222
|
-
this.context.fillText("FPS:"
|
|
1307
|
+
this.context.strokeText("FPS:".concat(this.fps), 100, 100);
|
|
1308
|
+
this.context.fillText("FPS:".concat(this.fps), 100, 100);
|
|
1223
1309
|
}
|
|
1224
1310
|
if (this.showCommentCount) {
|
|
1225
1311
|
this.context.font = parseFont("defont", 60, this.useLegacy);
|
|
1226
1312
|
this.context.fillStyle = "#00FF00";
|
|
1227
1313
|
this.context.strokeStyle = "rgba(0,0,0,0.7)";
|
|
1228
|
-
if (
|
|
1229
|
-
this.context.strokeText("Count:"
|
|
1230
|
-
this.context.fillText("Count:"
|
|
1314
|
+
if (timelineRange) {
|
|
1315
|
+
this.context.strokeText("Count:".concat(timelineRange.length), 100, 200);
|
|
1316
|
+
this.context.fillText("Count:".concat(timelineRange.length), 100, 200);
|
|
1231
1317
|
}
|
|
1232
1318
|
else {
|
|
1233
1319
|
this.context.strokeText("Count:0", 100, 200);
|
|
@@ -1241,19 +1327,55 @@
|
|
|
1241
1327
|
};
|
|
1242
1328
|
return NiconiComments;
|
|
1243
1329
|
}());
|
|
1244
|
-
var groupBy = function (array
|
|
1245
|
-
var data = {
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1330
|
+
var groupBy = function (array) {
|
|
1331
|
+
var data = ["defont", "gothic", "mincho"].reduce(function (pv, font) {
|
|
1332
|
+
pv[font] = {};
|
|
1333
|
+
return pv;
|
|
1334
|
+
}, {});
|
|
1335
|
+
array.forEach(function (item, index) {
|
|
1336
|
+
var value = data[item.font][item.fontSize] || [];
|
|
1337
|
+
value.push(_assign(_assign({}, item), { index: index }));
|
|
1338
|
+
if (value.length === 1) {
|
|
1339
|
+
data[item.font][item.fontSize] = value;
|
|
1249
1340
|
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1341
|
+
});
|
|
1342
|
+
return data;
|
|
1343
|
+
};
|
|
1344
|
+
var getPosY = function (currentPos, targetComment, collision, data) {
|
|
1345
|
+
var isChanged = false, isBreak = false;
|
|
1346
|
+
if (!collision)
|
|
1347
|
+
return { currentPos: currentPos, isChanged: isChanged, isBreak: isBreak };
|
|
1348
|
+
for (var _i = 0, collision_1 = collision; _i < collision_1.length; _i++) {
|
|
1349
|
+
var index = collision_1[_i];
|
|
1350
|
+
var collisionItem = data[index];
|
|
1351
|
+
if (!collisionItem)
|
|
1352
|
+
continue;
|
|
1353
|
+
if (currentPos < collisionItem.posY + collisionItem.height &&
|
|
1354
|
+
currentPos + targetComment.height > collisionItem.posY &&
|
|
1355
|
+
collisionItem.owner === targetComment.owner &&
|
|
1356
|
+
collisionItem.layer === targetComment.layer) {
|
|
1357
|
+
if (collisionItem.posY + collisionItem.height > currentPos) {
|
|
1358
|
+
currentPos = collisionItem.posY + collisionItem.height;
|
|
1359
|
+
isChanged = true;
|
|
1360
|
+
}
|
|
1361
|
+
if (currentPos + targetComment.height > 1080) {
|
|
1362
|
+
if (1080 < targetComment.height) {
|
|
1363
|
+
if (targetComment.mail.includes("naka")) {
|
|
1364
|
+
currentPos = (targetComment.height - 1080) / -2;
|
|
1365
|
+
}
|
|
1366
|
+
else {
|
|
1367
|
+
currentPos = 0;
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
else {
|
|
1371
|
+
currentPos = Math.floor(Math.random() * (1080 - targetComment.height));
|
|
1372
|
+
}
|
|
1373
|
+
isBreak = true;
|
|
1374
|
+
break;
|
|
1375
|
+
}
|
|
1252
1376
|
}
|
|
1253
|
-
array[i].index = i;
|
|
1254
|
-
data[array[i][key]][array[i][key2]].push(array[i]);
|
|
1255
1377
|
}
|
|
1256
|
-
return
|
|
1378
|
+
return { currentPos: currentPos, isChanged: isChanged, isBreak: isBreak };
|
|
1257
1379
|
};
|
|
1258
1380
|
var parseFont = function (font, size, useLegacy) {
|
|
1259
1381
|
switch (font) {
|
|
@@ -1271,28 +1393,33 @@
|
|
|
1271
1393
|
}
|
|
1272
1394
|
};
|
|
1273
1395
|
var arrayPush = function (array, key, push) {
|
|
1396
|
+
var _a;
|
|
1274
1397
|
if (!array) {
|
|
1275
1398
|
array = {};
|
|
1276
1399
|
}
|
|
1277
|
-
if (!array[key]) {
|
|
1278
|
-
array[key] = [];
|
|
1400
|
+
if (!array[Number(key)]) {
|
|
1401
|
+
array[Number(key)] = [];
|
|
1279
1402
|
}
|
|
1280
|
-
array[key].push(push);
|
|
1403
|
+
(_a = array[Number(key)]) === null || _a === void 0 ? void 0 : _a.push(push);
|
|
1281
1404
|
};
|
|
1282
1405
|
var hex2rgb = function (hex) {
|
|
1283
1406
|
if (hex.slice(0, 1) === "#")
|
|
1284
1407
|
hex = hex.slice(1);
|
|
1285
1408
|
if (hex.length === 3)
|
|
1286
|
-
hex =
|
|
1409
|
+
hex =
|
|
1410
|
+
hex.slice(0, 1) +
|
|
1411
|
+
hex.slice(0, 1) +
|
|
1412
|
+
hex.slice(1, 2) +
|
|
1413
|
+
hex.slice(1, 2) +
|
|
1414
|
+
hex.slice(2, 3) +
|
|
1415
|
+
hex.slice(2, 3);
|
|
1287
1416
|
return [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map(function (str) {
|
|
1288
1417
|
return parseInt(str, 16);
|
|
1289
1418
|
});
|
|
1290
1419
|
};
|
|
1291
1420
|
var replaceAll = function (string, target, replace) {
|
|
1292
|
-
|
|
1293
|
-
while (string.indexOf(target) !== -1 && count < 100) {
|
|
1421
|
+
while (string.indexOf(target) !== -1) {
|
|
1294
1422
|
string = string.replace(target, replace);
|
|
1295
|
-
count++;
|
|
1296
1423
|
}
|
|
1297
1424
|
return string;
|
|
1298
1425
|
};
|
|
@@ -1303,23 +1430,28 @@
|
|
|
1303
1430
|
var changeCALayer = function (rawData) {
|
|
1304
1431
|
var userList = {};
|
|
1305
1432
|
var data = [], index = {};
|
|
1306
|
-
for (var
|
|
1307
|
-
var value =
|
|
1433
|
+
for (var _i = 0, rawData_1 = rawData; _i < rawData_1.length; _i++) {
|
|
1434
|
+
var value = rawData_1[_i];
|
|
1308
1435
|
if (value.user_id === undefined || value.user_id === -1)
|
|
1309
1436
|
continue;
|
|
1310
1437
|
if (userList[value.user_id] === undefined)
|
|
1311
1438
|
userList[value.user_id] = 0;
|
|
1312
|
-
if (value.mail.indexOf("ca") > -1 ||
|
|
1439
|
+
if (value.mail.indexOf("ca") > -1 ||
|
|
1440
|
+
value.mail.indexOf("patissier") > -1 ||
|
|
1441
|
+
value.mail.indexOf("ender") > -1 ||
|
|
1442
|
+
value.mail.indexOf("full") > -1) {
|
|
1313
1443
|
userList[value.user_id] += 5;
|
|
1314
1444
|
}
|
|
1315
1445
|
if ((value.content.match(/\r\n|\n|\r/g) || []).length > 2) {
|
|
1316
|
-
userList[value.user_id] +=
|
|
1446
|
+
userList[value.user_id] +=
|
|
1447
|
+
(value.content.match(/\r\n|\n|\r/g) || []).length / 2;
|
|
1317
1448
|
}
|
|
1318
|
-
var key = "".concat(value.content, "@@").concat(Array.from(new Set(
|
|
1449
|
+
var key = "".concat(value.content, "@@").concat(Array.from(new Set(__spreadArray([], value.mail, true).sort()))
|
|
1450
|
+
.filter(function (e) { return !e.match(/@[\d.]+|184|device:.+|patissier|ca/); })
|
|
1451
|
+
.join("")), lastComment = index[key];
|
|
1319
1452
|
if (lastComment !== undefined) {
|
|
1320
|
-
if (value.vpos
|
|
1321
|
-
|
|
1322
|
-
if (value.vpos - lastComment.vpos > 100 || Math.abs(value.date - lastComment.date) < 3600) {
|
|
1453
|
+
if (value.vpos - lastComment.vpos > 100 ||
|
|
1454
|
+
Math.abs(value.date - lastComment.date) < 3600) {
|
|
1323
1455
|
data.push(value);
|
|
1324
1456
|
index[key] = value;
|
|
1325
1457
|
}
|
|
@@ -1329,11 +1461,10 @@
|
|
|
1329
1461
|
index[key] = value;
|
|
1330
1462
|
}
|
|
1331
1463
|
}
|
|
1332
|
-
for (var
|
|
1333
|
-
var value =
|
|
1334
|
-
if (userList[value.user_id]
|
|
1464
|
+
for (var _a = 0, data_1 = data; _a < data_1.length; _a++) {
|
|
1465
|
+
var value = data_1[_a];
|
|
1466
|
+
if (userList[value.user_id] || 0 >= 10)
|
|
1335
1467
|
value.layer = value.user_id;
|
|
1336
|
-
}
|
|
1337
1468
|
}
|
|
1338
1469
|
return data;
|
|
1339
1470
|
};
|