Skip to content

Commit

Permalink
Cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkelM committed May 21, 2024
1 parent 3f4dcc9 commit 14877bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
12 changes: 3 additions & 9 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ async function startDOMObserver(event) {
resetShuffleButtonText();

let pageType = getPageTypeFromURL(window.location.href);
// console.log(event)
// console.log(pageType)

// Get the channel id from the event data
let channelId;
Expand All @@ -44,19 +42,15 @@ async function startDOMObserver(event) {
} else if (pageType == "channel") {
channelId = event?.detail?.response?.response?.header?.c4TabbedHeaderRenderer?.channelId;
channelName = event?.detail?.response?.response?.header?.c4TabbedHeaderRenderer?.title;
// The event contents changed with a recent update. If the above doesn't work, try this:
if (!channelId) {
eventVersion = "newYTFinishEvent20240521";
eventVersion = "20240521";
channelId = event?.detail?.endpoint?.browseEndpoint?.browseId;
}
if (!channelName) {
eventVersion = "newYTFinishEvent20240521";
eventVersion = "20240521";
channelName = event?.detail?.response?.response?.header?.pageHeaderRenderer?.pageTitle;
}
}
// console.log(channelId)
// console.log(channelName)
console.log(eventVersion);

if (!channelId?.startsWith("UC")) {
// If no valid channelId was provided in the event, we won't be able to add the button
Expand All @@ -71,7 +65,7 @@ async function startDOMObserver(event) {
case "default":
channelPageRequiredElementLoadComplete = document.getElementById("channel-header");
break;
case "newYTFinishEvent20240521":
case "20240521":
channelPageRequiredElementLoadComplete = document.getElementById("page-header");
break;
}
Expand Down
7 changes: 1 addition & 6 deletions src/domManipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ export function buildShuffleButton(pageType, channelId, eventVersion, clickHandl
buttonDivOwner = [document.getElementById("channel-header").querySelector("#inner-header-container").children.namedItem("buttons")];
buttonDivExtraStyle = "margin-left: 8px;";
break;
case "newYTFinishEvent20240521":
case "20240521":
buttonDivOwner = [document.getElementById("page-header").querySelector(".page-header-view-model-wiz__page-header-headline-info").getElementsByTagName("yt-flexible-actions-view-model")[0]];
break;
}
break;
// TODO: Fix video shuffle button
case "video":
buttonDivID = "youtube-random-video-large-shuffle-button-video";
buttonDivExtraStyle = "margin-left: 8px;";
Expand All @@ -43,9 +42,6 @@ export function buildShuffleButton(pageType, channelId, eventVersion, clickHandl
return;
}

console.log(buttonDivOwner);

// TODO: How does this work with the new layout?
// If we are on a video page, modify the "min-width" of the two divs holding the buttons to make room for the 'Shuffle' button
// This doesn't fix them overlapping in all cases, but most times it does
if (pageType == "video") {
Expand Down Expand Up @@ -98,7 +94,6 @@ export function buildShuffleButton(pageType, channelId, eventVersion, clickHandl

// Create the button div & renderer
let buttonDiv;
// TODO: Check if the new styling for video page buttons is the same as for channel page buttons
if (pageType === "channel" || pageType === "video") {
buttonDiv = `
<div id="${buttonDivID}" class="style-scope ytd-c4-tabbed-header-renderer" style="align-items: center; display: flex; flex-direction: row; ${buttonDivExtraStyle}">
Expand Down

0 comments on commit 14877bb

Please sign in to comment.