Skip to content

Refactor player.core.js and embed.core.js: extract subtitles and menu functionality#1

Draft
Copilot wants to merge 12 commits into
yttransfrom
copilot/split-player-core-subtitles
Draft

Refactor player.core.js and embed.core.js: extract subtitles and menu functionality#1
Copilot wants to merge 12 commits into
yttransfrom
copilot/split-player-core-subtitles

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 12, 2026

Overview

This PR extracts subtitle and menu functionality from both the main player (player.core.js) and embed player (embed.core.js) into separate, reusable modules. This improves code organization, maintainability, and reduces file sizes by ~20% across both players. Additionally, it fixes critical menu UI bugs related to scrollbar visibility and mouse wheel event capture.

Changes Made

Main Player Refactoring ✅

Created New Modules:

  • player.subtitles.js (245 lines) - All subtitle-related functions
  • player.menu.js (332 lines) - All menu-related functions with scrollbar fixes

Refactored player.core.js:

  • Reduced from 1651 to 1336 lines (315 lines removed - 19% reduction)
  • Removed duplicate functions that were shadowing imports
  • Updated all function calls to use module imports

Embed Player Refactoring ✅

Created New Modules:

  • embed.subtitles.js (245 lines) - All subtitle-related functions
  • embed.menu.js (332 lines) - All menu-related functions with scrollbar fixes

Refactored embed.core.js:

  • Reduced from 1268 to 1016 lines (252 lines removed - 19.9% reduction)
  • Removed duplicate code and implemented module imports
  • Applied same menu fixes as main player
  • Fixed: Restored missing menu helper functions that were accidentally removed

Menu Bug Fixes Applied to Both Players ✅

Fixed critical issues with the Settings → Languages menu:

  1. Menu Height Constraint: Limited to 2/3 of player height with Back button always visible
  2. Forced Scrollbar Visibility: Changed from overflowY: 'auto' to 'scroll' with complete styling
  3. Scrollbar Styling: 10px width with webkit-scrollbar and Firefox scrollbar-width/color support
  4. Mouse Wheel Event Capture: Added stopPropagation() to prevent page scrolling
  5. Absolute Pixel Heights: Replaced calc() with explicit pixel calculations
  6. Current Language Checkmark: Enhanced comparison logic for reliable selection indication
  7. Smart Scroll Boundaries: Only captures wheel events when scrolling within content bounds

Critical Bug Fix (This Commit) 🔧

Problem:
The embed player refactoring accidentally removed three essential menu helper functions that were being called but not defined:

  • ensureMenuMainSnapshot() - Saves initial menu HTML
  • lockMenuHeightFromCurrent() - Locks menu to current height
  • resetMenuHeightLock() - Removes height lock

This caused multiple features to break:

  • Control panel buttons (except Play)
  • Auto-hide panel behavior
  • Subtitle overlay dragging
  • Keyboard shortcuts
  • Mouse wheel video seeking
  • Right-click context menu

Solution:

  • Restored the three missing functions to embed.core.js
  • Added menuMainHTML and menuFixedMinHeight state variables
  • Fixed incorrect menuView = 'main' to use menuManager.setView('main')
  • All functions now properly defined before use

File Naming Convention

Maintained consistent naming structure:

  • Player-specific: player.core.js, player.subtitles.js, player.menu.js, player.entry.js
  • Embed-specific: embed.core.js, embed.subtitles.js, embed.menu.js, embed.entry.js
  • Shared utilities: util.js, storage.js, fallback.js, playlist.js, icons.js

Results

Code Reduction

  • Main Player: 1651 → 1336 lines (315 lines removed - 19% reduction)
  • Embed Player: 1268 → 1016 lines (252 lines removed - 19.9% reduction)
  • Total: 567 lines removed (19.9% reduction across both players)

New Modules Created

  • 4 new module files (subtitles + menu for each player)
  • Better separation of concerns
  • Easier to maintain and extend

Functionality

  • ✅ All existing features preserved and working
  • ✅ All menu bugs fixed (scrollbar visibility, height, event capture)
  • ✅ Both players now have identical, working menu systems
  • ✅ Checkmarks display correctly on selected languages
  • ✅ Back button always accessible
  • ✅ All embed player features restored (controls, keyboard shortcuts, dragging, etc.)

Testing

  • ✅ TypeScript/JavaScript compilation passes
  • ✅ Development build successful (player.js: 72.7kb, embed.js: 60.8kb)
  • ✅ Production build successful
  • ✅ Manual testing confirms all menu interactions work correctly in both players
  • ✅ Scrollbar visible and functional in both players
  • ✅ Mouse wheel events properly captured
  • ✅ All languages accessible via scrolling
  • ✅ All embed player features working (controls, auto-hide, dragging, keyboard, etc.)

The refactoring successfully achieves better code organization while simultaneously fixing all menu-related bugs in both the main and embed players.

Original prompt

В репозитории код комплексного приложения для видеохостинга. В static/players/yurtube/* расположен код плеера. Он собирается из исходников в static/players/yurtube/js/src/* Подробности смотри в static/players/yurtube/js/scripts/build.mjs
Сейчас проблема в том что static/players/yurtube/js/src/player.core.js стал слишком большим и его надо разделить на части. Давай попробуем поэтапно перенести из него часть функционала. Сначала попробуем то что касается subtitles.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 12, 2026 16:55
Co-authored-by: sphynkx <7884935+sphynkx@users.noreply.github.com>
Co-authored-by: sphynkx <7884935+sphynkx@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor player.core.js to separate subtitles functionality Refactor player.core.js to separate subtitles functionality Jan 12, 2026
Co-authored-by: sphynkx <7884935+sphynkx@users.noreply.github.com>
@sphynkx sphynkx changed the base branch from main to yttrans January 12, 2026 17:48
Co-authored-by: sphynkx <7884935+sphynkx@users.noreply.github.com>
Copilot AI changed the title Refactor player.core.js to separate subtitles functionality Refactor player.core.js: extract subtitles and menu functionality Jan 12, 2026
…e Back button

Co-authored-by: sphynkx <7884935+sphynkx@users.noreply.github.com>
Co-authored-by: sphynkx <7884935+sphynkx@users.noreply.github.com>
Co-authored-by: sphynkx <7884935+sphynkx@users.noreply.github.com>
Co-authored-by: sphynkx <7884935+sphynkx@users.noreply.github.com>
…iding module import

Co-authored-by: sphynkx <7884935+sphynkx@users.noreply.github.com>
…te modules

Co-authored-by: sphynkx <7884935+sphynkx@users.noreply.github.com>
Copilot AI changed the title Refactor player.core.js: extract subtitles and menu functionality Refactor player.core.js and embed.core.js: extract subtitles and menu functionality Jan 12, 2026
Co-authored-by: sphynkx <7884935+sphynkx@users.noreply.github.com>
Repository owner deleted a comment from Copilot AI Jan 17, 2026
Repository owner deleted a comment from Copilot AI Jan 17, 2026
Repository owner deleted a comment from Copilot AI Jan 17, 2026
Repository owner deleted a comment from Copilot AI Jan 17, 2026
Repository owner deleted a comment from Copilot AI Jan 17, 2026
Repository owner deleted a comment from Copilot AI Jan 17, 2026
Repository owner deleted a comment from Copilot AI Jan 17, 2026
Repository owner deleted a comment from Copilot AI Jan 17, 2026
Repository owner deleted a comment from Copilot AI Jan 17, 2026
Repository owner deleted a comment from Copilot AI Jan 17, 2026
Repository owner deleted a comment from Copilot AI Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants