js/utils.js
Utility functions for video playback, UI toggles, loader management, and video player enhancements.
Methods
(static) closeVideo()
Closes the video overlay and stops playback.
(static) downloadProgressBackup()
Downloads a JSON backup of watch progress.
(static) getEpisodeWatchData(seriesTitle, season, epIndex) → {Object}
Retrieves watch data for a specific series episode.
Parameters:
| Name | Type | Description |
|---|---|---|
seriesTitle |
string | Series title. |
season |
string | number | Season number. |
epIndex |
number | Episode index (0-based). |
Returns:
Watch data object with watched boolean and time number.
- Type
- Object
(static) getFilmWatchData(title) → {Object}
Retrieves watch data for a specific film.
Parameters:
| Name | Type | Description |
|---|---|---|
title |
string | Film title. |
Returns:
Watch data object with watched boolean and time number.
- Type
- Object
(static) getWatchedContent() → {Object}
Retrieves watched content data from localStorage.
Returns:
Object with films and series watch data.
- Type
- Object
(static) hardenPlayerControls()
Enhances video player controls to prevent downloading and remote playback.
(static) hideLoader()
Hides the loading spinner with a fade-out effect.
(static) importProgressFromFile(file) → {Promise.<Object>}
Imports watch progress from a JSON file.
Parameters:
| Name | Type | Description |
|---|---|---|
file |
File | The file to import. |
Returns:
Object with filmsCount and seriesCount.
- Type
- Promise.<Object>
(static) initPlayerPersistence()
Initializes video player progress persistence.
(static) isSeriesFullyWatched(series) → {boolean}
Checks if all episodes of a series have been watched.
Parameters:
| Name | Type | Description |
|---|---|---|
series |
Object | Series object with seasons data. |
Returns:
True if all episodes are watched, false otherwise.
- Type
- boolean
(static) openProgressImport()
Opens the file input dialog for importing progress data.
(static) playVideo(src, context)
Plays a video in the overlay player with optional watch context.
Parameters:
| Name | Type | Description |
|---|---|---|
src |
string | The video source URL. |
context |
Object | null | Optional playback context {type, title, season, episodeIndex}. |
(static) showLoader()
Shows the loading spinner.
(static) toggleMobileMenu()
Toggles the mobile menu visibility.
(static) toggleMobileSearch()
Toggles the mobile search panel visibility.
(static) toggleNotifs()
Toggles the notifications dropdown visibility.
(static) toggleSettings()
Toggles the settings dropdown visibility.
(inner) applyStartTime(player, startTime)
Applies a saved start time (resume) when metadata is available.
Parameters:
| Name | Type | Description |
|---|---|---|
player |
HTMLVideoElement | The video player element. |
startTime |
number | Time in seconds to seek to. |
(inner) cleanupCustomVideoControls()
Cleans up custom video controls event listeners
(inner) formatTime(seconds) → {string}
Formats time in seconds to MM:SS or HH:MM:SS
Parameters:
| Name | Type | Description |
|---|---|---|
seconds |
number | Time in seconds |
Returns:
Formatted time string
- Type
- string
(inner) getResumeTime(src, context) → {number}
Gets the resume time for a video based on context or fallback.
Parameters:
| Name | Type | Description |
|---|---|---|
src |
string | Video source URL. |
context |
Object | null | Playback context. |
Returns:
Resume time in seconds.
- Type
- number
(inner) handleKeyboardControls(e)
Handles keyboard controls
Parameters:
| Name | Type | Description |
|---|---|---|
e |
KeyboardEvent | Keyboard event |
(inner) hideControls()
Hides video controls
(inner) initCustomVideoControls()
Initializes all custom video player controls
(inner) markEpisodeWatched(seriesTitle, season, epIndex, watchedopt, timeopt)
Marks a series episode as watched or updates its progress.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
seriesTitle |
string | Series title. | ||
season |
string | number | Season number. | ||
epIndex |
number | Episode index (0-based). | ||
watched |
boolean |
<optional> |
true | Whether the episode is watched. |
time |
number |
<optional> |
0 | Current playback time in seconds. |
(inner) markFilmWatched(title, watchedopt, timeopt)
Marks a film as watched or updates its progress.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
title |
string | Film title. | ||
watched |
boolean |
<optional> |
true | Whether the film is watched. |
time |
number |
<optional> |
0 | Current playback time in seconds. |
(inner) normalizeEpisodeIndex(epIndex) → {number}
Normalizes episode index to a valid non-negative integer.
Parameters:
| Name | Type | Description |
|---|---|---|
epIndex |
any | Episode index to normalize. |
Returns:
Normalized episode index (defaults to 0).
- Type
- number
(inner) normalizeSeason(season) → {string}
Normalizes season input to a valid string.
Parameters:
| Name | Type | Description |
|---|---|---|
season |
any | Season value to normalize. |
Returns:
Normalized season string (defaults to '1').
- Type
- string
(inner) persistGenericProgress(player)
Persists video playback progress to localStorage (fallback when no context is provided).
Parameters:
| Name | Type | Description |
|---|---|---|
player |
HTMLVideoElement | The video player element. |
(inner) progressKey(src) → {string}
Generates a unique key for storing video progress in localStorage.
Parameters:
| Name | Type | Description |
|---|---|---|
src |
string | The video source URL. |
Returns:
The generated storage key.
- Type
- string
(inner) resetControlsTimeout()
Resets the auto-hide timeout for controls
(inner) sanitizeProgressData(raw) → {Object}
Sanitizes raw progress data to ensure valid structure.
Parameters:
| Name | Type | Description |
|---|---|---|
raw |
Object | Raw data to sanitize. |
Returns:
Sanitized data with films and series objects.
- Type
- Object
(inner) saveWatchProgress(player, isEndedopt)
Saves watch progress for the current video.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
player |
HTMLVideoElement | The video player element. | ||
isEnded |
boolean |
<optional> |
false | Whether the video has ended. |
(inner) seekToPosition(e)
Seeks to clicked position on progress bar
Parameters:
| Name | Type | Description |
|---|---|---|
e |
MouseEvent | Click event |
(inner) setWatchedContent(data)
Stores watched content data to localStorage.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Object | Watch data object containing films and series. |
(inner) showControls()
Shows video controls
(inner) showTimeTooltip(e)
Shows time tooltip on progress bar hover
Parameters:
| Name | Type | Description |
|---|---|---|
e |
MouseEvent | Mouse event |
(inner) toggleFullscreen()
Toggles fullscreen mode
(inner) toggleMute()
Toggles mute state
(inner) togglePlayPause()
Toggles play/pause state
(inner) updateBufferedProgress()
Updates buffered progress bar
(inner) updatePlayPauseIcon(isPaused)
Updates play/pause button icon
Parameters:
| Name | Type | Description |
|---|---|---|
isPaused |
boolean | Whether video is paused |
(inner) updateProgress()
Updates progress bar and time display
(inner) updateVideoTitle(context)
Updates the video title overlay based on context
Parameters:
| Name | Type | Description |
|---|---|---|
context |
Object | null | Video context {type, title, season, episodeIndex, episodeTitle} |
(inner) updateVolumeIcon(volume)
Updates volume icon based on volume level
Parameters:
| Name | Type | Description |
|---|---|---|
volume |
number | Volume level (0-1) |
(inner) updateVolumeSliderBackground(value)
Updates volume slider background gradient
Parameters:
| Name | Type | Description |
|---|---|---|
value |
number | Slider value (0-100) |