Skip to content

Instantly share code, notes, and snippets.

@Igloczek
Created January 29, 2025 19:21
Show Gist options
  • Select an option

  • Save Igloczek/422b0eaf301fe9358832ee67df958c9f to your computer and use it in GitHub Desktop.

Select an option

Save Igloczek/422b0eaf301fe9358832ee67df958c9f to your computer and use it in GitHub Desktop.

Revisions

  1. Igloczek created this gist Jan 29, 2025.
    41 changes: 41 additions & 0 deletions script.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    (async function collectSpotifyPlaylist() {
    const TRACK_SELECTOR = '._iQpvk1c9OgRAc8KRTlH';

    // Find the correct scroll container
    let scrollContainers = document.querySelectorAll('[data-overlayscrollbars-viewport]');
    let scrollContainer = scrollContainers.length > 1 ? scrollContainers[1] : scrollContainers[0];

    if (!scrollContainer) {
    console.error("Could not find the scrollable playlist container.");
    return;
    }

    let results = new Set(); // To store unique tracks
    let lastTrackCount = 0;

    function extractTracks() {
    document.querySelectorAll(TRACK_SELECTOR).forEach(el => {
    results.add(el.innerText.replace('\n', ' by '));
    });
    }

    async function scrollAndCollect() {
    while (true) {
    extractTracks();

    scrollContainer.scrollBy(0, scrollContainer.clientHeight); // Scroll one viewport down
    await new Promise(resolve => setTimeout(resolve, 1000)); // Wait longer for new content

    let currentTrackCount = results.size;
    if (currentTrackCount === lastTrackCount) {
    break; // Stop when no new tracks are loaded
    }

    lastTrackCount = currentTrackCount;
    }

    console.log([...results].join('\n')); // Print all collected tracks
    }

    scrollAndCollect();
    })();