From dee477b55a3f2c30647a859ec4d155dadb340406 Mon Sep 17 00:00:00 2001 From: ImprovedTube Date: Fri, 29 Sep 2023 16:59:11 +0200 Subject: [PATCH] fix #1768 fixing playlist repeat & shuffle --- .../www.youtube.com/playlist.js | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/js&css/web-accessible/www.youtube.com/playlist.js b/js&css/web-accessible/www.youtube.com/playlist.js index 7cfdac931..e2915e124 100644 --- a/js&css/web-accessible/www.youtube.com/playlist.js +++ b/js&css/web-accessible/www.youtube.com/playlist.js @@ -101,24 +101,34 @@ ImprovedTube.playlistRepeat = function () { if ( ImprovedTube.storage.playlist_repeat === true ) { setTimeout(function (){ var option = ImprovedTube.storage.playlist_repeat, - button = document.querySelector("ytd-playlist-loop-button-renderer button"), + button = document.querySelector("#button.ytd-playlist-loop-button-renderer") || document.querySelector("ytd-playlist-loop-button-renderer button") || document.querySelector("ytd-playlist-loop-button-renderer"); svg = button.querySelector("path").attributes.d.textContent.split(" ")[0]; - if (button && ((option === true && svg !== 'M20,14h2v5L5.84,19.02l1.77,1.77l-1.41,1.41L1.99,18l4.21-4.21l1.41,1.41l-1.82,1.82L20,17V14z') -// || (option === false && svg !== 'M21,13h1v5L3.93,18.03l2.62,2.62l-0.71,0.71L1.99,17.5l3.85-3.85l0.71,0.71l-2.67,2.67L21,17V13z') - )) { button.click(); } + if (button && (option === true && svg.startsWith('M21') + ) && button.querySelector("#tooltip")?.textContent !== 'Loop video' + && button.firstElementChild?.firstElementChild?.attributes[2]?.textContent !== 'Loop video' + && button.querySelector("#tooltip")?.textContent !== 'Turn off loop' + && button.firstElementChild?.firstElementChild?.attributes[2]?.textContent !== 'Turn off loop' + ) + { button.click(); } }, 5000); } }; +/* https://github.com/code-charity/youtube/issues/1768#issuecomment-1720423923 */ + /*------------------------------------------------------------------------------ 4.5.4 SHUFFLE ------------------------------------------------------------------------------*/ ImprovedTube.playlistShuffle = function () { - var button = ImprovedTube.elements.playlist.shuffle_button, + if ( ImprovedTube.storage.playlist_shuffle === true ) { + setTimeout(function (){ + var button = ImprovedTube.elements.playlist.shuffle_button, option = ImprovedTube.storage.playlist_shuffle; - try{ - if (button && ((option === true && button.firstElementChild.firstElementChild.attributes[2].textContent !== 'Loop video') || (option === 'disabled' && button.firstElementChild.firstElementChild.attributes[2].textContent === 'Loop playlist'))) { - button.click(); - } - }catch{} + button = document.querySelector('#playlist-actions #playlist-action-menu ytd-toggle-button-renderer'); + svg = button.querySelector("path").attributes.d.textContent.split(" ")[0]; + if (button && (option === true && svg.startsWith('M18.1') + ) ) + { button.click(); } + }, 5000); + } }; \ No newline at end of file