Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add playback speed button for quick acess #2674

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions speedControl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*------------------------------------------------------------------------------
QUICK ACCESS PLAYBACK SPEED
------------------------------------------------------------------------------*/
ImprovedTube.createPlaybackSpeedButtons = function () {
const playerControls = document.querySelector('.ytp-right-controls'); // Adjust this selector based on your player structure
if (!playerControls) return;

// Create playback speed buttons
const speeds = [0.5, 1.0, 1.5, 2.0];
speeds.forEach(speed => {
const button = document.createElement('button');
button.innerText = `${speed}x`;
button.style.margin = '0 5px'; // Add some margin for spacing
button.style.cursor = 'pointer';
button.title = `Set playback speed to ${speed}x`;

// Add event listener to change playback speed
button.addEventListener('click', () => {
const newSpeed = ImprovedTube.playbackSpeed(speed);
document.getElementById('currentSpeed').innerText = newSpeed || 'Error';
});

playerControls.appendChild(button); // Add button to player controls
});

// Display current speed
const currentSpeedDisplay = document.createElement('span');
currentSpeedDisplay.id = 'currentSpeed';
currentSpeedDisplay.innerText = '1.0'; // Default speed
currentSpeedDisplay.style.marginLeft = '10px';
playerControls.appendChild(currentSpeedDisplay);
};

/* Call this function when the player is ready */
ImprovedTube.init = function () {
// Other initialization code...
this.createPlaybackSpeedButtons(); // Create playback speed buttons
};

// Ensure to call ImprovedTube.init() somewhere in your code after the player is ready