Page 1 of 1

Parse new set card data from MTG-Salvation

PostPosted: 09 Aug 2017, 05:20
by LevelX
Retrieving card Data from MTG-Salvation Spoiler

Open Opera/chrome and go to the Spoiler page
Push CRTL + SHIFT + I to open the Opera debugger or the command to open the Chrome console
Go to the console tab and post the script
Change the set name in Line number 5
Push return
mark the output and copy it to the mtg-cards-data.txt file.

Code: Select all
(function(){
    var x = '';
    function printCard(card){
        var text = '';
        text += card.name + '|[ENTER HERE THE SET NAME]|';
        text += (card.number ? card.number : '') + '|';
        text += card.rarity[0].replace('B', 'L') + '|';
        text += ((card.cost.length > 0) ? '{' : '') + card.cost.join('}{') + ((card.cost.length > 0) ? '}|' : '|');
        text += card.type + '|';
        text += (card.pt ? card.pt.split('/').join("|") : '|') + '|';
        text += (card.abilities ? card.abilities.join('$') : '') + '|';
        return text;
    }
    $.each($('table[cellpadding=5]'), function(index, value) {
        var $value = $(value);
        var card = {};
        card.name = $value.find('td[width=220px]:eq(0) a:eq(1)').attr('name');
        card.cost = [];
        $.each($value.find('td[width=80px]:eq(0) img'), function(idx, val) {
            card.cost.push(val.alt.toUpperCase());
        });
        card.type = $value.find('td[width=220px]:eq(1)').text();
        card.rarity = $value.find('td[width=80px]:eq(1) img').attr('alt');
        var findResult = $value.find('td[colspan=2]:eq(0)');
        if(findResult.length > 0){
            var text = findResult.html().replace(/<img src="http:\/\/forums.mtgsalvation.com\/images\/smilies\/[\w\d]+?.gif" alt="/g, '{');
            text = text.replace(/">/g, '}');
            text = text.replace(/{{/g, '{');
            text = text.replace(/}}/g, '}');
            text = text.replace(/(\r\n|\n|\r)/gm,"");
            card.abilities = text.split('<br>');
        }
        findResult = $value.find('tr:last i')
        if(findResult.length > 0){
            card.number = findResult.html().replace('#', '').split('/')[0];
        }
        findResult = $value.find('tr:last td:last')
        if(findResult.length > 0){   
            card.pt = findResult.html();
        }

        if(card.name.indexOf('//') != -1){
            var card1 = {};
            var card2 = {};
            card1.name = card.name.split(' // ')[0];
            card2.name = card.name.split(' // ')[1];
            card1.cost = card.cost;
            card2.cost = [];
            card1.rarity = card.rarity;
            card2.rarity = card.rarity;
            card1.type = card.type.split(' // ')[0];
            card2.type = card.type.split(' // ')[1];
            card1.pt = card.pt.split(' // ')[0];
            card2.pt = card.pt.split(' // ')[1];
            if(card.number){
                card1.number = card.number;
                card2.number = card.number;
            }
            var first = true;
            card1.abilities = [];
            card2.abilities = [];
            for(var i = 0; i < card.abilities.length; i++){
                if(card.abilities[i].indexOf('//') != -1 || card.abilities[i].indexOf('--') != -1){
                    first = false;
                }else if (card.abilities[i].length > 0) {
                    if(first){
                        card1.abilities.push(card.abilities[i]);
                    }else{
                        card2.abilities.push(card.abilities[i]);
                    }
                }
            }
            x += printCard(card1) + '\n';
            x += printCard(card2) + '\n';
        }else{
            x += printCard(card) + '\n';
        }
    });
    console.log(x);
})();

Re: Parse new set card data from MTG-Salvation

PostPosted: 14 Jan 2025, 07:33
by victoryearing
Push CRTL + SHIFT + I to open the Opera debugger or the command to open the Chrome console

Re: Parse new set card data from MTG-Salvation

PostPosted: 06 Aug 2025, 09:01
by selecthave
If you're working with MTG Forge or other tools, check if they support Scryfall/MTGJSON imports.

Re: Parse new set card data from MTG-Salvation

PostPosted: 13 Sep 2025, 07:43
by ryansmith53
The script itself is pretty handy, especially the way it handles split cards and formats abilities. However, since MTG-Salvation spoilers are no longer maintained, I think it might be better in the long run to switch over to something like Scryfall or MTGJSON, as they provide more reliable and structured data. Still, for historical sets or for people who want to practice parsing HTML directly, this guide is clear and practical.