mixed 模式
Browse files- youtube_sub.js +96 -35
youtube_sub.js
CHANGED
|
@@ -346,6 +346,35 @@ GM_addStyle(`
|
|
| 346 |
font-size: 14px;
|
| 347 |
line-height: 1.6;
|
| 348 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
`;
|
| 350 |
|
| 351 |
// Add popup HTML
|
|
@@ -906,20 +935,20 @@ GM_addStyle(`
|
|
| 906 |
});
|
| 907 |
line.appendChild(textContainer);
|
| 908 |
|
| 909 |
-
// Add suffix buttons
|
| 910 |
-
const suffixControls = document.createElement('div');
|
| 911 |
-
suffixControls.className = 'line-controls';
|
| 912 |
-
['✎', '↓'].forEach(text => {
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
});
|
| 922 |
-
line.appendChild(suffixControls);
|
| 923 |
|
| 924 |
// Add timestamp
|
| 925 |
const timestamp = document.createElement('span');
|
|
@@ -936,38 +965,70 @@ GM_addStyle(`
|
|
| 936 |
|
| 937 |
displayMixed(container) {
|
| 938 |
const maxLength = Math.max(
|
| 939 |
-
this.subtitles.english
|
| 940 |
-
this.subtitles.chinese
|
| 941 |
);
|
| 942 |
-
|
| 943 |
for (let i = 0; i < maxLength; i++) {
|
| 944 |
const line = document.createElement('div');
|
| 945 |
line.className = 'subtitle-line mixed-line';
|
| 946 |
-
|
| 947 |
-
|
| 948 |
-
const
|
| 949 |
-
|
| 950 |
-
|
| 951 |
-
|
| 952 |
-
enText.textContent = enSub?.text || '';
|
| 953 |
-
|
| 954 |
const zhText = document.createElement('div');
|
| 955 |
zhText.className = 'zh-text';
|
| 956 |
-
|
| 957 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 958 |
const timestamp = document.createElement('span');
|
| 959 |
timestamp.className = 'timestamp';
|
| 960 |
-
timestamp.textContent =
|
| 961 |
-
|
| 962 |
-
line.appendChild(enText);
|
| 963 |
-
line.appendChild(zhText);
|
| 964 |
line.appendChild(timestamp);
|
| 965 |
-
|
| 966 |
-
if (
|
| 967 |
-
line.dataset.time =
|
| 968 |
line.dataset.index = i;
|
| 969 |
}
|
| 970 |
-
|
| 971 |
container.appendChild(line);
|
| 972 |
}
|
| 973 |
}
|
|
|
|
| 346 |
font-size: 14px;
|
| 347 |
line-height: 1.6;
|
| 348 |
}
|
| 349 |
+
|
| 350 |
+
.mixed-text-container {
|
| 351 |
+
display: flex;
|
| 352 |
+
flex-direction: column;
|
| 353 |
+
gap: 8px;
|
| 354 |
+
flex: 1;
|
| 355 |
+
padding: 0 8px;
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
.mixed-line {
|
| 359 |
+
display: flex;
|
| 360 |
+
align-items: flex-start;
|
| 361 |
+
padding: 15px;
|
| 362 |
+
gap: 8px;
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
.zh-text {
|
| 366 |
+
color: #fff;
|
| 367 |
+
font-size: 14px;
|
| 368 |
+
line-height: 1.5;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
.en-text {
|
| 372 |
+
color: #aaa;
|
| 373 |
+
font-size: 14px;
|
| 374 |
+
line-height: 1.5;
|
| 375 |
+
border-top: 1px solid rgba(255,255,255,0.1);
|
| 376 |
+
padding-top: 8px;
|
| 377 |
+
}
|
| 378 |
`;
|
| 379 |
|
| 380 |
// Add popup HTML
|
|
|
|
| 935 |
});
|
| 936 |
line.appendChild(textContainer);
|
| 937 |
|
| 938 |
+
// // Add suffix buttons
|
| 939 |
+
// const suffixControls = document.createElement('div');
|
| 940 |
+
// suffixControls.className = 'line-controls';
|
| 941 |
+
// ['✎', '↓'].forEach(text => {
|
| 942 |
+
// const btn = document.createElement('button');
|
| 943 |
+
// btn.className = 'line-btn';
|
| 944 |
+
// btn.textContent = text;
|
| 945 |
+
// btn.onclick = (e) => {
|
| 946 |
+
// e.stopPropagation(); // Prevent line click
|
| 947 |
+
// console.log(`Suffix button ${text} clicked for line ${index}`);
|
| 948 |
+
// };
|
| 949 |
+
// suffixControls.appendChild(btn);
|
| 950 |
+
// });
|
| 951 |
+
// line.appendChild(suffixControls);
|
| 952 |
|
| 953 |
// Add timestamp
|
| 954 |
const timestamp = document.createElement('span');
|
|
|
|
| 965 |
|
| 966 |
displayMixed(container) {
|
| 967 |
const maxLength = Math.max(
|
| 968 |
+
this.subtitles.english?.length || 0,
|
| 969 |
+
this.subtitles.chinese?.length || 0
|
| 970 |
);
|
| 971 |
+
|
| 972 |
for (let i = 0; i < maxLength; i++) {
|
| 973 |
const line = document.createElement('div');
|
| 974 |
line.className = 'subtitle-line mixed-line';
|
| 975 |
+
|
| 976 |
+
// Text container
|
| 977 |
+
const textContainer = document.createElement('div');
|
| 978 |
+
textContainer.className = 'mixed-text-container';
|
| 979 |
+
|
| 980 |
+
// Chinese text with word buttons
|
|
|
|
|
|
|
| 981 |
const zhText = document.createElement('div');
|
| 982 |
zhText.className = 'zh-text';
|
| 983 |
+
if (this.subtitles.chinese[i]?.words) {
|
| 984 |
+
this.subtitles.chinese[i].words.forEach((word, idx) => {
|
| 985 |
+
const wordBtn = document.createElement('button');
|
| 986 |
+
wordBtn.className = 'word-btn subtitle-word';
|
| 987 |
+
wordBtn.textContent = word.text;
|
| 988 |
+
wordBtn.dataset.start = word.startTime;
|
| 989 |
+
wordBtn.dataset.end = word.endTime;
|
| 990 |
+
zhText.appendChild(wordBtn);
|
| 991 |
+
if (idx < this.subtitles.chinese[i].words.length - 1) {
|
| 992 |
+
zhText.appendChild(document.createTextNode(' '));
|
| 993 |
+
}
|
| 994 |
+
});
|
| 995 |
+
} else {
|
| 996 |
+
zhText.textContent = '翻译中...';
|
| 997 |
+
}
|
| 998 |
+
|
| 999 |
+
// English text with word buttons
|
| 1000 |
+
const enText = document.createElement('div');
|
| 1001 |
+
enText.className = 'en-text';
|
| 1002 |
+
if (this.subtitles.english[i]?.words) {
|
| 1003 |
+
this.subtitles.english[i].words.forEach((word, idx) => {
|
| 1004 |
+
const wordBtn = document.createElement('button');
|
| 1005 |
+
wordBtn.className = 'word-btn subtitle-word';
|
| 1006 |
+
wordBtn.textContent = word.text;
|
| 1007 |
+
wordBtn.dataset.start = word.startTime;
|
| 1008 |
+
wordBtn.dataset.end = word.endTime;
|
| 1009 |
+
enText.appendChild(wordBtn);
|
| 1010 |
+
if (idx < this.subtitles.english[i].words.length - 1) {
|
| 1011 |
+
enText.appendChild(document.createTextNode(' '));
|
| 1012 |
+
}
|
| 1013 |
+
});
|
| 1014 |
+
}
|
| 1015 |
+
|
| 1016 |
+
textContainer.appendChild(zhText);
|
| 1017 |
+
textContainer.appendChild(enText);
|
| 1018 |
+
line.appendChild(textContainer);
|
| 1019 |
+
|
| 1020 |
+
// Add timestamp
|
| 1021 |
const timestamp = document.createElement('span');
|
| 1022 |
timestamp.className = 'timestamp';
|
| 1023 |
+
timestamp.textContent = this.subtitles.english[i] ?
|
| 1024 |
+
this.formatTime(this.subtitles.english[i].startTime) : '';
|
|
|
|
|
|
|
| 1025 |
line.appendChild(timestamp);
|
| 1026 |
+
|
| 1027 |
+
if (this.subtitles.english[i]) {
|
| 1028 |
+
line.dataset.time = this.subtitles.english[i].startTime;
|
| 1029 |
line.dataset.index = i;
|
| 1030 |
}
|
| 1031 |
+
|
| 1032 |
container.appendChild(line);
|
| 1033 |
}
|
| 1034 |
}
|