From 5c13201af1fcfb712ffc8143319da03718976d82 Mon Sep 17 00:00:00 2001 From: Zhibo Wang Date: Mon, 3 Nov 2025 16:42:20 +0800 Subject: [PATCH] Use a sidebar menu --- blur.html | 120 ++++++++++++++++++++++++++++++++++++++------------- menu.js | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 216 insertions(+), 30 deletions(-) create mode 100644 menu.js diff --git a/blur.html b/blur.html index dc07f71..462b91a 100644 --- a/blur.html +++ b/blur.html @@ -14,9 +14,6 @@ @@ -41,28 +91,31 @@ -
+ +
Select renderer and click Start to begin video processing
FPS: --
-
+ +

Renderer Selection

- - - - - + + + + +
+

Selfie Segmentation Backend

+

Options

-
- - -
-
+ +

Display Settings

+ +
+ + +
+ + + + @@ -124,4 +184,4 @@

Display Settings

- \ No newline at end of file + diff --git a/menu.js b/menu.js new file mode 100644 index 0000000..25ae328 --- /dev/null +++ b/menu.js @@ -0,0 +1,126 @@ +(function () { + const settingsForm = document.getElementById('settings-form'); + const floatBtn = document.getElementById('floatBtn'); + const processedVideo = document.getElementById('processedVideo'); + const startButton = document.getElementById('startButton'); + const stopButton = document.getElementById('stopButton'); + + let hideTimer = null; + let videoRunning = false; + + function showMenu() { + settingsForm.classList.remove('hidden'); + floatBtn.classList.remove('visible'); + } + + function hideMenu() { + settingsForm.classList.add('hidden'); + } + + function showFloatBtn() { + floatBtn.classList.add('visible'); + } + + function hideFloatBtn() { + floatBtn.classList.remove('visible'); + } + + function clearHideTimer() { + if (hideTimer) { + clearTimeout(hideTimer); + hideTimer = null; + } + } + + function resetHideTimer() { + if (!videoRunning) return; + showMenu(); + clearHideTimer(); + hideTimer = setTimeout(() => { + hideMenu(); + showFloatBtn(); + }, 5000); + } + + if (startButton) { + startButton.addEventListener('click', (e) => { + videoRunning = true; + resetHideTimer(); + }); + } + + if (stopButton) { + stopButton.addEventListener('click', (e) => { + videoRunning = false; + clearHideTimer(); + showMenu(); + hideFloatBtn(); + }); + } + + if (processedVideo) { + processedVideo.addEventListener('playing', () => { + videoRunning = true; + resetHideTimer(); + }); + processedVideo.addEventListener('pause', () => { + videoRunning = false; + clearHideTimer(); + showMenu(); + hideFloatBtn(); + }); + processedVideo.addEventListener('ended', () => { + videoRunning = false; + clearHideTimer(); + showMenu(); + hideFloatBtn(); + }); + } + + settingsForm.addEventListener('mouseenter', () => { + clearHideTimer(); + }); + settingsForm.addEventListener('mouseleave', () => { + if (videoRunning) resetHideTimer(); + }); + + document.addEventListener('mousemove', (e) => { + if (!videoRunning) return; + + if (settingsForm.classList.contains('hidden')) { + showFloatBtn(); + } else { + resetHideTimer(); + } + }); + + floatBtn.addEventListener('click', (e) => { + e.stopPropagation(); + showMenu(); + hideFloatBtn(); + resetHideTimer(); + }); + + settingsForm.addEventListener('click', (e) => { + e.stopPropagation(); + }); + + document.addEventListener('click', (e) => { + if (!videoRunning) return; + if (settingsForm.contains(e.target) || floatBtn.contains(e.target)) return; + hideMenu(); + showFloatBtn(); + clearHideTimer(); + }); + + window.addEventListener('load', () => { + if (processedVideo && !processedVideo.paused && !processedVideo.ended) { + videoRunning = true; + resetHideTimer(); + } else { + videoRunning = false; + showMenu(); + hideFloatBtn(); + } + }); +})();