sonygod commited on
Commit
2295d31
·
1 Parent(s): 1c6e2dc
youtube_sub.js CHANGED
@@ -185,6 +185,137 @@ GM_addStyle(`
185
  color: #fff;
186
  opacity: 1;
187
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  `;
189
 
190
  // Apply main styles
@@ -489,6 +620,10 @@ GM_addStyle(`
489
  });
490
  });
491
  }
 
 
 
 
492
 
493
  setupUI() {
494
  debug.log('Setting up UI');
@@ -502,6 +637,11 @@ GM_addStyle(`
502
  toggleButton.className = 'subtitle-toggle';
503
  toggleButton.textContent = '≡'; // Use textContent instead of innerHTML
504
 
 
 
 
 
 
505
  // Create tabs container
506
  const tabs = document.createElement('div');
507
  tabs.className = 'subtitle-tabs';
@@ -528,6 +668,7 @@ GM_addStyle(`
528
 
529
  // Append elements
530
  this.container.appendChild(toggleButton);
 
531
  this.container.appendChild(tabs);
532
  this.container.appendChild(content);
533
 
@@ -543,6 +684,9 @@ GM_addStyle(`
543
  // Add toggle functionality
544
  toggleButton.addEventListener('click', () => this.toggleCollapse());
545
 
 
 
 
546
  } catch (error) {
547
  debug.error('Error setting up UI:', error);
548
  }
@@ -556,36 +700,77 @@ GM_addStyle(`
556
  // Update displaySingleLanguage method
557
  displaySingleLanguage(container, subtitles) {
558
  subtitles.forEach((sub, index) => {
559
- // Only create lines with actual content
560
  if (sub.words && sub.words.length > 0) {
561
  const line = document.createElement('div');
562
  line.className = 'subtitle-line';
563
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
564
  sub.words.forEach((word, i) => {
565
  if (word.text && word.text.trim()) {
566
- const wordSpan = document.createElement('span');
567
- wordSpan.className = 'subtitle-word';
568
- wordSpan.textContent = word.text.trim();
569
- wordSpan.dataset.start = word.startTime;
570
- wordSpan.dataset.end = word.endTime;
571
- line.appendChild(wordSpan);
572
-
 
 
 
 
 
 
 
 
573
  if (i < sub.words.length - 1) {
574
- line.appendChild(document.createTextNode(' '));
575
  }
576
  }
577
  });
578
-
579
- // Only add lines with content
580
- if (line.textContent.trim()) {
581
- const timestamp = document.createElement('span');
582
- timestamp.className = 'timestamp';
583
- timestamp.textContent = this.formatTime(sub.startTime);
584
- line.appendChild(timestamp);
585
- line.dataset.time = sub.startTime;
586
- line.dataset.index = index;
587
- container.appendChild(line);
588
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
589
  }
590
  });
591
  }
 
185
  color: #fff;
186
  opacity: 1;
187
  }
188
+
189
+
190
+ .subtitle-manager[data-theme="light"] {
191
+ background: rgba(255, 255, 255, 0.95);
192
+ color: #0066cc;
193
+ }
194
+
195
+ .subtitle-manager[data-theme="light"] .subtitle-word {
196
+ color: #0066cc;
197
+ opacity: 0.8;
198
+ }
199
+
200
+ .subtitle-manager[data-theme="light"] .subtitle-word.active {
201
+ background: rgba(255, 255, 0, 0.3);
202
+ color: #000;
203
+ opacity: 1;
204
+ }
205
+
206
+ .subtitle-manager[data-theme="light"] .subtitle-tab {
207
+ color: #0066cc;
208
+ border-bottom: 1px solid #ddd;
209
+ }
210
+
211
+ .subtitle-manager[data-theme="light"] .subtitle-tab.active {
212
+ background: #e8e8e8;
213
+ }
214
+
215
+ .theme-toggle {
216
+ position: absolute;
217
+ right: 10px;
218
+ top: 10px;
219
+ padding: 4px 8px;
220
+ background: transparent;
221
+ border: 1px solid currentColor;
222
+ color: inherit;
223
+ cursor: pointer;
224
+ border-radius: 4px;
225
+ font-size: 12px;
226
+ }
227
+
228
+ .subtitle-toggle.theme-toggle {
229
+ left: -30px;
230
+ width: 30px;
231
+ height: 30px;
232
+ background: rgba(33, 33, 33, 0.95);
233
+ border: none;
234
+ color: white;
235
+ cursor: pointer;
236
+ display: flex;
237
+ align-items: center;
238
+ justify-content: center;
239
+ border-radius: 4px 0 0 4px;
240
+ }
241
+
242
+ .subtitle-manager[data-theme="light"] .timestamp {
243
+ background: rgba(220, 220, 220, 0.9);
244
+ color: #333;
245
+ }
246
+
247
+ .subtitle-manager[data-theme="light"] .subtitle-line .timestamp {
248
+ opacity: 0;
249
+ transition: opacity 0.2s ease;
250
+ }
251
+
252
+ .subtitle-manager[data-theme="light"] .subtitle-line:hover .timestamp {
253
+ opacity: 1;
254
+ }
255
+
256
+ .word-btn {
257
+ background: none;
258
+ border: none;
259
+ padding: 1px 2px;
260
+ margin: 0;
261
+ cursor: pointer;
262
+ color: inherit;
263
+ font: inherit;
264
+ }
265
+
266
+ .word-btn:hover {
267
+ background: rgba(255, 255, 255, 0.1);
268
+ border-radius: 2px;
269
+ outline: 1px solid rgba(255, 255, 255, 0.2);
270
+ }
271
+
272
+
273
+ .line-controls {
274
+ display: flex;
275
+ gap: 2px; // Reduce from 4px
276
+ align-items: center;
277
+ margin: 0 4px; // Reduce from 8px
278
+ }
279
+
280
+
281
+ .line-btn {
282
+ width: 20px; // Reduce from 24px
283
+ height: 20px; // Reduce from 24px
284
+ font-size: 10px; // Reduce from 12px
285
+ }
286
+
287
+ .line-btn:hover {
288
+ opacity: 1;
289
+ background: rgba(255, 255, 255, 0.1);
290
+ }
291
+
292
+ .subtitle-line {
293
+ display: flex;
294
+ align-items: center;
295
+ }
296
+
297
+ .subtitle-text {
298
+ flex: 1;
299
+ padding: 0 8px;
300
+ }
301
+ .subtitle-manager[data-theme="light"] .word-btn:hover {
302
+ background: rgba(0, 0, 0, 0.05);
303
+ outline: 1px solid rgba(0, 0, 0, 0.1);
304
+ }
305
+
306
+ // Keep active highlight styles
307
+ .subtitle-word.active {
308
+ background: rgba(255, 255, 255, 0.3);
309
+ color: #fff;
310
+ opacity: 1;
311
+ border-radius: 2px;
312
+ }
313
+
314
+ .subtitle-manager[data-theme="light"] .subtitle-word.active {
315
+ background: rgba(255, 255, 0, 0.3);
316
+ color: #000;
317
+ opacity: 1;
318
+ }
319
  `;
320
 
321
  // Apply main styles
 
620
  });
621
  });
622
  }
623
+ toggleTheme() {
624
+ this.currentTheme = this.currentTheme === 'dark' ? 'light' : 'dark';
625
+ this.container.dataset.theme = this.currentTheme;
626
+ }
627
 
628
  setupUI() {
629
  debug.log('Setting up UI');
 
637
  toggleButton.className = 'subtitle-toggle';
638
  toggleButton.textContent = '≡'; // Use textContent instead of innerHTML
639
 
640
+ const themeToggle = document.createElement('button');
641
+ themeToggle.className = 'subtitle-toggle theme-toggle';
642
+ themeToggle.style.top = '50px'; // Position below toggle button
643
+ themeToggle.textContent = '☀';
644
+ themeToggle.addEventListener('click', () => this.toggleTheme());
645
  // Create tabs container
646
  const tabs = document.createElement('div');
647
  tabs.className = 'subtitle-tabs';
 
668
 
669
  // Append elements
670
  this.container.appendChild(toggleButton);
671
+ this.container.appendChild(themeToggle);
672
  this.container.appendChild(tabs);
673
  this.container.appendChild(content);
674
 
 
684
  // Add toggle functionality
685
  toggleButton.addEventListener('click', () => this.toggleCollapse());
686
 
687
+ // Add theme toggle button
688
+
689
+
690
  } catch (error) {
691
  debug.error('Error setting up UI:', error);
692
  }
 
700
  // Update displaySingleLanguage method
701
  displaySingleLanguage(container, subtitles) {
702
  subtitles.forEach((sub, index) => {
 
703
  if (sub.words && sub.words.length > 0) {
704
  const line = document.createElement('div');
705
  line.className = 'subtitle-line';
706
+
707
+ // Add prefix buttons
708
+ const prefixControls = document.createElement('div');
709
+ prefixControls.className = 'line-controls';
710
+ ['↑', '★'].forEach(text => {
711
+ const btn = document.createElement('button');
712
+ btn.className = 'line-btn';
713
+ btn.textContent = text;
714
+ btn.onclick = (e) => {
715
+ e.stopPropagation(); // Prevent line click
716
+ console.log(`Prefix button ${text} clicked for line ${index}`);
717
+ };
718
+ prefixControls.appendChild(btn);
719
+ });
720
+ line.appendChild(prefixControls);
721
+
722
+ // Add subtitle text container
723
+ const textContainer = document.createElement('div');
724
+ textContainer.className = 'subtitle-text';
725
+
726
  sub.words.forEach((word, i) => {
727
  if (word.text && word.text.trim()) {
728
+ const wordBtn = document.createElement('button');
729
+ wordBtn.className = 'word-btn subtitle-word'; // Add subtitle-word class for highlighting
730
+ wordBtn.textContent = word.text.trim();
731
+ wordBtn.dataset.start = word.startTime;
732
+ wordBtn.dataset.end = word.endTime;
733
+ wordBtn.onclick = (e) => {
734
+ e.stopPropagation(); // Prevent line click
735
+ // const video = document.querySelector('video');
736
+ // if (video) {
737
+ // video.currentTime = parseFloat(word.startTime);
738
+ // }
739
+ console.log(`You click "${word.text.trim()}" word`);
740
+ };
741
+ textContainer.appendChild(wordBtn);
742
+
743
  if (i < sub.words.length - 1) {
744
+ textContainer.appendChild(document.createTextNode(' '));
745
  }
746
  }
747
  });
748
+ line.appendChild(textContainer);
749
+
750
+ // Add suffix buttons
751
+ const suffixControls = document.createElement('div');
752
+ suffixControls.className = 'line-controls';
753
+ ['✎', '↓'].forEach(text => {
754
+ const btn = document.createElement('button');
755
+ btn.className = 'line-btn';
756
+ btn.textContent = text;
757
+ btn.onclick = (e) => {
758
+ e.stopPropagation(); // Prevent line click
759
+ console.log(`Suffix button ${text} clicked for line ${index}`);
760
+ };
761
+ suffixControls.appendChild(btn);
762
+ });
763
+ line.appendChild(suffixControls);
764
+
765
+ // Add timestamp
766
+ const timestamp = document.createElement('span');
767
+ timestamp.className = 'timestamp';
768
+ timestamp.textContent = this.formatTime(sub.startTime);
769
+ line.appendChild(timestamp);
770
+
771
+ line.dataset.time = sub.startTime;
772
+ line.dataset.index = index;
773
+ container.appendChild(line);
774
  }
775
  });
776
  }
/345/261/217/345/271/225/346/210/252/345/233/276 2025-01-05 180757.png ADDED