1

(31 replies, posted in Site Discussion)

LucasVon wrote:

Hello, I edited the script a bit more to place the average CMC under the mana curve chart and make it look more like it's part of the website. Also commented out the console log and did some general tidying up of the formatting.

// ==UserScript==
// @name        deckboxCMC
// @match       https://deckbox.org/sets/*
// @description Calculates CMC in deckbox sets
// @version     0.6.1
// ==/UserScript==

// Function to append a new DOM element after another
function insertAfter(newNode, referenceNode) {
    referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}

// Initialize array and hash to hold mana costs
var manaCosts = {};
var totalCosts = [];

// Iterate through rows to get mana cost totals for each card
var x = document.getElementsByClassName("mtg_mana");
//console.log("mtg_mana element count: " + x.length);


for (i = 0; i < x.length; i++) {
    var re = /mtg_mana_[0-9URGBWCX]{1,2}/i;
    //console.log("This is a mana cost item: " + x[i].outerHTML);
    var row = x[i].parentElement.parentElement.id;
    //console.log("Parent element is " + row);
    //console.log("Card element looks like this: " + document.getElementById(row).innerHTML);
    var cardName = document.getElementById(row).innerHTML.match(/(?:a class="simple" href="https:\/\/deckbox\.org\/mtg\/.*" target="_blank">)(.*)(?:<\/a>)/)[1];
    //console.log("Card name is " + cardName);
    var stripped = x[i].outerHTML.match(re).toString();
    //console.log("This its stripped mana name: " + stripped);
    var strippedMore = stripped.replace("mtg_mana_", "");
    //console.log("Mana cost indicated: " + strippedMore);
    var converted = strippedMore.replace(/[URGBWC]([URGBWC])?/, "1");
    converted = converted.replace(/X/, "0");

    if (!manaCosts[row]) {
        //console.log("Adding new item to manaCosts hash for card " + cardName);
        //console.log("Found mana cost " + converted + " for card " + cardName);
        manaCosts[row] = Number(converted);
    } else {
        manaCosts[row] += Number(converted);
        //console.log("Found mana cost " + converted + " for card " + cardName);
    }
    //console.log("Total mana cost for " + cardName + " is " + manaCosts[row]);
}

// Summary of card costs by table row
//console.log("Here's what we found in the main deck: ");
for (var card in manaCosts) {
    // use hasOwnProperty to filter out keys from the Object.prototype
    if (manaCosts.hasOwnProperty(card)) {
        cardName = document.getElementById(card).innerHTML.match(/(?:a class="simple" href="https:\/\/deckbox\.org\/mtg\/.*" target="_blank">)(.*)(?:<\/a>)/)[1];
        if (document.getElementById(card).innerHTML.indexOf("wishlist") !== -1) {
            //console.log("Deck list has a wishlist.  I think this is YOUR deck.");
            var cardCount = document.getElementById(card).innerHTML.match(/(?:<td class="card_count deck_count.*>(\n)?)([0-9]{1,2})(?:(\n)?<\/td>\n<script>)/);
            cardCount = Number(cardCount[2]);
            //console.log("Raw cardCount is " + cardCount);
            //console.log("I think there are " + cardCount + " copies of " + cardName);
        } else {
            //console.log("Deck list DOESN'T have a wishlist.  I think this is someone elses deck.");
            cardCount = document.getElementById(card).innerHTML.match(/(?:<td class="card_count">)([0-9]*)(?:<\/td>\n<td class="card_name">)/)[1];
            //console.log("I think there are " + cardCount + " copies of " + cardName);
        }
        if (document.getElementById(card).innerHTML.indexOf("main") !== -1) {
            //console.log(cardCount + " copies of " + cardName + " (" + manaCosts[card] + ")");
            for (var i = 0; i < cardCount; i++) {
                //console.log("Adding mana cost " + manaCosts[card] + " for card " + cardName + " to the total.");
                totalCosts.push(manaCosts[card]);
            }
        } else {
            //console.log("Card " + cardName + " with value of " + card + " is not in main deck.  Will NOT use to calculate CMC average.");
        }
    }
}

// Get average
var total = 0;
//console.log("Found " + totalCosts.length + " cards in the main deck.");
for (var i = 0; i < totalCosts.length; i++) {
    //console.log("Adding mana cost number " + i + " to the total.");
    total += totalCosts[i];
    //console.log("Total is now: " + total);
}
//console.log("Dividing total mana cost of " + total + " by " + totalCosts.length + " total cards to find the average.");
var avg = total / totalCosts.length;
//console.log("Agerage CMC: " + avg);

// Create element with average CMC
var ElCMC = document.createElement('div');
ElCMC.id = 'avg_cmc';
ElCMC.style.textAlign = 'center';
ElCMC.style.fontSize = '10px';
ElCMC.style.color = '#484848';
ElCMC.textContent = "Average CMC: " + avg.toFixed(2);

// Insert the element after the mana curve chart
var ref = document.querySelector('#chart_curve');
insertAfter(ElCMC, ref);

Awesome, thanks!

2

(31 replies, posted in Site Discussion)

cybrosis wrote:

Awesome.  Can you edit your first post to include that version of the script.  Use the code button above the post edit box (https://deckbox.org/forum/extensions/pun_deckbox_bbcode/buttons/Oxygen/code.png) to format the code correctly.


Done.

3

(31 replies, posted in Site Discussion)

Works for the 20 or so decks I tested. Awesome work. Sebi should just add this to deckbox's code.

4

(31 replies, posted in Site Discussion)

cybrosis wrote:

I believe this update fixes the problem i mentioned before about non-singleton decks.  Need some outside testing since I'm pretty tired:


It seems to work for a few of a certain card, but not more. Here is an example: https://deckbox.org/sets/977088

The only time you will see this is for shadowborn or relentless decks where you can play any number of that card.

It worked on all the singleton decks I tested.

5

(31 replies, posted in Site Discussion)

Another bug: https://deckbox.org/sets/1043553

Returns "NaN".


Possibly from the commander having so many mana symbols? Not sure.


Edit: Same thing for these decks:

https://deckbox.org/sets/847100

https://deckbox.org/sets/1046290

https://deckbox.org/sets/750620

https://deckbox.org/sets/884169

https://deckbox.org/sets/1227193

https://deckbox.org/sets/514210

https://deckbox.org/sets/348273



Unsure what the common denominator is, they all worked before.

6

(31 replies, posted in Site Discussion)

cybrosis wrote:

Perhaps you could update your initial post with a copy of the script so people who find this thread can easily get access to it?

I also wonder if I should create a separate post somewhere on this forum to bring it to peoples attention.

A new post would probably be best. It should definitely be advertised, its such a useful feature. I can update my initial post as well, what do you use to inlay the code in the scroll-able box like that?

7

(31 replies, posted in Site Discussion)

cybrosis wrote:

Fixed:
1.  Was incorrectly parsing two digit numbers.  The script now does a replace on the mana element name rather than simply stripping to the last character.
2.  Was not set up to handle colorless mana.

    // ==UserScript==
    // @name        deckboxCMC
    // @match       https://deckbox.org/sets/*
    // @description Calculates CMC in deckbox sets
    // @version     0.4
    // ==/UserScript==

    var manaCosts = {};
    var totalCosts = [];

    var x = document.getElementsByClassName("mtg_mana");
    var i;
    for (i = 0; i < x.length; i++) {
        var re = /mtg_mana_[0-9URGBWCX]{1,2}/i;
        // console.log("This is a mana cost item: " + x[i].outerHTML);
        var row = x[i].parentElement.parentElement.id;
        // console.log("Parent element is " + row);
        var stripped = x[i].outerHTML.match(re).toString();
        // console.log("This its stripped mana name: " + stripped);
        var strippedMore = stripped.replace("mtg_mana_", "");
        // console.log("Mana cost indicated: " + strippedMore);
        var converted = strippedMore.replace(/[URGBWC]/, "1");
        var converted = converted.replace(/X/, "0");

        if (!manaCosts[row]) {
            // console.log("Adding new item to manaCosts hash for row " + row);
            // console.log("Found mana cost " + converted + " for row " + row);
            manaCosts[row] = Number(converted);
        } else {
            manaCosts[row] += Number(converted);
            // console.log("Found mana cost " + converted + " for row " + row);
        }
        // console.log("Total mana cost for " + row + " is " + manaCosts[row]);
    }

    // Summary of card costs by table row
    // console.log("Here's a hash of mana costs: ");
    for (var card in manaCosts) {
        // use hasOwnProperty to filter out keys from the Object.prototype
        if (manaCosts.hasOwnProperty(card)) {
            if (card.indexOf("main") !== -1) {
                // console.log("Card " + card + " with cost " + manaCosts[card] + " is in main deck.  Will use to calculate CMC average.");
                totalCosts.push(manaCosts[card]);
            } else {
                // console.log("Card " + card + " with cost " + manaCosts[card] + " is not in main deck.  Will NOT use to calculate CMC average.");
            }
        }
    }

    var total = 0;
    // console.log("Found " + totalCosts.length + " costs to work with");
    for(var i = 0; i < totalCosts.length; i++) {
        // console.log("Adding mana cost number " + i + " to the total.");
        total += totalCosts[i];
        // console.log("Total is now: " + total);
    }
    // console.log("Dividing total mana cost of " + total + " by " + totalCosts.length + " total cards to find the average.");
    var avg = total / totalCosts.length;
    // console.log("Agerage CMC: " + avg);

    var box = document.createElement( 'div' );
    box.id = 'myAlertBox';
    box.style.background = 'white';
    box.style.border = '2px solid red';
    box.style.padding = '4px';
    box.style.position = 'absolute';
    box.style.top = '8px';
    box.style.left = '8px';
    box.style.maxWidth = '400px';
    box.textContent = "Converted mana cost: " + avg;
    document.body.appendChild( box );

Working well, thanks!

8

(31 replies, posted in Site Discussion)

cybrosis wrote:

If you notice it bugging out or not working or seeming to give inaccurate results please let me know and I'll try to fix.  The whole thing is a quick and dirty hack job, but it seems to work for now.

Found a bug:

Doesn't work for this deck: https://deckbox.org/sets/1603743

Not sure why, box just doesn't show up.

9

(31 replies, posted in Site Discussion)

Just a quick update for anyone else looking to use it.

Works perfectly for me so far, no issues.

Thanks again!

10

(4 replies, posted in Site Discussion)

A great feature to have for deck-building would be a token notification feature where deckbox has a list of tokens you need for your deck based on the cards in the mainboard. Tapped out has a similar feature which is very useful.

11

(31 replies, posted in Site Discussion)

cybrosis wrote:

If you notice it bugging out or not working or seeming to give inaccurate results please let me know and I'll try to fix.  The whole thing is a quick and dirty hack job, but it seems to work for now.

Its better than not having it, so it works for me. Thanks again.

12

(31 replies, posted in Site Discussion)

cybrosis wrote:

Yeah this is working for me with tampermonkey.

https://www.dropbox.com/s/7h5w9c3t6e799 … 5.png?dl=0

Awesome, thanks.

13

(31 replies, posted in Site Discussion)

This will work with tampermonkey too I assume? I am reading into it now, its a new extension for me, but the functionality is worth a bit of a learning curve.

14

(31 replies, posted in Site Discussion)

Having the average CMC for a deck would be a useful stat for deckbuilding in EDH. I imagine its a quick add too.

Edit: Current Code:

    // ==UserScript==
    // @name        deckboxCMC
    // @match       https://deckbox.org/sets/*
    // @description Calculates CMC in deckbox sets
    // @version     0.6.1
    // ==/UserScript==

    // Initialize array and hash to hold mana costs
    var manaCosts = {};
    var totalCosts = [];

    // Iterate through rows to get mana cost totals for each card
    var x = document.getElementsByClassName("mtg_mana");

    for (i = 0; i < x.length; i++) {
        var re = /mtg_mana_[0-9URGBWCX]{1,2}/i;
        //console.log("This is a mana cost item: " + x[i].outerHTML);
        var row = x[i].parentElement.parentElement.id;
        //console.log("Parent element is " + row);
        //console.log("Card element looks like this: " + document.getElementById(row).innerHTML);
        var cardName = document.getElementById(row).innerHTML.match(/(?:a class="simple" href="https:\/\/deckbox\.org\/mtg\/.*" target="_blank">)(.*)(?:<\/a>)/)[1];
        //console.log("Card name is " + cardName);
        var stripped = x[i].outerHTML.match(re).toString();
        //console.log("This its stripped mana name: " + stripped);
        var strippedMore = stripped.replace("mtg_mana_", "");
        //console.log("Mana cost indicated: " + strippedMore);
        var converted = strippedMore.replace(/[URGBWC]([URGBWC])?/, "1");
        var converted = converted.replace(/X/, "0");

        if (!manaCosts[row]) {
            //console.log("Adding new item to manaCosts hash for card " + cardName);
            //console.log("Found mana cost " + converted + " for card " + cardName);
            manaCosts[row] = Number(converted);
        } else {
            manaCosts[row] += Number(converted);
            //console.log("Found mana cost " + converted + " for card " + cardName);
        }
        //console.log("Total mana cost for " + cardName + " is " + manaCosts[row]);
    }

    // Summary of card costs by table row
    console.log("Here's what we found in the main deck: ");
    for (var card in manaCosts) {
        // use hasOwnProperty to filter out keys from the Object.prototype
        if (manaCosts.hasOwnProperty(card)) {
            var cardName = document.getElementById(card).innerHTML.match(/(?:a class="simple" href="https:\/\/deckbox\.org\/mtg\/.*" target="_blank">)(.*)(?:<\/a>)/)[1];
            if (document.getElementById(card).innerHTML.indexOf("wishlist") !== -1) {
                //console.log("Deck list has a wishlist.  I think this is YOUR deck.");
                var cardCount = document.getElementById(card).innerHTML.match(/(?:<td class="card_count deck_count.*>(\n)?)([0-9]{1,2})(?:(\n)?<\/td>\n<script>)/);
                cardCount = Number(cardCount[2]);
                //console.log("Raw cardCount is " + cardCount);
                //console.log("I think there are " + cardCount + " copies of " + cardName);
            } else {
                //console.log("Deck list DOESN'T have a wishlist.  I think this is someone elses deck.");
                var cardCount = document.getElementById(card).innerHTML.match(/(?:<td class="card_count">)([0-9]*)(?:<\/td>\n<td class="card_name">)/)[1];
                //console.log("I think there are " + cardCount + " copies of " + cardName);
            }
            if (card.indexOf("main") !== -1) {
                console.log(cardCount + " copies of " + cardName + " (" + manaCosts[card] + ")");
                for(var i = 0; i < cardCount; i++) {
                    console.log("Adding mana cost " + manaCosts[card] + " for card " + cardName + " to the total.");
                    totalCosts.push(manaCosts[card]);
                }
            } else {
                console.log("Card " + cardName + " is not in main deck.  Will NOT use to calculate CMC average.");
            }
        }
    }

    // Get average
    var total = 0;
    console.log("Found " + totalCosts.length + " cards in the main deck.");
    for(var i = 0; i < totalCosts.length; i++) {
        //console.log("Adding mana cost number " + i + " to the total.");
        total += totalCosts[i];
        //console.log("Total is now: " + total);
    }
    console.log("Dividing total mana cost of " + total + " by " + totalCosts.length + " total cards to find the average.");
    var avg = total / totalCosts.length;
    console.log("Agerage CMC: " + avg);

    // Create pop up with CMC average
    var box = document.createElement( 'div' );
    box.id = 'myAlertBox';
    box.style.background = 'white';
    box.style.border = '2px solid red';
    box.style.padding = '4px';
    box.style.position = 'absolute';
    box.style.top = '8px';
    box.style.left = '8px';
    box.style.maxWidth = '400px';
    box.textContent = "Converted mana cost: " + avg;
    document.body.appendChild( box );

Awesome, thanks Sebi.

Great addition Sebi.

17

(2 replies, posted in Reddit MTG Trades)

whatsthepoint wrote:

Sunday funday bump

I have some stuff on your list, hit me up.

Up

Uppers

up

up

up

Updated offer

uppers

Updated my list after taking a few edh decks apart. I also have some nice alters for trade. Feel free to browse!

I am looking to trade for bulk. Rares or Mythics, English only, NM condition.

I will give...

12 cents per bulk rare
28 cents per bulk mythic

Anything on my tradelist is for trade for this. I use tcgmid market price for pricing.