Skip to content

Commit

Permalink
speed limits #2421
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprovedTube committed Jul 8, 2024
1 parent 324299f commit 47a23fe
Showing 1 changed file with 29 additions and 40 deletions.
69 changes: 29 additions & 40 deletions js&css/web-accessible/www.youtube.com/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,49 +332,38 @@ ImprovedTube.shortcutScreenshot = ImprovedTube.screenshot;
/*------------------------------------------------------------------------------
4.7.16 INCREASE PLAYBACK SPEED
------------------------------------------------------------------------------*/
ImprovedTube.shortcutIncreasePlaybackSpeed = function () { value = Number(this.storage.shortcuts_playback_speed_step) || .05;
// original:
const video = this.elements.video;
if (video) {if ( video.playbackRate){
if ( video.playbackRate < 1 && video.playbackRate > 1-ImprovedTube.storage.shortcuts_playback_speed_step ) {
video.playbackRate = 1 } // aligning at 1.0 instead of passing by 1.0
else { video.playbackRate = Math.min(Math.max(Number((video.playbackRate + Number(ImprovedTube.storage.shortcuts_playback_speed_step || .05)).toFixed(2)), .1),16);
} // Firefox doesnt limit speed to 16x. We can allow more in Firefox if people ask
ImprovedTube.showStatus(video.playbackRate);
} else {
// alternative:
const player = this.elements.player;
if (player) {
if ( player.getPlaybackRate() < 1 && player.getPlaybackRate() > 1-ImprovedTube.storage.shortcuts_playback_speed_step ) {
player.setPlaybackRate(1) } // aligning at 1.0 instead of passing by 1.0
else { player.setPlaybackRate(Math.min(Math.max(Number((player.getPlaybackRate() + Number(ImprovedTube.storage.shortcuts_playback_speed_step || .05)).toFixed(2)), .1),16))
}
ImprovedTube.showStatus(player.getPlaybackRate());
}}}};
ImprovedTube.shortcutIncreasePlaybackSpeed = function (decrease) {
const value = Number(this.storage.shortcuts_playback_speed_step) || .05,
speed = this.playbackSpeed(),
direction = decrease ? 'Decrease' : 'Increase';
let newSpeed;

if (!speed) {
console.error('shortcut' + direction + 'PlaybackSpeed: Cant establish playbackRate/getPlaybackRate');
return;
}
if (decrease) {
// Slow down near 0 // Chrome's minimum is 0.0625. Otherwise this could seamlessly turn into single frame steps.
newSpeed = (speed - value < 0.1) ? math.max(Number(speed*0.7).toFixed(2),0.625) : (speed - value);

Check warning on line 347 in js&css/web-accessible/www.youtube.com/shortcuts.js

View workflow job for this annotation

GitHub Actions / lint-and-test

A space is required after ','

Check warning on line 347 in js&css/web-accessible/www.youtube.com/shortcuts.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
} else {
// Aligning at 1.0 instead of passing by 1:

Check warning on line 349 in js&css/web-accessible/www.youtube.com/shortcuts.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
if (speed < 1 && speed > 1-ImprovedTube.storage.shortcuts_playback_speed_step ) {newSpeed = 1;

Check warning on line 350 in js&css/web-accessible/www.youtube.com/shortcuts.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
// Firefox doesnt limit speed to 16x, we can allow more in Firefox.
} else { newSpeed = (speed + value > 16) ? 16 : (speed + value); }

Check warning on line 352 in js&css/web-accessible/www.youtube.com/shortcuts.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
}
newSpeed = this.playbackSpeed(newSpeed);
if (!newSpeed) {
console.error('shortcut' + direction + 'PlaybackSpeed: Cant read back playbackRate/getPlaybackRate');
return;
}
ImprovedTube.showStatus(newSpeed);
};
/*------------------------------------------------------------------------------
4.7.17 DECREASE PLAYBACK SPEED
------------------------------------------------------------------------------*/
ImprovedTube.shortcutDecreasePlaybackSpeed = function () { value = Number(ImprovedTube.storage.shortcuts_playback_speed_step) || .05;
// original:
const video = this.elements.video;
if (video) {
if (video.playbackRate){
if ( video.playbackRate < 0.1+ImprovedTube.storage.shortcuts_playback_speed_step ) {
video.playbackRate = video.playbackRate*0.7 } // slow down near minimum
else { video.playbackRate = Math.max(Number((video.playbackRate - Number(ImprovedTube.storage.shortcuts_playback_speed_step || .05)).toFixed(2)), .1);
}
ImprovedTube.showStatus(video.playbackRate);
}
else {
// alternative:
const player = this.elements.player;
if (player) {
if ( player.getPlaybackRate() < 0.1+ImprovedTube.storage.shortcuts_playback_speed_step ) {
player.setPlaybackRate(player.getPlaybackRate()*0.7) } // slow down near minimum
else { player.setPlaybackRate(Math.max(Number((player.getPlaybackRate() - Number(ImprovedTube.storage.shortcuts_playback_speed_step || .05)).toFixed(2)), .1))
}
ImprovedTube.showStatus(player.getPlaybackRate());
}}}};
ImprovedTube.shortcutDecreasePlaybackSpeed = function () {
ImprovedTube.shortcutIncreasePlaybackSpeed(true);
};

Check warning on line 366 in js&css/web-accessible/www.youtube.com/shortcuts.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
/*------------------------------------------------------------------------------
4.7.18 RESET PLAYBACK SPEED
------------------------------------------------------------------------------*/
Expand Down

0 comments on commit 47a23fe

Please sign in to comment.