Skip to content

Commit

Permalink
#2421 decrese; keeping familar speed stepping; max.; decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprovedTube committed Jul 8, 2024
1 parent e2c24bf commit c00004c
Showing 1 changed file with 43 additions and 33 deletions.
76 changes: 43 additions & 33 deletions js&css/web-accessible/www.youtube.com/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,18 @@ ImprovedTube.shortcutSeekPreviousChapter = function () {
/*------------------------------------------------------------------------------
4.7.13 INCREASE VOLUME
------------------------------------------------------------------------------*/
ImprovedTube.shortcutIncreaseVolume = function (decrese) {
ImprovedTube.shortcutIncreaseVolume = function (decrease) {
const player = this.elements.player,
value = Number(this.storage.shortcuts_volume_step) || 5,
direction = decrese ? 'Decrease' : 'Increase';
direction = decrease ? 'Decrease' : 'Increase';

if (!player || !player.setVolume || !player.getVolume) {
console.error('shortcut' + direction + 'Volume: No valid Player element');
return;
}

// universal, goes both ways if you know what I mean
if (decrese) {
if (decrease) {
player.setVolume(player.getVolume() - value);
} else {
player.setVolume(player.getVolume() + value);
Expand Down Expand Up @@ -353,39 +353,49 @@ ImprovedTube.shortcutScreenshot = ImprovedTube.screenshot;
/*------------------------------------------------------------------------------
4.7.16 INCREASE PLAYBACK SPEED
------------------------------------------------------------------------------*/
ImprovedTube.shortcutIncreasePlaybackSpeed = function (decrese) {
const value = Number(this.storage.shortcuts_playback_speed_step) || .05,
speed = this.playbackSpeed(),
direction = decrese ? 'Decrease' : 'Increase';
let newSpeed;

if (!speed) {
console.error('shortcut' + direction + 'PlaybackSpeed: Cant establish playbackRate/getPlaybackRate');
return;
}

// universal, goes both ways if you know what I mean
if (decrese) {
// 0.1x speed is the minimum
newSpeed = (speed - value < 0.1) ? 0.1 : (speed - value);
} else {
// 10x speed is the limit
newSpeed = (speed + value > 10) ? 10 : (speed + value);
}

newSpeed = this.playbackSpeed(newSpeed);
if (!newSpeed) {
console.error('shortcut' + direction + 'PlaybackSpeed: Cant read back playbackRate/getPlaybackRate');
return;
}
ImprovedTube.showStatus(newSpeed);
};
ImprovedTube.shortcutIncreasePlaybackSpeed = function () { const value = Number(this.storage.shortcuts_playback_speed_step) || .05,
// original:
var video = this.elements.video;
if (video) {if ( video.playbackRate){
if ( video.playbackRate < 1 && video.playbackRate > 1-ImprovedTube.storage.shortcut_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.shortcut_playback_speed_step || .05)).toFixed(2)), .1),24);
}
ImprovedTube.showStatus(video.playbackRate);
} else {
// alternative:
var player = this.elements.player;
if (player) {
if ( player.getPlaybackRate() < 1 && player.getPlaybackRate() > 1-ImprovedTube.storage.shortcut_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.shortcut_playback_speed_step || .05)).toFixed(2)), .1),24))
}
ImprovedTube.showStatus(player.getPlaybackRate());
}}}};
/*------------------------------------------------------------------------------
4.7.17 DECREASE PLAYBACK SPEED
------------------------------------------------------------------------------*/
ImprovedTube.shortcutDecreasePlaybackSpeed = function () {
ImprovedTube.shortcutIncreasePlaybackSpeed(true);
};
ImprovedTube.shortcutDecreasePlaybackSpeed = function () { const value = Number(ImprovedTube.storage.shortcut_playback_speed_step) || .05;
// original:
var video = this.elements.video;
if (video) {
if (video.playbackRate){
if ( video.playbackRate < 0.1+ImprovedTube.storage.shortcut_playback_speed_step ) {
video.playbackRate = video.playbackRate*0.7 } // slow down near minimum
else { video.playbackRate = Math.max(Number((video.playbackRate - Number(ImprovedTube.storage.shortcut_playback_speed_step || .05)).toFixed(2)), .1);
}
ImprovedTube.showStatus(video.playbackRate);
}
else {
// alternative:
var player = this.elements.player;
if (player) {
if ( player.getPlaybackRate() < 0.1+ImprovedTube.storage.shortcut_playback_speed_step ) {
player.setPlaybackRate(player.getPlaybackRate()*0.7) } // slow down near minimum
else { player.setPlaybackRate(Math.max(Number((player.getPlaybackRate() - Number(ImprovedTube.storage.shortcut_playback_speed_step || .05)).toFixed(2)), .1))
}
ImprovedTube.showStatus(player.getPlaybackRate());
}}}};
/*------------------------------------------------------------------------------
4.7.18 RESET PLAYBACK SPEED
------------------------------------------------------------------------------*/
Expand Down

0 comments on commit c00004c

Please sign in to comment.