diff --git a/extension/background.js b/extension/background.js index 4698a04..3c550cc 100644 --- a/extension/background.js +++ b/extension/background.js @@ -531,6 +531,20 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { connect(); // We wait for status update in handleServerEvent }); + } else if (message.type === 'GET_VIDEO_STATE') { + const { tabId } = message; + if (!tabId) { + sendResponse({ error: 'No tabId provided' }); + return; + } + chrome.tabs.sendMessage(tabId, { type: 'GET_VIDEO_STATE' }, (res) => { + if (chrome.runtime.lastError) { + sendResponse({ error: chrome.runtime.lastError.message }); + } else { + sendResponse(res); + } + }); + return true; // Keep channel open } else if (message.type === 'CONTENT_EVENT') { if (sender.tab) { currentTabId = sender.tab.id; diff --git a/extension/content.js b/extension/content.js index fd0226a..904395e 100644 --- a/extension/content.js +++ b/extension/content.js @@ -146,6 +146,24 @@ tryMediaAction(EVENTS.PLAY); } } + + if (message.type === 'GET_VIDEO_STATE') { + const video = findVideo(); + if (video) { + sendResponse({ + paused: video.paused, + currentTime: video.currentTime, + duration: video.duration || 0, + readyState: video.readyState, + muted: video.muted, + playbackRate: video.playbackRate, + url: window.location.href, + id: video.id || 'none' + }); + } else { + sendResponse({ error: 'No video found' }); + } + } }); // Detect native events diff --git a/extension/popup.html b/extension/popup.html index 1c7965d..2397091 100644 --- a/extension/popup.html +++ b/extension/popup.html @@ -200,15 +200,12 @@
+
-
- - -
@@ -301,12 +298,30 @@
+ + +
+
+ + +
+ +
+ + +
+ +
+

• Username helps others identify you.

+

• Noise filtering hides tabs without videos.

+
+
-
- - + +
+ No tab selected or video detected.
diff --git a/extension/popup.js b/extension/popup.js index 48a68f4..6c2b6b3 100644 --- a/extension/popup.js +++ b/extension/popup.js @@ -44,6 +44,7 @@ const elements = { activeServer: document.getElementById('activeServer'), peerList: document.getElementById('peerList'), peerListSync: document.getElementById('peerListSync'), + videoDebug: document.getElementById('videoDebug'), playBtn: document.getElementById('playBtn'), pauseBtn: document.getElementById('pauseBtn') }; @@ -89,6 +90,9 @@ async function init() { // Initial room list fetch chrome.runtime.sendMessage({ type: 'GET_ROOM_LIST' }); + + // Debug Info Refresh + setInterval(refreshDebugInfo, 2000); } // --- UI Logic --- @@ -575,5 +579,36 @@ elements.copyLogs.addEventListener('click', () => { }); }); +function refreshDebugInfo() { + // Only refresh if Dev tab is visible + const devTab = document.getElementById('tab-dev'); + if (!devTab || devTab.style.display === 'none') return; + + chrome.runtime.sendMessage({ type: 'GET_STATUS' }, (res) => { + if (!res || !res.targetTabId) { + if (elements.videoDebug) elements.videoDebug.textContent = 'No target tab selected.'; + return; + } + + // Request direct state from the content script via background + chrome.runtime.sendMessage({ type: 'GET_VIDEO_STATE', tabId: res.targetTabId }, (state) => { + if (!state || state.error) { + if (elements.videoDebug) elements.videoDebug.textContent = 'Could not communicate with tab video.'; + return; + } + + if (elements.videoDebug) { + elements.videoDebug.innerHTML = ` +
VIDEO STATE: ${state.paused ? 'PAUSED' : 'PLAYING'}
+
Time: ${state.currentTime.toFixed(2)}s / ${state.duration.toFixed(2)}s
+
ReadyState: ${state.readyState}
+
Muted: ${state.muted} | PlaybackRate: ${state.playbackRate}
+
URL: ${state.url.substring(0, 40)}...
+ `; + } + }); + }); +} + init(); setInterval(refreshLogs, 5000);