bigbossmonster commited on
Commit
d1afead
·
verified ·
1 Parent(s): 9c5c9a9

Update static/index.html

Browse files
Files changed (1) hide show
  1. 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
- parseSRT: (data) => {
72
- if (!data) return [];
73
- const normalized = data.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
74
-
75
- // Robust Regex-based parsing to handle inconsistent spacing/newlines
76
- // Looks for: Line with Digits (ID) -> Newline -> Timestamp Line
77
- const regex = /(\d+)\n(\d{2}:\d{2}:\d{2}[,.]\d{3}\s*-->\s*\d{2}:\d{2}:\d{2}[,.]\d{3})/g;
78
-
79
- const parsed = [];
80
- let match;
81
- const matches = [];
82
-
83
- // 1. Scan for all headers first
84
- while ((match = regex.exec(normalized)) !== null) {
85
- matches.push({
86
- id: match[1],
87
- time: match[2],
88
- index: match.index,
89
- endHeader: match.index + match[0].length
90
- });
91
- }
92
-
93
- // 2. Extract content between headers
94
- matches.forEach((m, i) => {
95
- const nextMatch = matches[i + 1];
96
- const startText = m.endHeader;
97
- const endText = nextMatch ? nextMatch.index : normalized.length;
98
-
99
- const textRaw = normalized.substring(startText, endText).trim();
100
- const text = textRaw || "";
101
-
102
- const startTimeStr = m.time.split('-->')[0].trim();
103
-
104
- parsed.push({
105
- id: m.id,
106
- time: m.time,
107
- startTimeMs: Helpers.timeStringToMs(startTimeStr),
108
- text: text
109
- });
110
- });
111
-
112
- return parsed;
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
  // ==========================================