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 functions.js ignore video previews #2384

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
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
37 changes: 21 additions & 16 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,22 +325,27 @@ ImprovedTube.videoPageUpdate = function () {
ImprovedTube.playerOnPlay = function () {
HTMLMediaElement.prototype.play = (function (original) {
return function () {
this.removeEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);
this.addEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);

this.removeEventListener('timeupdate', ImprovedTube.playerOnTimeUpdate);
this.addEventListener('timeupdate', ImprovedTube.playerOnTimeUpdate);

this.removeEventListener('pause', ImprovedTube.playerOnPause, true);
this.addEventListener('pause', ImprovedTube.playerOnPause, true);

this.removeEventListener('ended', ImprovedTube.playerOnEnded, true);
this.addEventListener('ended', ImprovedTube.playerOnEnded, true);

ImprovedTube.autoplayDisable(this);
ImprovedTube.playerLoudnessNormalization();
ImprovedTube.playerCinemaModeEnable();

if (!this.closest('#inline-preview-player')) {
this.removeEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);
this.addEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);

this.removeEventListener('timeupdate', ImprovedTube.playerOnTimeUpdate);
this.addEventListener('timeupdate', ImprovedTube.playerOnTimeUpdate);

this.removeEventListener('pause', ImprovedTube.playerOnPause, true);
this.addEventListener('pause', ImprovedTube.playerOnPause, true);
this.onpause = (event) => {
console.log('this.onpause');
};

this.removeEventListener('ended', ImprovedTube.playerOnEnded, true);
this.addEventListener('ended', ImprovedTube.playerOnEnded, true);
if (this.user_interacted || !(this.storage.player_autoplay_disable == true || this.storage.playlist_autoplay === false || this.storage.channel_trailer_autoplay === false))
{ document.dispatchEvent(new CustomEvent('it-play')); } else {ImprovedTube.autoplayDisable(this); }
ImprovedTube.autoplayDisable(this);
ImprovedTube.playerLoudnessNormalization();
ImprovedTube.playerCinemaModeEnable();
}
return original.apply(this, arguments);
}
})(HTMLMediaElement.prototype.play);
Expand Down
23 changes: 6 additions & 17 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@
AUTOPLAY DISABLE
------------------------------------------------------------------------------*/
ImprovedTube.autoplayDisable = function (videoElement) {
if (this.storage.player_autoplay_disable
|| this.storage.playlist_autoplay === false
|| this.storage.channel_trailer_autoplay === false) {
const player = this.elements.player || videoElement.closest('.html5-video-player') || videoElement.closest('#movie_player'); // #movie_player: outdated since 2024?

if (this.video_url !== location.href) { this.user_interacted = false; }

// 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
if (player && !this.user_interacted
// no ads playing
&& !player.classList.contains('ad-showing')
// video page
&& ((location.href.includes('/watch?') // #1703
// if there is a player && no ads playing && ((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)
if (player
&& !player.classList.contains('ad-showing') // no ads playing
&& ((location.href.includes('/watch?') // video page // #1703
// player_autoplay_disable & not playlist
&& (this.storage.player_autoplay_disable && !location.href.includes('list='))
&& ((this.storage.player_autoplay_disable && !location.href.includes('list='))
// !playlist_autoplay & playlist
|| (this.storage.playlist_autoplay === false && location.href.includes('list=')))
// channel homepage & !channel_trailer_autoplay
Expand All @@ -31,9 +23,6 @@ ImprovedTube.autoplayDisable = function (videoElement) {
} else {
document.dispatchEvent(new CustomEvent('it-play'));
}
} else {
document.dispatchEvent(new CustomEvent('it-play'));
}
};
/*------------------------------------------------------------------------------
FORCED PLAY VIDEO FROM THE BEGINNING
Expand Down
Loading