Spaces:
Running
Running
frontend update
Browse files- theater_template.html +11 -36
theater_template.html
CHANGED
|
@@ -367,43 +367,18 @@
|
|
| 367 |
return colors[index];
|
| 368 |
}
|
| 369 |
|
| 370 |
-
//
|
|
|
|
| 371 |
function prepareMessages() {
|
| 372 |
-
flattenedMessages =
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
const messages = segment.messages || [];
|
| 383 |
-
messages.forEach((msg, index) => {
|
| 384 |
-
// Spread messages evenly or randomly across the duration
|
| 385 |
-
const randomOffset = Math.random() * duration;
|
| 386 |
-
const displayTime = start + randomOffset;
|
| 387 |
-
|
| 388 |
-
// Generate unique ID
|
| 389 |
-
const id = `${start}_${index}_${msg.username}`;
|
| 390 |
-
|
| 391 |
-
// Assign visual badges
|
| 392 |
-
const isMod = (index % 15 === 0);
|
| 393 |
-
const isSub = (index % 4 === 0) && !isMod;
|
| 394 |
-
|
| 395 |
-
flattenedMessages.push({
|
| 396 |
-
id: id,
|
| 397 |
-
displayTime: displayTime,
|
| 398 |
-
username: msg.username,
|
| 399 |
-
text: msg.text,
|
| 400 |
-
isMod: isMod,
|
| 401 |
-
isSub: isSub
|
| 402 |
-
});
|
| 403 |
-
});
|
| 404 |
-
}
|
| 405 |
-
|
| 406 |
-
// Sort messages by displayTime
|
| 407 |
flattenedMessages.sort((a, b) => a.displayTime - b.displayTime);
|
| 408 |
}
|
| 409 |
|
|
|
|
| 367 |
return colors[index];
|
| 368 |
}
|
| 369 |
|
| 370 |
+
// chatData is a flat list of messages with precomputed numeric displayTime.
|
| 371 |
+
// No segment loops, no timestamp arithmetic, no NaN path.
|
| 372 |
function prepareMessages() {
|
| 373 |
+
flattenedMessages = chatData.map((msg, index) => ({
|
| 374 |
+
id: msg.id || `msg_${index}`,
|
| 375 |
+
displayTime: msg.displayTime, // numeric, pre-computed by pipeline
|
| 376 |
+
username: msg.username,
|
| 377 |
+
text: msg.text,
|
| 378 |
+
isMod: (index % 15 === 0),
|
| 379 |
+
isSub: (index % 4 === 0) && !(index % 15 === 0),
|
| 380 |
+
}));
|
| 381 |
+
// Guaranteed numeric sort — displayTime is never a string or NaN.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
flattenedMessages.sort((a, b) => a.displayTime - b.displayTime);
|
| 383 |
}
|
| 384 |
|