diff --git a/js&css/web-accessible/functions.js b/js&css/web-accessible/functions.js index 2326e4457..78bd409c8 100644 --- a/js&css/web-accessible/functions.js +++ b/js&css/web-accessible/functions.js @@ -345,6 +345,8 @@ ImprovedTube.videoPageUpdate = function () { ImprovedTube.playerCinemaModeButton(); ImprovedTube.playerHamburgerButton(); ImprovedTube.playerControls(); + ImprovedTube.autoPauseOtherVideos(); + } }; diff --git a/js&css/web-accessible/www.youtube.com/player.js b/js&css/web-accessible/www.youtube.com/player.js index 88fab0a16..4e192452d 100644 --- a/js&css/web-accessible/www.youtube.com/player.js +++ b/js&css/web-accessible/www.youtube.com/player.js @@ -44,7 +44,7 @@ ImprovedTube.forcedPlayVideoFromTheBeginning = function () { video = this.elements.video, paused = video?.paused; - if (player && video && this.storage.forced_play_video_from_the_beginning && location.pathname == '/watch') { + if (player && video && this.storage.forced_play_video_from_the_beginning && location.pathname === '/watch') { player.seekTo(0); // restore previous paused state if (paused) { player.pauseVideo(); } @@ -153,7 +153,7 @@ ImprovedTube.playerPlaybackSpeed = function () { if (this.storage.player_forced_ return;} if (DATA.keywords && !keywords) { keywords = DATA.keywords.join(', ') || ''; } if (keywords === 'video, sharing, camera phone, video phone, free, upload') { keywords = ''; } - var musicIdentifiers = /(official|music|lyrics?)[ -]video|(cover|studio|radio|album|alternate)[- ]version|soundtrack|unplugged|\bmedley\b|\blo-fi\b|\blofi\b|a(lla)? cappella|feat\.|(piano|guitar|jazz|ukulele|violin|reggae)[- ](version|cover)|karaok|backing[- ]track|instrumental|(sing|play)[- ]?along|卡拉OK|卡拉OK|الكاريوكي|караоке|カラオケ|노래방|bootleg|mashup|Radio edit|Guest (vocals|musician)|(title|opening|closing|bonus|hidden)[ -]track|live acoustic|interlude|featuring|recorded (at|live)/i; + var musicIdentifiers = /(official|music|lyrics?)[ -]video|(cover|studio|radio|album|alternate)[- ]version|soundtrack|unplugged|\bmedley\b|\blo-fi\b|\blofi\b|a(lla)? cappella|feat\.|(piano|guitar|jazz|ukulele|violin|reggae)[- ](version|cover)|karaok|backing[- ]track|instrumental|(sing|play)[- ]?along|卡拉OK|الكاريوكي|караоке|カラオケ|노래방|bootleg|mashup|Radio edit|Guest (vocals|musician)|(title|opening|closing|bonus|hidden)[ -]track|live acoustic|interlude|featuring|recorded (at|live)/i; var musicIdentifiersTitleOnly = /lyrics|theme song|\bremix|\bAMV ?[^a-z0-9]|[^a-z0-9] ?AMV\b|\bfull song\b|\bsong:|\bsong[\!$]|^song\b|( - .*\bSong\b|\bSong\b.* - )|cover ?[^a-z0-9]|[^a-z0-9] ?cover|\bconcert\b/i; var musicIdentifiersTitle = new RegExp(musicIdentifiersTitleOnly.source + '|' + musicIdentifiers.source, "i"); var musicRegexMatch = musicIdentifiersTitle.test(DATA.title); @@ -236,7 +236,7 @@ if (title && title !== 'YouTube') { } amountOfSongs = (htmlContent.slice(-80000).match(/},"subtitle":{"simpleText":"(\d*)\s/) || [])[1] || false; if (keywords) { ImprovedTube.speedException(); } - } catch (error) { console.error('Error: fetching from https://Youtube.com/watch?v=${DATA.videoID}', error); keywords = ''; } + } catch (error) { console.error(`Error: fetching from https://Youtube.com/watch?v=${DATA.videoID}`, error); keywords = ''; } })(); } } @@ -1746,6 +1746,23 @@ ImprovedTube.pauseWhileTypingOnYoutube = function () { } }; +// AUTO PAUSE OTHER VIDEOS + +ImprovedTube.autoPauseOtherVideos = function(){ + const currentplayer = ImprovedTube.elements.player; + if(!currentplayer) return ; + currentplayer.addEventListener('play', ()=> { + const allVideos=document.querySelectorAll('video'); + + allVideos.forEach(video=>{ + + if(video!==currentplayer && !video.paused){ + video.pause(); + } + }); + }); +}; + /*------------------------------------------------------------------------------ HIDE PROGRESS BAR PREVIEW ------------------------------------------------------------------------------*/ @@ -2195,8 +2212,8 @@ SHORTS AUTO SCROLL ------------------------------------------------------------------------------*/ ImprovedTube.shortsAutoScroll = function () { if (this.storage.shorts_auto_scroll) { - if (!ImprovedTube.shortsAutoScrollInterval) { - ImprovedTube.shortsAutoScrollInterval = setInterval(() => { + if (!ImprovedTube.shortsAutoScroll) { + ImprovedTube.shortsAutoScroll = setInterval(() => { if (!location.pathname.startsWith('/shorts/')) return; const activeRenderer = document.querySelector('ytd-reel-video-renderer[is-active]'); @@ -2224,9 +2241,9 @@ ImprovedTube.shortsAutoScroll = function () { }, 1000); } } else { - if (ImprovedTube.shortsAutoScrollInterval) { - clearInterval(ImprovedTube.shortsAutoScrollInterval); - ImprovedTube.shortsAutoScrollInterval = null; + if (ImprovedTube.shortsAutoScroll) { + clearInterval(ImprovedTube.shortsAutoScroll); + ImprovedTube.shortsAutoScroll = null; } } };