Skip to content

Instantly share code, notes, and snippets.

@wellingtonpgp
Created June 14, 2025 03:04
Show Gist options
  • Save wellingtonpgp/86ce6b268ebab8540b4cf7a86083e326 to your computer and use it in GitHub Desktop.
Save wellingtonpgp/86ce6b268ebab8540b4cf7a86083e326 to your computer and use it in GitHub Desktop.
(async function exportYoutubeSubscriptions() {
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
async function autoScroll() {
const distance = 1000;
let lastHeight = 0;
while (true) {
window.scrollBy(0, distance);
await delay(800);
const { scrollTop, scrollHeight, clientHeight } = document.documentElement;
if (scrollTop + clientHeight >= scrollHeight - 5 || scrollTop === lastHeight) break;
lastHeight = scrollTop;
}
console.log("✅ Scroll completo");
}
await autoScroll();
const elements = document.querySelectorAll('ytd-channel-renderer');
console.log(`🔍 Renderers encontrados: ${elements.length}`);
const channels = Array.from(elements).map(el => {
const nameEl = el.querySelector('yt-formatted-string#text');
const anchorEl = el.querySelector('a[href^="/@"], a[href^="/channel/"]');
const name = nameEl?.textContent.trim();
const href = anchorEl?.getAttribute('href');
const url = href ? `https://www.youtube.com${href}` : null;
return name && url ? { name, url } : null;
}).filter(Boolean);
console.log('📦 Canais extraídos:', channels.length);
console.table(channels);
if (channels.length === 0) {
console.warn("⚠️ Nenhum canal extraído. A estrutura da página pode ter mudado.");
return;
}
const blob = new Blob([JSON.stringify(channels, null, 2)], { type: 'application/json' });
const urlBlob = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = urlBlob;
a.download = 'youtube_subscriptions.json';
a.click();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment