TCGPlayer Cart/History to CSV in Console

Takes a TCGPlayer Cart/History and spits out a CSV

目前为 2024-03-12 提交的版本。查看 最新版本

// ==UserScript==
// @name         TCGPlayer Cart/History to CSV in Console
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Takes a TCGPlayer Cart/History and spits out a CSV
// @author       multimeric, ganondorc, micool777
// @match        https://cart.tcgplayer.com/*
// @match        https://store.tcgplayer.com/myaccount/orderhistory
// @match        https://store.tcgplayer.com/shoppingcart/review
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tcgplayer.com
// @grant        none
// @require      http://code.jquery.com/jquery-3.4.1.min.js
// @license      MIT
// ==/UserScript==
window.addEventListener('load', function() {
    function qs(element, query){
        // Finds an element by selector and returns it as an array
        return Array.from(element.querySelectorAll(query))
    }

    let csv = 'Name\tRarity\tCondition\tIndividual Price\tQuantity\n';
    for (let order of qs(document, '.orderWrap')){
        for (let tr of qs(order, '.orderTable tr')){
            try{
                let items = [
                    qs(tr, '.nocontext')[0].innerText,
                    qs(tr, '.orderHistoryDetail')[0].childNodes[0].textContent.split(':')[1],
                    qs(tr, '.orderHistoryDetail')[0].childNodes[2].textContent.split(':')[1],
                    qs(tr, '.orderHistoryPrice')[0].innerText,
                    qs(tr, '.orderHistoryQuantity')[0].innerText
                ];
                csv += items.map(item => item.trim()).join('\t') + '\n';
            }
            catch {
                continue;
            }
        }
    }
    console.log(csv);
    // window.alert(csv);

    (function(){
        let str = ''
        let tables = Array.from($('.sellerWrapMarket'))
        for (let table of tables){
            let $table = $(table)
            let rows = Array.from($table.find('table.sellerTable'))
            for (let row of rows){
                let $row = $(row)
                // Card name
                str += '"' + $row.find('.itemsContents h3').text().replace(/ *\([^)]*\) */g, "") + '",'
                // Card condition
                // str += $($row.find('.detailsContents p').get(1)).text().trim().replace('\n', '') + '\t'
                // Card set
                // str += $row.find('.itemsContents p').text() + '\t'
                // Price
                str += $row.find('.priceBox').text().trim().replace(/\$/g, '')
                // Quantity
                // str += $row.find('.qtyBox').text().trim() + '\t'
                str += '\n'
            }
        }
        console.log(str);
        // window.alert(str);
    })()
}, false);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址