Skip to content

Instantly share code, notes, and snippets.

@Abdallatif
Last active November 13, 2021 15:48
Show Gist options
  • Save Abdallatif/b5b04c3132cfc6c6720e937a36956c96 to your computer and use it in GitHub Desktop.
Save Abdallatif/b5b04c3132cfc6c6720e937a36956c96 to your computer and use it in GitHub Desktop.
Add a delete button for videos in a youtube playlist

This is a script that adds a delete button to clean up a playlist (Watch Later/Liked videos ...etc) so you can delete videos quickly without opening a menu.

Copy the following code and paste it in the devtools console after you open the playlist page:

const videos = document.querySelectorAll("ytd-playlist-video-renderer");

for (const video of videos) {
	const deleteButton = document.createElement("button")
	deleteButton.innerHTML = `x`;
	deleteButton.style = "margin-top: -48px; margin-right: -29px; margin-left: 4px; z-index: 10; cursor: pointer";
	video.prepend(deleteButton);

	deleteButton.addEventListener("click", () => {
		video.querySelector(`button[aria-label="Action menu"]`).click();
		setTimeout(() => {
		    document.querySelector("ytd-menu-service-item-renderer yt-formatted-string span").click()
		}, 10);
	});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment