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

Update shortcuts.js handlers rewrite, multiple fixes #2421

Merged
merged 30 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a7ed0a5
Update shortcuts.js handlers rewrite, multiple fixes
raszpl Jun 29, 2024
68d9141
Update shortcuts.js more meaningful names
raszpl Jun 29, 2024
892c4d7
Update shortcuts.js sane shortcutQuality
raszpl Jun 29, 2024
a3a969b
Update core.js shortcut variables, proper caller on setting change
raszpl Jun 29, 2024
69c9ffd
background.js renamed quality shortcuts to more intuitive names, simp…
raszpl Jun 29, 2024
4f0caef
Update shortcuts.js safe shortcutPictureInPicture
raszpl Jun 29, 2024
0234e75
shortcuts.js 'cancelled' list so we also cancel keyup events, safer s…
raszpl Jun 29, 2024
0eaa958
Update core.js shortcut cancelled
raszpl Jun 29, 2024
4b0739f
Update shortcuts.js fixedshortcutToggleLoop
raszpl Jun 29, 2024
69abf48
Update shortcuts.js simpler shortcutSubscribe
raszpl Jun 29, 2024
ac40b7c
Update shortcuts.js allow wheel shortcuts
raszpl Jun 29, 2024
d6653a8
Update shortcuts.js comments
raszpl Jun 29, 2024
1712fe6
shortcuts.js rename 'shortcut_volume_step', 'shortcut_playback_speed_…
raszpl Jun 29, 2024
a72c593
Update shortcuts.js missing commas, redundant newlines
raszpl Jun 29, 2024
a091217
player.js new playbackSpeed(), formatting
raszpl Jun 29, 2024
16c1364
shortcuts.js rewrote shortcutIncreasePlaybackSpeed shortcutDecreasePl…
raszpl Jun 29, 2024
08f7bcd
Update shortcuts.js developer warning
raszpl Jun 29, 2024
acc789c
shortcuts.js rewrote non working shortcutRotateVideo, shortcutToggleA…
raszpl Jun 29, 2024
16a8457
Update shortcuts.js simplified shortcutResetPlaybackSpeed
raszpl Jun 29, 2024
f43f6e6
shortcuts.js rewrote shortcutIncreaseVolume shortcutDecreaseVolume
raszpl Jun 29, 2024
6544daf
Update shortcuts.js simplified shortcutGoToSearchBox shortcutActivate…
raszpl Jun 29, 2024
9fc8e9f
shortcuts.js safer shortcutStatsForNerds, reformatted shortcutToggleC…
raszpl Jun 29, 2024
8204eec
shortcuts.js simplified shortcutLike shortcutDislike
raszpl Jun 29, 2024
45d7871
shortcuts.js simplified shortcutSeekBackward shortcutSeekForward
raszpl Jun 29, 2024
ad0dcb4
shortcuts.js added optional shortcut 'toggle', maybe for future press…
raszpl Jun 29, 2024
2697442
Update shortcuts.js formatting
raszpl Jun 29, 2024
a2af19d
Update shortcuts.js stray }
raszpl Jun 29, 2024
7dcb386
Update background.js more updates
raszpl Jun 29, 2024
60bf516
Update background.js safety
raszpl Jun 29, 2024
bbeadcd
Update shortcuts.js safety
raszpl Jun 29, 2024
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
29 changes: 27 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,35 @@ chrome.runtime.onInstalled.addListener(function (installed) {
if(installed.reason == 'update') {
// var thisVersion = chrome.runtime.getManifest().version;
// console.log("Updated from " + installed.previousVersion + " to " + thisVersion + "!");
// Shortcut renames:
chrome.storage.local.get(['shortcut_auto', 'shortcut_144p', 'shortcut_240p', 'shortcut_360p', 'shortcut_480p', 'shortcut_720p', 'shortcut_1080p', 'shortcut_1440p', 'shortcut_2160p', 'shortcut_2880p', 'shortcut_4320p'], function (result) {
// validate and move to new name
for (let [name, keys] of Object.entries(result)) {
if (!keys) continue;
let newKeys = {},
newName = name.replace('shortcut_', 'shortcut_quality_');
for (const button of ['alt','ctrl','shift','wheel','toggle']) {
if (keys[button]) newKeys[button] = keys[button];
}
if (keys['keys'] && Object.keys(keys['keys'])?.length) {
newKeys['keys'] = keys['keys'];
}
// only shortcuts with Key of Wheel are valid and saved
if (newKeys['keys'] || newKeys['wheel']) chrome.storage.local.set({[newName]: newKeys});
}
chrome.storage.local.remove(Object.keys(result));
});
chrome.storage.local.get(['shortcut_volume_step', 'shortcut_playback_speed_step'], function (result) {
for (let [name, value] of Object.entries(result)) {
let newName = name.replace('shortcut_', 'shortcuts_');
chrome.storage.local.set({[newName]: value});
}
chrome.storage.local.remove(Object.keys(result));
});
chrome.storage.local.get('player_autoplay', function (result) {
if (result.player_autoplay === false) {
chrome.storage.local.set({player_autoplay_disable: true});
chrome.storage.local.remove(['player_autoplay'], (i) => {});
chrome.storage.local.remove(['player_autoplay']);
}
});
chrome.storage.local.get('channel_default_tab', function (result) {
Expand All @@ -54,7 +79,7 @@ chrome.runtime.onInstalled.addListener(function (installed) {
chrome.storage.local.get('hideSubscribe', function (result) {
if (result.hideSubscribe === true) {
chrome.storage.local.set({subscribe: 'hidden'});
chrome.storage.local.remove(['hideSubscribe'], (i) => {});
chrome.storage.local.remove(['hideSubscribe']);
}
});
chrome.storage.local.get('limit_page_width', function (result) {
Expand Down
16 changes: 16 additions & 0 deletions js&css/web-accessible/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ var ImprovedTube = {
played_before_blur: false,
played_time: 0,
user_interacted: false,
input: {
listening: {},
listeners: {},
pressed: {
keys: [],
alt: false,
ctrl: false,
shift: false,
player: false,
wheel: 0
},
cancelled: []
},
mini_player__mode: false,
mini_player__move: false,
mini_player__cursor: '',
Expand Down Expand Up @@ -387,6 +400,9 @@ document.addEventListener('it-message-from-extension', function () {
break
}

// dont trigger shortcuts on config change, reinitialize handler instead
if (message.key.startsWith('shortcut_')) camelized_key = 'shortcuts';

if (ImprovedTube[camelized_key]) {
try{ImprovedTube[camelized_key]()}catch{};
}
Expand Down
47 changes: 37 additions & 10 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@ ImprovedTube.autoplayDisable = function (videoElement) {
// if (no user clicks) and (no ads playing) and
// ( there is a player and ( (it is not in a playlist and auto play is off ) or ( playlist auto play is off and in a playlist ) ) ) or (if we are in a channel and the channel trailer autoplay is off) )

// user didnt click
// user didnt click
if (player && !this.user_interacted
// no ads playing
// no ads playing
&& !player.classList.contains('ad-showing')
// video page
// video page
&& ((location.href.includes('/watch?') // #1703
// player_autoplay_disable & not playlist
// player_autoplay_disable & not playlist
&& (this.storage.player_autoplay_disable && !location.href.includes('list='))
// !playlist_autoplay & playlist
// !playlist_autoplay & playlist
|| (this.storage.playlist_autoplay === false && location.href.includes('list=')))
// channel homepage & !channel_trailer_autoplay
// channel homepage & !channel_trailer_autoplay
|| (this.storage.channel_trailer_autoplay === false && this.regex.channel.test(location.href)))) {
setTimeout(function() { try { player.pauseVideo(); }
catch (error) { console.log("autoplayDisable: Pausing"); videoElement.pause(); }
});

setTimeout(function() {
try { player.pauseVideo(); } catch (error) { console.log("autoplayDisable: Pausing"); videoElement.pause(); }
});
} else {
document.dispatchEvent(new CustomEvent('it-play'));
}
Expand Down Expand Up @@ -80,7 +81,33 @@ ImprovedTube.playerAutoPip = function () {
}
})();
}
}
};
/*------------------------------------------------------------------------------
PLAYBACK SPEED
------------------------------------------------------------------------------*/
ImprovedTube.playbackSpeed = function (newSpeed) {
const video = this.elements.video,
player = this.elements.player,
speed = video?.playbackRate ? Number(video.playbackRate.toFixed(2)) : (player?.getPlaybackRate ? Number(player.getPlaybackRate().toFixed(2)) : null);

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

// called with no option or demanded speed already set, only provide readback
if (!newSpeed || speed == newSpeed) return speed;

if (video?.playbackRate) {
video.playbackRate = newSpeed;
newSpeed = video.playbackRate;
} else if (player?.setPlaybackRate && player.getPlaybackRate) {
player.setPlaybackRate(newSpeed);
newSpeed = player.getPlaybackRate();
} else newSpeed = false;

return newSpeed;
};
/*------------------------------------------------------------------------------
FORCED PLAYBACK SPEED
------------------------------------------------------------------------------*/
Expand Down
Loading
Loading