Skip to content

Commit

Permalink
Merge pull request #2157 from raszpl/patch-5
Browse files Browse the repository at this point in the history
Update player.js slightly more readable autoplayDisable
  • Loading branch information
ImprovedTube authored May 6, 2024
2 parents e56ddb2 + e3fee6d commit 0172a5c
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
/*------------------------------------------------------------------------------
AUTOPLAY DISABLE
------------------------------------------------------------------------------*/
ImprovedTube.autoplayDisable = function (videoElement) {
ImprovedTube.autoplayDisable = function (videoElement) {
if (ImprovedTube.storage.player_autoplay_disable
|| ImprovedTube.storage.playlist_autoplay === false || ImprovedTube.storage.channel_trailer_autoplay === false){
const video = ImprovedTube.elements.player || videoElement.closest('#movie_player');
if (ImprovedTube.video_url !== location.href) {
this.user_interacted = false;
if (ImprovedTube.video_url !== location.href) { this.user_interacted = false; }

// if (no user clicks) and (no ads playing) and
// ( there is a video 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 (video && !this.user_interacted
// no ads playing
&& !video.classList.contains('ad-showing')
// video
&& ((location.href.includes('/watch?') // #1703
// player_autoplay_disable & not playlist
&& (ImprovedTube.storage.player_autoplay_disable && !location.href.includes('list='))
// !playlist_autoplay & playlist
|| (ImprovedTube.storage.playlist_autoplay === false && location.href.includes('list=')))
// channel homepage & !channel_trailer_autoplay
|| (ImprovedTube.storage.channel_trailer_autoplay === false && ImprovedTube.regex.channel.test(location.href)))) {

if (!ImprovedTube.autoplayDeniedOnce) {
setTimeout(function () { video.pauseVideo(); });
ImprovedTube.autoplayDeniedOnce = true;
} else { video.pauseVideo();
console.log("autoplay:off - should we pause here again?");
}
}
// if (allow autoplay is false) and (no ads playing) and
// ( there is a video and ( (it is not in a playlist and auto play is off ) or ( playlist auto play is off and it is not in a playlist ) ) ) or (if we are in a channel and the channel trailer autoplay is off) )
if (video && !this.user_interacted && video.classList.contains('ad-showing') === false &&
(
// quick fix #1703 thanks to @AirRaid#9957
(/* document.documentElement.dataset.pageType === "video" */ location.href.indexOf('/watch?') !== -1 && ((location.href.indexOf('list=') === -1 && ImprovedTube.storage.player_autoplay_disable) || (ImprovedTube.storage.playlist_autoplay === false && location.href.indexOf('list=') !== -1))) ||
(/* document.documentElement.dataset.pageType === "channel" */ ImprovedTube.regex.channel.test(location.href) && ImprovedTube.storage.channel_trailer_autoplay === false)
)
)
{if (!ImprovedTube.autoplayDeniedOnce) {
setTimeout(function () { video.pauseVideo(); });
ImprovedTube.autoplayDeniedOnce = true;
} else { console.log("autoplay:off - should we pause here again?"); } }
}
};
/*------------------------------------------------------------------------------
FORCED PLAY VIDEO FROM THE BEGINNING
Expand Down

0 comments on commit 0172a5c

Please sign in to comment.