Clicker Heroes Mercs

HTML

<textarea id="savegame" placeholder="Paste your save game here"></textarea>
<br>Number of mercs:
<br>
<input type="number" step="1" min="1" id="inputMercs" value="100">
<button onclick="readSave()">Read save</button>
<div id="error"></div>
<div id="mercListPanel">
    <ol id="mercList"></ol>
</div>

CSS

#mercListPanel {
    height: 500px;
    overflow: auto;
    margin: 10px;
    border: 1px solid grey;
    border-radius: 10px;
    padding: 3px;
    background-color: #ddd;
}
#mercList > li {
    color: #333;
    font-size: 10pt;
}
li > span[data-rarity="Common"] {
    color: grey;
    font-size: 7pt;
}
li > span[data-rarity="Uncommon"] {
    color: darkgreen;
    font-size: 7pt;
}
li > span[data-rarity="Rare"] {
    color: blue;
    font-size: 11pt;
}
li > span[data-rarity="Epic"] {
    color: violet;
    font-size: 12pt;
    background-color: #333;
}
li > span[data-rarity="Fabled"] {
    color: lightgreen;
    font-size: 14pt;
    background-color: #333;
}
li > span[data-rarity="Mythical"] {
    color: lightblue;
    font-size: 16pt;
    background-color: #333;
}
li > span[data-rarity="Legendary"] {
    color: yellow;
    font-size: 18pt;
    background-color: #333;
}
li > span[data-rarity="Transcendent"] {
    color: magenta;
    font-size: 20pt;
    background-color: #333;
}
li > span[data-type="Gold"] {
    text-decoration: line-through;
}
li > span[data-type="HS"] {
    
}
li > span[data-type="Rubies"] {
    text-shadow: 0 0 3px rgba(255, 0, 99, 0.8);
}
li > span[data-type="Skills"] {
    text-decoration: line-through;
}
li > span[data-type="Success"] {
    
}
li > span[data-type="Recruitment"] {
    
}

JavaScript

// http://liveweave.com/ft6IWE

function readSave() {
    var txt = document.getElementById("savegame").value;
    var inputMercs = document.getElementById("inputMercs").value;
    document.getElementById('mercList').innerHTML = '';

    if (txt.indexOf("Fe12NAfA3R6z4k0z") == -1) {
        document.getElementById("error").innerHTML = "Not a valid save, try again.";
        return;
    }

    document.getElementById("error").innerHTML = "Decoding...";
    var result = txt.split("Fe12NAfA3R6z4k0z");
    txt = "";
    for (var i = 0; i < result[0].length; i += 2) {
        txt += result[0][i];
    }
    var data = JSON.parse(decode64(txt));
    mercs(data.mercenaries.mercRoller.seed, inputMercs);
}

function mercs(seed, inputMercs) {
    var output = "";
    var bonusTypes = ["Gold", "HS", "Rubies", "Skills", "Success", "Recruitment"];
    for (var i = 0; i < inputMercs; i++) {
        seed = randNum(seed); // gender
        seed = randNum(seed); // name
        seed = randNum(seed); // death phrase
        seed = randNum(seed); // rarity
        var rarity = getRarity(seed);
        seed = randNum(seed); // bonus type
        var bonusType = seed % 6;
        while (bonusType == 4) {
            seed = randNum(seed); // if bonus type is Success keep trying
            bonusType = seed % 6;
        }
        seed = randNum(seed); // added with nov 24th patch
        output += '<li><span data-rarity="' + rarity + '" data-type="' + bonusTypes[bonusType] + '">' + rarity + ' ' + bonusTypes[bonusType] + '</span></li>';
    }
    document.getElementById("error").innerHTML = '';
    document.getElementById("mercList").innerHTML = output;
}

function randNum(seed) {
    return (seed * 16807) % 2147483647;
}

function getRarity(seed) {
    var chance = [5000, 2000, 800, 300, 100, 25, 8, 1];
    var rarities = ["Common", "Uncommon", "Rare", "Epic", "Fabled", "Mythical", "Legendary", "Transcendent"];
    var sum = 0;
    for (var i = 0; i < 8; i++)
    sum += chance[i];
   ...