It is currently 17 Aug 2017, 03:36
   
Text Size

Parse new set card data from MTG-Salvation

Moderators: noxx, Aurum, fireshoes, jeffwadsworth, BetaSteward, LevelX, North, escplan9, CCGHQ Admins

Parse new set card data from MTG-Salvation

Postby LevelX » 09 Aug 2017, 05:20

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);
})();
User avatar
LevelX
DEVELOPER
 
Posts: 1594
Joined: 08 Dec 2011, 15:08
Has thanked: 173 times
Been thanked: 336 times

Return to Developers Talk

Who is online

Users browsing this forum: No registered users and 2 guests


Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (based on users active over the past 10 minutes)
Most users ever online was 279 on 11 Jul 2013, 22:03

Users browsing this forum: No registered users and 2 guests

Login Form