Spaces:
Sleeping
Sleeping
Update static/index.html
Browse files- static/index.html +47 -43
static/index.html
CHANGED
|
@@ -68,49 +68,53 @@
|
|
| 68 |
const [_, h, m, s, ms] = match;
|
| 69 |
return (Number(h) * 3600000) + (Number(m) * 60000) + (Number(s) * 1000) + Number(ms);
|
| 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 |
// ==========================================
|
|
|
|
| 68 |
const [_, h, m, s, ms] = match;
|
| 69 |
return (Number(h) * 3600000) + (Number(m) * 60000) + (Number(s) * 1000) + Number(ms);
|
| 70 |
},
|
| 71 |
+
// In index.html -> Helpers object
|
| 72 |
+
|
| 73 |
+
parseSRT: (data) => {
|
| 74 |
+
if (!data) return [];
|
| 75 |
+
const normalized = data.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
| 76 |
+
|
| 77 |
+
// Regex matches only the ID and Timestamp
|
| 78 |
+
const regex = /(\d+)\n(\d{2}:\d{2}:\d{2}[,.]\d{3}\s*-->\s*\d{2}:\d{2}:\d{2}[,.]\d{3})/g;
|
| 79 |
+
|
| 80 |
+
const parsed = [];
|
| 81 |
+
let match;
|
| 82 |
+
const matches = [];
|
| 83 |
+
|
| 84 |
+
// 1. Scan for all headers first
|
| 85 |
+
while ((match = regex.exec(normalized)) !== null) {
|
| 86 |
+
matches.push({
|
| 87 |
+
id: match[1],
|
| 88 |
+
time: match[2],
|
| 89 |
+
index: match.index,
|
| 90 |
+
endHeader: match.index + match[0].length
|
| 91 |
+
});
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
// 2. Extract content between headers
|
| 95 |
+
matches.forEach((m, i) => {
|
| 96 |
+
const nextMatch = matches[i + 1];
|
| 97 |
+
const startText = m.endHeader;
|
| 98 |
+
const endText = nextMatch ? nextMatch.index : normalized.length;
|
| 99 |
+
|
| 100 |
+
// Get text and Trim
|
| 101 |
+
const textRaw = normalized.substring(startText, endText).trim();
|
| 102 |
+
|
| 103 |
+
// Use "[EMPTY]" placeholder if you want to see it visually, or keep it empty
|
| 104 |
+
const text = textRaw || "";
|
| 105 |
+
|
| 106 |
+
const startTimeStr = m.time.split('-->')[0].trim();
|
| 107 |
+
|
| 108 |
+
parsed.push({
|
| 109 |
+
id: m.id,
|
| 110 |
+
time: m.time,
|
| 111 |
+
startTimeMs: Helpers.timeStringToMs(startTimeStr),
|
| 112 |
+
text: text
|
| 113 |
+
});
|
| 114 |
+
});
|
| 115 |
+
|
| 116 |
+
return parsed;
|
| 117 |
+
}
|
| 118 |
};
|
| 119 |
|
| 120 |
// ==========================================
|