Skip to content

Instantly share code, notes, and snippets.

@jesse-spevack
Created December 15, 2024 18:41
Show Gist options
  • Save jesse-spevack/9fafad7e4038e5252f42e3c79169ca1c to your computer and use it in GitHub Desktop.
Save jesse-spevack/9fafad7e4038e5252f42e3c79169ca1c to your computer and use it in GitHub Desktop.
Bulk remove videos from a youtube playlist
async function removeVideosFromPlaylist(count = 25) {
console.log('%c=== Starting Playlist Video Removal Script ===', 'color: #00ff00; font-weight: bold;');
console.log(`Will attempt to remove ${count} videos`);
for (let i = 0; i < count; i++) {
console.log(`\n%c[Step ${i + 1}/${count}] Starting removal process...`, 'color: #4CAF50; font-weight: bold;');
// 1. Find menu buttons
console.log('1️⃣ Searching for menu buttons...');
const menuButtons = Array.from(document.querySelectorAll('ytd-playlist-video-renderer ytd-menu-renderer button'));
console.log(` Found ${menuButtons.length} menu buttons`);
if (menuButtons.length === 0) {
console.log('%c❌ No menu buttons found. Stopping script.', 'color: #ff0000');
break;
}
// 2. Click menu button
console.log('2️⃣ Attempting to click first menu button...');
try {
const firstButton = menuButtons[0];
console.log(` Button text: "${firstButton.textContent}"`);
console.log(` Button aria-label: "${firstButton.getAttribute('aria-label')}"`);
firstButton.click();
console.log(' ✅ Successfully clicked menu button');
// 3. Wait for menu
console.log('3️⃣ Waiting for menu to appear...');
await new Promise(resolve => {
console.log(' ⏳ Waiting 1 second...');
setTimeout(resolve, 1000);
});
// 4. Find remove button
console.log('4️⃣ Searching for remove button...');
const removeButtons = Array.from(document.querySelectorAll('tp-yt-paper-item'))
.filter(item => {
const text = item.textContent.toLowerCase();
console.log(` Found menu item with text: "${text}"`);
return text.includes('remove from');
});
console.log(` Found ${removeButtons.length} remove buttons`);
// 5. Click remove button
if (removeButtons.length > 0) {
console.log('5️⃣ Attempting to click remove button...');
removeButtons[0].click();
console.log(' ✅ Successfully clicked remove button');
// 6. Wait for removal
console.log('6️⃣ Waiting for removal to complete...');
await new Promise(resolve => {
console.log(' ⏳ Waiting 1.5 seconds...');
setTimeout(resolve, 1500);
});
console.log(' ✅ Wait complete');
} else {
console.log('%c❌ No remove button found!', 'color: #ff0000');
}
} catch (error) {
console.error('%c❌ Error occurred:', 'color: #ff0000', error);
}
}
console.log('\n%c=== Script Execution Complete ===', 'color: #00ff00; font-weight: bold;');
}
// Run the script
console.clear(); // Clear previous console output
console.log('%cStarting script execution...', 'color: #blue; font-weight: bold;');
const result = removeVideosFromPlaylist(25);
console.log('Script initiated, waiting for completion...');
// Log when complete
result.then(() => console.log('%cScript promise resolved', 'color: #blue; font-weight: bold;'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment