Skip to content

Instantly share code, notes, and snippets.

@judell
Created October 5, 2024 21:17
Show Gist options
  • Save judell/94638a957ddf8daae8d63925f61c3010 to your computer and use it in GitHub Desktop.
Save judell/94638a957ddf8daae8d63925f61c3010 to your computer and use it in GitHub Desktop.
votefwd-2

Claude ChatGPT

async function gatherBundles() {
    // Function to scroll the page to the bottom to trigger loading of new content
    function scrollPage() {
        return new Promise((resolve) => {
            let lastScrollTop = window.scrollY;
            const interval = setInterval(() => {
                window.scrollBy(0, 1000); // Scroll down by 1000px
                if (window.scrollY === lastScrollTop) {
                    clearInterval(interval);
                    resolve(); // Resolving the promise when no further scrolling happens
                }
                lastScrollTop = window.scrollY;
            }, 500); // Adjust scrolling speed if necessary
        });
    }
// Scroll the page to load all bundles
await scrollPage();

// After scrolling, collect the bundles
const bundles = document.querySelectorAll('li.bundle-list-item');
const results = [];

bundles.forEach(bundle => {
    // Extract user ID
    const userId = bundle.querySelector('span.font-monospace').textContent.trim();

    // Extract status from "data-testid" attribute
    const dataTestId = bundle.getAttribute('data-testid');
    const status = dataTestId.split('-').pop();

    // Push the result in the desired format
    results.push(`${userId} ${status}`);
});

// Output the gathered results
console.log(results.join('\n'));

}

// Run the function to gather and log the bundles gatherBundles();


// Function to extract bundle information
function extractBundleInfo(bundle) {
const id = bundle.querySelector('span.font-monospace').textContent.trim();
const status = bundle.getAttribute('data-testid').split('-').pop();
return ${id} ${status};
}

// Function to scroll and extract all bundles async function scrollAndExtractBundles() { const bundles = []; const container = document.querySelector('.bundle-list-container'); let lastHeight = container.scrollHeight;

while (true) {
    // Extract current visible bundles
    document.querySelectorAll('li.bundle-list-item').forEach(bundle => {
        bundles.push(extractBundleInfo(bundle));
    });

    // Scroll to the bottom of the container
    container.scrollTo(0, container.scrollHeight);

    // Wait for new content to load
    await new Promise(resolve => setTimeout(resolve, 1000));

    // Check if we've reached the bottom
    if (container.scrollHeight === lastHeight) {
        break;
    }
    lastHeight = container.scrollHeight;
}

return [...new Set(bundles)]; // Remove duplicates

}

// Run the extraction and log results scrollAndExtractBundles().then(results => { console.log("Unprepped bundles:"); console.log(results.filter(r => r.includes("UNPREPPED")).join("\n")); console.log("\nPrepped bundles:"); console.log(results.filter(r => r.includes("PREPPED")).join("\n")); });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment