Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (async () => {
- const results = {};
- const delay = ms => new Promise(r => setTimeout(r, ms));
- // Wait for element to appear
- const waitForElement = (selector, timeout = 8000) => {
- return new Promise((resolve, reject) => {
- const start = Date.now();
- const check = () => {
- const el = document.querySelector(selector);
- if (el) return resolve(el);
- if (Date.now() - start > timeout) return reject(new Error(`Timeout waiting for ${selector}`));
- setTimeout(check, 200);
- };
- check();
- });
- };
- // Wait for element to be removed
- const waitForElementRemoved = (selector, timeout = 5000) => {
- return new Promise((resolve, reject) => {
- const start = Date.now();
- const check = () => {
- const el = document.querySelector(selector);
- if (!el) return resolve();
- if (Date.now() - start > timeout) return reject(new Error(`Timeout waiting for ${selector} to be removed`));
- setTimeout(check, 200);
- };
- check();
- });
- };
- // Get initial list of case slugs and names
- const getCaseList = () => {
- const links = [...document.querySelectorAll('a.chest-slide[href^="/cases/"]')];
- return links.map(link => ({
- name: link.querySelector('span.color-text-3')?.textContent?.trim() || 'Unknown',
- href: link.href,
- slug: link.getAttribute('href')
- }));
- };
- const allCases = getCaseList();
- console.log(`Found ${allCases.length} cases. Starting scrape...`);
- for (let i = 0; i < allCases.length; i++) {
- const caseInfo = allCases[i];
- console.log(`[${i+1}/${allCases.length}] ${caseInfo.name}`);
- try {
- // Re-query the case link to ensure it's fresh
- const currentLinks = [...document.querySelectorAll('a.chest-slide[href^="/cases/"]')];
- const targetLink = currentLinks.find(link => link.href === caseInfo.href);
- if (!targetLink) {
- throw new Error('Case link not found in DOM (maybe page changed?)');
- }
- // Click the case
- targetLink.click();
- // Wait for loot container
- await waitForElement('.ChestGameLoot', 12000);
- await delay(1000); // extra render time
- // Scrape items
- const slides = document.querySelectorAll('.ChestGameLoot .loot-slide');
- const items = [...slides].map(slide => {
- try {
- const nameEl = slide.querySelector('.loot-name');
- const name = nameEl?.textContent?.trim() || '';
- const img = slide.querySelector('.loot-icon img')?.src || '';
- const priceEl = slide.querySelector('.TokenText span.size-xs');
- const priceText = priceEl?.textContent?.trim() || '';
- const price = parseInt(priceText.replace(/,/g, ''), 10) || 0;
- const rateContainer = slide.querySelector('.justify-center.margin-top-2');
- const rateSpan = rateContainer?.querySelector('span.size-xxxs');
- const rateText = rateSpan?.textContent?.trim() || '';
- let rate = null;
- if (rateText.includes('%')) rate = parseFloat(rateText.replace('%', '')) || null;
- return { name, price, priceFormatted: priceText, dropRate: rate, dropRateFormatted: rateText, image: img };
- } catch (e) {
- return null;
- }
- }).filter(it => it && it.name);
- results[caseInfo.name] = {
- slug: caseInfo.slug,
- url: caseInfo.href,
- itemCount: items.length,
- items
- };
- console.log(` ✓ ${items.length} items`);
- // Go back to listing (works if the modal uses pushState)
- history.back();
- await waitForElementRemoved('.ChestGameLoot', 5000);
- await delay(500); // settle
- } catch (e) {
- console.error(` ✗ Failed:`, e.message);
- results[caseInfo.name] = { slug: caseInfo.slug, url: caseInfo.href, error: e.message };
- // Try to force close modal
- try {
- const backdrop = document.querySelector('.BaseElement.Backdrop');
- if (backdrop) backdrop.click();
- document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
- } catch (_) {}
- // If we navigated away, go back
- if (window.location.href !== caseInfo.href) {
- history.back();
- }
- await delay(1000);
- }
- // Extra delay between cases
- await delay(600 + Math.random() * 400);
- }
- // Download JSON
- const blob = new Blob([JSON.stringify(results, null, 2)], { type: 'application/json' });
- const url = URL.createObjectURL(blob);
- const a = document.createElement('a');
- a.href = url;
- a.download = `goldpump_loot_${new Date().toISOString().slice(0,10)}.json`;
- a.click();
- URL.revokeObjectURL(url);
- const total = Object.values(results).reduce((sum, c) => sum + (c.itemCount || 0), 0);
- console.log(`✅ Done! ${Object.keys(results).length} cases, ${total} items.`);
- return results;
- })();
Advertisement
Add Comment
Please, Sign In to add comment