diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a91eac9..dab63ec0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,18 @@ # Changelog -## v3.1.7 +## v3.1.8-beta +- Fixed a bug where the shuffle button would sometimes not be added to the page if it was opened directly from a new tab. +- Fixed a bug where the playlist created by the extension would sometimes not be renamed correctly. + + +## v3.1.7 + - The extension's news page can now be updated with breaking changes or other important information without the need to update the extension itself. - Fixed some dynamic content on the News page. - Added a hint in the popup if no channel has yet been visited. - Removed some unneeded scripts from the extension's pages. - ## v3.1.6 diff --git a/src/content.js b/src/content.js index 90e0b205..fbf605a2 100644 --- a/src/content.js +++ b/src/content.js @@ -98,8 +98,8 @@ async function startDOMObserver(event) { } async function channelDetectedAction(pageType, channelId, channelName, eventVersion) { - // It might be that we got here after shuffling, in which case we want to check if there is a 'Untitled List' that we can rename - // We do this before anything else to prevent the previous text from showing shortly + // It might be that we got to this page after shuffling, in which case we want to check if there is a 'Untitled List' that we can rename + // We do this before anything else to prevent the previous text from showing if (pageType === "video") { tryRenameUntitledList(); } diff --git a/src/domManipulation.js b/src/domManipulation.js index 77ff92c8..8036ca95 100644 --- a/src/domManipulation.js +++ b/src/domManipulation.js @@ -139,16 +139,26 @@ export function buildShuffleButton(pageType, channelId, eventVersion, clickHandl }); } -// With the way that YouTube handles navigation, the playlist title somehow won't get updated correctly when navigating if we change it here at any point -// So we need to change it back if the user moves to a different playlist -export function tryRenameUntitledList() { - let mainPlaylistElement = document.querySelector('ytd-playlist-panel-renderer#playlist.style-scope.ytd-watch-flexy').querySelector('yt-formatted-string.title.style-scope.ytd-playlist-panel-renderer'); - let collapsedPlaylistElement = document.querySelector('ytd-playlist-panel-renderer#playlist.style-scope.ytd-watch-flexy').querySelector('yt-formatted-string.byline-title.style-scope.ytd-playlist-panel-renderer'); +export function tryRenameUntitledList(attempt = 1) { + let mainPlaylistElement = document.querySelector('ytd-playlist-panel-renderer#playlist.style-scope.ytd-watch-flexy')?.querySelector('yt-formatted-string.title.style-scope.ytd-playlist-panel-renderer'); + let collapsedPlaylistElement = document.querySelector('ytd-playlist-panel-renderer#playlist.style-scope.ytd-watch-flexy')?.querySelector('yt-formatted-string.byline-title.style-scope.ytd-playlist-panel-renderer'); + + // Retry this a few times, in case the element has not yet loaded in + if (!mainPlaylistElement || !collapsedPlaylistElement) { + if (attempt <= 10) { + setTimeout(() => tryRenameUntitledList(attempt + 1), 200); + return; + } else { + return; + } + } for (let playlistType of [mainPlaylistElement, collapsedPlaylistElement]) { if (playlistType && window.location.href.includes("&list=TL") && playlistType.title == "Untitled List") { playlistType.innerText = "Random YouTube Video - Playlist"; - playlistType.title = "This playlist is unlisted, temporary and cannot be saved. Until it is removed by YouTube (which will happen automatically), you can revisit it using the link in the URL bar."; + playlistType.title = "This playlist is unlisted, temporary and cannot be saved. You can visit it using the link in the URL bar until it is removed by YouTube, which will happen automatically."; + // With the way that YouTube handles navigation, the playlist title somehow won't get updated correctly when navigating if we change it here at any point + // So we need to change it back if the user moves to a different playlist } else if (playlistType) { playlistType.innerText = playlistType.title; } diff --git a/static/manifest.json b/static/manifest.json index d7952e6e..23d7b25f 100644 --- a/static/manifest.json +++ b/static/manifest.json @@ -2,7 +2,7 @@ "name": "Random YouTube Video", "description": "Customize, shuffle and play random videos from any YouTube channel.", "version": "3.1.7", - "version_name": "3.1.7", + "version_name": "3.1.8-beta", "manifest_version": 3, "content_scripts": [ { @@ -12,7 +12,7 @@ "matches": [ "*://*.youtube.com/*" ], - "run_at": "document_end" + "run_at": "document_start" } ], "permissions": [