Skip to content

Instantly share code, notes, and snippets.

@TaylanTatli
Last active December 4, 2023 02:05
Show Gist options
  • Save TaylanTatli/55547a54e029a1cfd9f9e99344edc424 to your computer and use it in GitHub Desktop.
Save TaylanTatli/55547a54e029a1cfd9f9e99344edc424 to your computer and use it in GitHub Desktop.
Youtube & YTMusic Scripts
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function deleteLibSongs() {
`use strict`;
var items = document.body.querySelectorAll(
".dropdown-trigger.ytmusic-menu-renderer"
);
var out;
for (var i = 0; i < items.length; i++) {
items[i].click();
out = setTimeout(function () {
if (
document.querySelector(
`ytmusic-toggle-menu-service-item-renderer.ytmusic-menu-popup-renderer`
).lastElementChild
) {
document
.querySelector(
`ytmusic-toggle-menu-service-item-renderer.ytmusic-menu-popup-renderer`
)
.lastElementChild.click();
}
}, 100);
await sleep(500); // sleep cause browser can not handle the process
clearTimeout(out);
}
}
deleteLibSongs();
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function deleteLikedVideos() {
`use strict`;
var items = document.querySelectorAll(
`#primary ytd-playlist-video-renderer yt-icon-button.dropdown-trigger > button[aria-label]`
);
var out;
for (var i = 0; i < items.length; i++) {
items[i].click();
out = setTimeout(function () {
if (
document.querySelector(
`tp-yt-paper-listbox.style-scope.ytd-menu-popup-renderer`
).lastElementChild
) {
document
.querySelector(
`tp-yt-paper-listbox.style-scope.ytd-menu-popup-renderer`
)
.lastElementChild.click();
}
}, 100);
await sleep(500); // sleep cause browser can not handle the process
clearTimeout(out);
}
}
deleteLikedVideos();
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function $$(selector,context=document.documentElement){return[...context?.querySelectorAll?.(selector) ?? []]}
async function removeduplicates() {
let titles = $$("#primary a#video-title")
.filter((i,j,k)=>k.
findIndex(k=>k.href.includes(Object.fromEntries(new URLSearchParams(i.href))['https://www.youtube.com/watch?v']))!==j)
for (let i = 0; i < titles.length; i++) {
titles[i].focus()
titles[i].closest("#contents > *").querySelector('button[aria-label="İşlem menüsü"]').click()
await sleep(100)
var things = document.evaluate(
'//span[contains(text(),"listesinden kaldır")]',
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
);
await sleep(300)
for (var j = 0; j < things.snapshotLength; j++) {
things.snapshotItem(j).click();
}
console.log(titles[i].innerText)
}
}
removeduplicates()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment