Skip to content

Feat: Implement Smart Speed feature using YouTube heatmap (#1463)#3599

Merged
ImprovedTube merged 2 commits intocode-charity:masterfrom
AryaXDG:feature/smart-speed-heatmap
Feb 6, 2026
Merged

Feat: Implement Smart Speed feature using YouTube heatmap (#1463)#3599
ImprovedTube merged 2 commits intocode-charity:masterfrom
AryaXDG:feature/smart-speed-heatmap

Conversation

@AryaXDG
Copy link
Contributor

@AryaXDG AryaXDG commented Feb 5, 2026

This Pull Request implements the "Smart Speed" feature requested in Issue #1463. This functionality leverages YouTube's native "Most Replayed" heatmap data (engagement histogram) to dynamically adjust playback speed in real-time, optimizing content consumption efficiency.

The feature analyzes normalized engagement metrics to automatically:

  1. Skip Intros: Seeks past low-engagement segments at the start of the video (0-15% duration) if the interest score is below the defined threshold.
  2. Dynamic Playback Speed: Scales playback speed inversely to user engagement during low-retention sections.
  3. Restore Normal Speed: Automatically reverts to 1.0x speed during high-engagement segments.

Key Changes:

  • Logic Engine (player.js):
  • Implemented ImprovedTube.heatmap module to encapsulate state and logic.
  • Resilient Data Extraction: Developed a multi-tiered data retrieval strategy to handle YouTube's A/B testing and data lazy-loading:
  1. Tier 1: Direct DOM access via getPlayerResponse().
  2. Tier 2: Inspection of global window objects (ytInitialData, ytInitialPlayerResponse).
  3. Tier 3: Background fetch of the document source to parse raw JSON when runtime data is unavailable or obfuscated (common in music videos or specific user sessions).
  • Recursive Parsing: Implemented a recursive search algorithm to locate MARKER_TYPE_HEATMAP objects within arbitrary JSON structures, making the feature robust against minor DOM layout changes.

  • Dynamic Speed Mapping: Implemented a heuristic gradient for speed adjustment based on intensity scores:
    Score ≤ 0.05: 2.00x
    Score ≤ 0.12: 1.75x
    Score ≤ 0.18: 1.50x
    Score ≤ 0.25: 1.25x
    Score > 0.25: 1.00x

  • User Interface (menu/skeleton-parts/player.js):
    Added a toggle switch in the "Player" section labeled "Smart Speed (Skip Boring Parts)".

  • Shortcuts (shortcuts.js):
    Added logic for a keyboard shortcut to toggle the feature state during playback.

  • Localization (messages.json):
    Added the English locale string for the new menu item.

Technical Implementation Details:

  • Performance: The logic loop utilizes a 500ms throttle to ensure negligible CPU impact during playback monitoring.
  • Safety: Extensive try/catch blocks and type checking prevent player instability if upstream API data formats change.
  • SPA Support: Includes event listeners for yt-navigate-finish to ensure correct re-initialization during YouTube's Single Page Application navigation events.

How to Test:

  1. Enable "Smart Speed (Skip Boring Parts)" in the ImprovedTube Player menu.
  2. Navigate to a video with established heatmap data (e.g., a popular tutorial or educational video).
  3. Monitor the playback speed via the YouTube player settings. Verify that speed increases during low-engagement sections and returns to 1.0x during peaks.
  4. Verify that intros with low engagement (first 15%) are automatically skipped.
  5. Test on a video known to obscure data (e.g., music videos) to verify the background fetch fallback mechanism functions correctly.

Related Issue:
Closes #1463

@ImprovedTube ImprovedTube merged commit b104b35 into code-charity:master Feb 6, 2026
1 check passed
@ImprovedTube
Copy link
Member

Awesome!!!

( added the shortcut GUI element. )

isEnabled

  • Sorry our global functions & documentation didn't spare you from these lines of work. ( Functions and settings can be separate like if (this.storage.player_always_repeat === true) { ImprovedTube.playerRepeat(); } )

@AryaXDG
Copy link
Contributor Author

AryaXDG commented Feb 6, 2026

No worries at all! I expected a bit of legacy structure given the project's history, but it was honestly a fun challenge to figure out how everything fits together.

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.

Youtube's Timeline Heatmap (Histogram) enables/improves a lot...

2 participants