Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(new option) playlist popup button #1832

Merged
merged 7 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added calls to playlistPopupUpdate
  • Loading branch information
MAZ01001 committed Nov 15, 2023
commit 449fbdc36771a538ab8c0dc0d806a588bea40ab9
7 changes: 4 additions & 3 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ ImprovedTube.ytElementsHandler = function (node) {
this.playlistReverse();
}
}
this.playlistPopupUpdate();
} else if (name === 'YTD-GUIDE-SECTION-RENDERER') {
if (!this.elements.sidebar_section) {
this.elements.sidebar_section = node;
Expand All @@ -122,7 +123,9 @@ ImprovedTube.ytElementsHandler = function (node) {
if(document.documentElement.dataset.pageType === 'video'){
this.hideDetailButton(node.$['flexible-item-buttons'].children);
}
} else if (name === 'YTD-SUBSCRIBE-BUTTON-RENDERER') {
} else if (name === 'YTD-PLAYLIST-HEADER-RENDERER' || (name === 'YTD-MENU-RENDERER' && node.classList.contains('ytd-playlist-panel-renderer'))) {
this.playlistPopupUpdate();
} else if (name === 'YTD-SUBSCRIBE-BUTTON-RENDERER') {
if (node.className.indexOf('ytd-c4-tabbed-header-renderer') !== -1) {
ImprovedTube.blacklist('channel', node);
}
Expand Down Expand Up @@ -255,8 +258,6 @@ ImprovedTube.ytElementsHandler = function (node) {
ImprovedTube.chapters(node);}, 200);
}
}
// TODO move do different ifs ↑ to minimize calls (~ mini player, video player, and playlist page)
this.playlistPopup();

};

Expand Down
6 changes: 4 additions & 2 deletions js&css/web-accessible/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ ImprovedTube.observer = new MutationObserver(function (mutationList) {
for (var j = 0, k = mutation.addedNodes.length; j < k; j++) {
ImprovedTube.childHandler(mutation.addedNodes[j]);
}
for (const node of mutation.removedNodes){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might should fix our other playlist buttons like this too @MAZ01001 👍

Copy link
Contributor Author

@MAZ01001 MAZ01001 Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, or really every element that gets inserted into the DOM

That's how I wrote this playlist-popup button:

  1. One function that only creates the button (as an object) and returns it (does not insert it into the DOM)
  2. and another that checks if it should add a button to the current page (and adds it via 1.) or update any existing buttons

Then 2. can be called anytime since it checks for itself if it should insert something to the DOM, so I added it to every page where a button might be needed (in the ImprovedTube.childHandler) and whenever any existing buttons got deleted by YT (the for-loop you highlighted).

if(node.nodeName === 'BUTTON' && node.id === 'it-popup-playlist-button') ImprovedTube.playlistPopupUpdate();
}
}
}
}).observe(document.documentElement, {
Expand Down Expand Up @@ -105,8 +108,7 @@ document.addEventListener('yt-page-data-updated', function (event) {
ImprovedTube.playlistShuffle();
ImprovedTube.playlistReverse();
}
// TODO when does this event fire ?
// ImprovedTube.playlistPopup();
ImprovedTube.playlistPopupUpdate();
});

window.addEventListener('load', function () {
Expand Down