11const PROGRESS_PREFIX = 'streamit:progress:' ;
22let currentVideoSrc = '' ;
33
4+ /**
5+ * Generates a unique key for storing video progress in localStorage.
6+ * @param {string } src - The video source URL.
7+ * @returns {string } The generated storage key.
8+ */
49function progressKey ( src ) {
510 return `${ PROGRESS_PREFIX } ${ src } ` ;
611}
712
13+ /**
14+ * Restores video playback progress from localStorage.
15+ * @param {HTMLVideoElement } player - The video player element.
16+ * @param {string } src - The video source URL.
17+ */
818function restoreProgress ( player , src ) {
919 const saved = parseFloat ( localStorage . getItem ( progressKey ( src ) ) || '' ) ;
1020 if ( Number . isNaN ( saved ) ) return ;
@@ -19,6 +29,10 @@ function restoreProgress(player, src) {
1929 else player . addEventListener ( 'loadedmetadata' , applyTime ) ;
2030}
2131
32+ /**
33+ * Persists video playback progress to localStorage.
34+ * @param {HTMLVideoElement } player - The video player element.
35+ */
2236function persistProgress ( player ) {
2337 if ( ! currentVideoSrc ) return ;
2438 const key = progressKey ( currentVideoSrc ) ;
@@ -29,6 +43,10 @@ function persistProgress(player) {
2943 else localStorage . setItem ( key , String ( t ) ) ;
3044}
3145
46+ /**
47+ * Plays a video in the overlay player.
48+ * @param {string } src - The video source URL.
49+ */
3250export function playVideo ( src ) {
3351 const overlay = document . getElementById ( 'videoOverlay' ) ;
3452 const player = document . getElementById ( 'mainPlayer' ) ;
@@ -48,6 +66,9 @@ export function playVideo(src) {
4866 } , 50 ) ;
4967}
5068
69+ /**
70+ * Closes the video overlay and stops playback.
71+ */
5172export function closeVideo ( ) {
5273 const overlay = document . getElementById ( 'videoOverlay' ) ;
5374 const player = document . getElementById ( 'mainPlayer' ) ;
@@ -57,11 +78,17 @@ export function closeVideo() {
5778 overlay . classList . add ( 'hidden' ) ;
5879}
5980
81+ /**
82+ * Toggles the notifications dropdown visibility.
83+ */
6084export function toggleNotifs ( ) {
6185 const dropdown = document . getElementById ( 'notifDropdown' ) ;
6286 dropdown . classList . toggle ( 'active' ) ;
6387}
6488
89+ /**
90+ * Toggles the mobile menu visibility.
91+ */
6592export function toggleMobileMenu ( ) {
6693 const menu = document . getElementById ( 'mobileMenuPanel' ) ;
6794 const search = document . getElementById ( 'mobileSearchPanel' ) ;
@@ -73,6 +100,9 @@ export function toggleMobileMenu() {
73100 menu . classList . toggle ( 'active' ) ;
74101}
75102
103+ /**
104+ * Toggles the mobile search panel visibility.
105+ */
76106export function toggleMobileSearch ( ) {
77107 const search = document . getElementById ( 'mobileSearchPanel' ) ;
78108 const menu = document . getElementById ( 'mobileMenuPanel' ) ;
@@ -88,17 +118,26 @@ export function toggleMobileSearch() {
88118 }
89119}
90120
121+ /**
122+ * Shows the loading spinner.
123+ */
91124export function showLoader ( ) {
92125 document . getElementById ( 'loader' ) . classList . remove ( 'hidden' ) ;
93126 document . getElementById ( 'loader' ) . style . opacity = '1' ;
94127}
95128
129+ /**
130+ * Hides the loading spinner with a fade-out effect.
131+ */
96132export function hideLoader ( ) {
97133 const loader = document . getElementById ( 'loader' ) ;
98134 loader . style . opacity = '0' ;
99135 setTimeout ( ( ) => loader . classList . add ( 'hidden' ) , 700 ) ;
100136}
101137
138+ /**
139+ * Enhances video player controls to prevent downloading and remote playback.
140+ */
102141export function hardenPlayerControls ( ) {
103142 const player = document . getElementById ( 'mainPlayer' ) ;
104143 if ( ! player ) return ;
@@ -109,6 +148,9 @@ export function hardenPlayerControls() {
109148 player . addEventListener ( 'contextmenu' , ( e ) => e . preventDefault ( ) ) ;
110149}
111150
151+ /**
152+ * Initializes video player progress persistence.
153+ */
112154export function initPlayerPersistence ( ) {
113155 const player = document . getElementById ( 'mainPlayer' ) ;
114156 if ( ! player ) return ;
0 commit comments