Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files8 unmodified lines9101112131454 unmodified lines69707172737475763 unmodified lines8081828384858613 unmodified lines1001011021031041051061071081091101111121131141151 unmodified line1171181191201211221233 unmodified lines127128129130131132133134135136137138139192 unmodified lines3323333343353363373383393403413423433441 unmodified line3463473483493503513528 unmodified lineslet speakerData = {};// UI要素const hamburger = document.querySelector('.hamburger');const nav = document.querySelector('.nav');54 unmodified linesupdateSpeakerColorUI();});socket.on('new_subtitle', (data) => {if (!data || !subtitleContainer) return;if (!speakerData[data.speaker_id]) {socket.emit('request_speaker_profiles');3 unmodified linesconst displayName = info.name;const displayColor = info.color;// 輝度判定による色の自動調整let logNameColor = displayColor;const isDarkMode = document.body.classList.contains('dark-mode');13 unmodified linesconst lum = getLuminance(logNameColor);if (isDarkMode) {if (lum < 60) {logNameColor = '#FFFFFF';}} else {if (lum > 190) {logNameColor = '#000000';}}// 履歴if (historyList) {const li = document.createElement('li');li.innerHTML = `<span style="font-weight:bold; color:${logNameColor}">${displayName}:</span> ${data.translated}`;1 unmodified lineif (historyList.children.length > 30) historyList.removeChild(historyList.lastChild);}// 字幕const p = document.createElement('p');p.className = 'subtitle-line';p.style.fontSize = currentFontSize;3 unmodified linesapplySubtitleBackground(p);subtitleContainer.appendChild(p);while (subtitleContainer.children.length > 6) {subtitleContainer.removeChild(subtitleContainer.firstChild);}setTimeout(() => p.style.opacity = '0', 3500);setTimeout(() => p.remove(), 4000);});socket.on("speaker_name_changed", data => {const { id, new_name } = data;192 unmodified lines});}// ▼▼▼ シアターモード切替ロジック (修正) ▼▼▼if (document.getElementById('video-container')) {const container = document.getElementById('video-container');if (theaterBtn) {theaterBtn.addEventListener('click', () => {document.body.classList.add('theater-active'); // Bodyにクラス追加container.classList.add('theater-mode');container.classList.remove('normal-mode');});1 unmodified lineif (closeTheaterBtn) {closeTheaterBtn.addEventListener('click', () => {document.body.classList.remove('theater-active'); // Bodyからクラス削除container.classList.remove('theater-mode');container.classList.add('normal-mode');});8 unmodified lines9101112131415161754 unmodified lines727374757677787980818283848586878889909192939495969798991001011021033 unmodified lines10710810911011111211313 unmodified lines1271281291301311321331341351361371381 unmodified line1401411421431441451463 unmodified lines150151152153154155156157158159160161162163164165166167168169170171192 unmodified lines3643653663673683693703713723733743751 unmodified line3773783793803813823838 unmodified lineslet speakerData = {};// ▼▼▼ 暫定表示用の要素ID ▼▼▼const PREVIEW_ID = 'subtitle-preview-line';// UI要素const hamburger = document.querySelector('.hamburger');const nav = document.querySelector('.nav');54 unmodified linesupdateSpeakerColorUI();});// ▼▼▼ 修正: 字幕受信ロジックの大幅変更 ▼▼▼socket.on('new_subtitle', (data) => {if (!data || !subtitleContainer) return;// 1. 暫定結果 (Interim) の場合if (!data.is_final) {let p = document.getElementById(PREVIEW_ID);if (!p) {p = document.createElement('p');p.id = PREVIEW_ID;p.className = 'subtitle-line';p.style.fontSize = currentFontSize;p.style.color = '#AAAAAA'; // 薄いグレーp.style.fontStyle = 'italic'; // 斜体subtitleContainer.appendChild(p);}// 暫定翻訳を表示p.textContent = `... ${data.translated}`;applySubtitleBackground(p);return; // 履歴には追加せず終了}// 2. 確定結果 (Final) の場合// 暫定表示を消すconst previewEl = document.getElementById(PREVIEW_ID);if (previewEl) previewEl.remove();if (!speakerData[data.speaker_id]) {socket.emit('request_speaker_profiles');3 unmodified linesconst displayName = info.name;const displayColor = info.color;// 輝度判定let logNameColor = displayColor;const isDarkMode = document.body.classList.contains('dark-mode');13 unmodified linesconst lum = getLuminance(logNameColor);if (isDarkMode) {if (lum < 60) logNameColor = '#FFFFFF';} else {if (lum > 190) logNameColor = '#000000';}// 履歴に追加if (historyList) {const li = document.createElement('li');li.innerHTML = `<span style="font-weight:bold; color:${logNameColor}">${displayName}:</span> ${data.translated}`;1 unmodified lineif (historyList.children.length > 30) historyList.removeChild(historyList.lastChild);}// 字幕表示const p = document.createElement('p');p.className = 'subtitle-line';p.style.fontSize = currentFontSize;3 unmodified linesapplySubtitleBackground(p);subtitleContainer.appendChild(p);// 古い字幕を消すwhile (subtitleContainer.children.length > 6) {// プレビュー要素以外を消すconst first = subtitleContainer.firstChild;if (first.id === PREVIEW_ID) {if(subtitleContainer.children.length > 1) subtitleContainer.removeChild(subtitleContainer.children[1]);else break;} else {subtitleContainer.removeChild(first);}}setTimeout(() => p.style.opacity = '0', 3500);setTimeout(() => p.remove(), 4000);});// ▲▲▲ 修正ここまで ▲▲▲socket.on("speaker_name_changed", data => {const { id, new_name } = data;192 unmodified lines});}if (document.getElementById('video-container')) {const container = document.getElementById('video-container');if (theaterBtn) {theaterBtn.addEventListener('click', () => {document.body.classList.add('theater-active');container.classList.add('theater-mode');container.classList.remove('normal-mode');});1 unmodified lineif (closeTheaterBtn) {closeTheaterBtn.addEventListener('click', () => {document.body.classList.remove('theater-active');container.classList.remove('theater-mode');container.classList.add('normal-mode');});
static/script.js+44-13