Skip to content

Commit

Permalink
Gave the 'Untitled List' after a shuffle a proper name (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkelM authored Nov 25, 2023
1 parent ff09bd7 commit f1365be
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<!--Releasenotes start-->
- Added a new option to shuffle only from shorts.
- Reduced the time it takes to shuffle, as the extension now uses a more sophisticated way to decide whether or not to check if a video has been deleted or not.
- The playlist that is opened when shuffling (if the option is enabled) now has a better title and tooltip.
- The popup now feels smoother in some places, and will make it clearer when some inputs are invalid.
- Fixed bugs that would prevent some initialization logic to run after the extension is updated.
<!--Releasenotes end-->
Expand Down
8 changes: 7 additions & 1 deletion src/content.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Content script that is injected into YouTube pages
import { setDOMTextWithDelay, isVideoUrl, RandomYoutubeVideoError } from "./utils.js";
import { configSync, setSyncStorageValue } from "./chromeStorage.js";
import { buildShuffleButton, shuffleButton, shuffleButtonTextElement } from "./buildShuffleButton.js";
import { buildShuffleButton, shuffleButton, shuffleButtonTextElement, tryRenameUntitledList } from "./domManipulation.js";
import { chooseRandomVideo } from "./shuffleVideo.js";

// ---------- Initialization ----------
Expand Down Expand Up @@ -83,6 +83,12 @@ async function startDOMObserver(event) {
}

async function channelDetectedAction(pageType, channelId, channelName) {
// 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
if (pageType === "video") {
tryRenameUntitledList();
}

// We can get an error here if the extension context was invalidated and the user navigates without reloading the page
try {
// If we are still connected to the background worker, we can send a message to test the connection
Expand Down
9 changes: 9 additions & 0 deletions src/buildShuffleButton.js → src/domManipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ export function buildShuffleButton(pageType, channelId, clickHandler) {
});
}

export function tryRenameUntitledList() {
let untitledListElement = document.querySelector('ytd-playlist-panel-renderer#playlist.style-scope.ytd-watch-flexy').querySelector('yt-formatted-string');

if (untitledListElement) {
untitledListElement.innerText = "Random YouTube Video - Playlist";
untitledListElement.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.";
}
}

// ----- Private -----
function finalizeButton(pageType, channelId, clickHandler) {
let buttonDivID = "youtube-random-video-shuffle-button";
Expand Down
2 changes: 1 addition & 1 deletion webpack.common.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = env => {
entry: {
// JS
background: './src/background.js',
buildShuffleButton: './src/buildShuffleButton.js',
domManipulation: './src/domManipulation.js',
content: './src/content.js',
shuffleVideo: './src/shuffleVideo.js',
utils: './src/utils.js',
Expand Down

0 comments on commit f1365be

Please sign in to comment.