Skip to content

Commit

Permalink
Merge pull request #2384 from raszpl/patch-8
Browse files Browse the repository at this point in the history
Update functions.js ignore video previews
  • Loading branch information
ImprovedTube authored Jun 18, 2024
2 parents 2e850c8 + 69e301e commit 3cb2844
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
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

0 comments on commit 3cb2844

Please sign in to comment.