mich939 / Drops

// ==UserScript==
// @name         Drops
// @namespace    http://tampermonkey.net/
// @copyright    2019, mich939
// @version      0.1.2
// @description  Live drops at battle page
// @author       You
// @match        https://*.e-sim.org/battle.html?id=*
// @grant        none
// @licence      MIT
// ==/UserScript==

var hits=0;
var bonus=0;
var div=document.getElementsByClassName("foundation-style small-10 columns")[0];
var htm=div.innerHTML;

var page=window.location.href;
var link=page.split("//")[1];
var server=link.split(".")[0];
var id=link.split("=")[1];
var url='https://'+server+'.e-sim.org/apiFights.html?battleId='+id;

fetch(url)
  .then(res => res.json())
  .then((data) => {
    for(var i=0; i<data.length; i++){
    if(data[i].berserk==true) hits+=5;
        else hits++;
    }

     fetch('https://'+server+'.e-sim.org/index.html')
    .then(res2 => res2.text())
    .then((newdata) => {
        var parser = new DOMParser();
        var doc = parser.parseFromString(newdata, "text/html");
        var bonusdiv = doc.getElementsByClassName("promotionDescription")[0];
        if(bonusdiv!=undefined){
            var bonusText = bonusdiv.innerText;
            var isBonusDrop = bonusText.indexOf("more drops");
            var text2 = bonusText.split(' ')[1];
            var test=false;
            if(text2.indexOf('!')==-1) test=true;
            if(test==false){
                var procent = text2.split('!')[1];
                var number = Number(procent.split('%')[0]);
            }
            if(isBonusDrop>-1){
                bonus = number;
            }
           }

        var q6=Math.round(hits/100000*(1+bonus/100));
        var q5=Math.round(hits/30000*(1+bonus/100));
        var q4=Math.round(hits/10000*(1+bonus/100));
        var q3=Math.round(hits/3000*(1+bonus/100));
        var q2=Math.round(hits/1000*(1+bonus/100));
        var q1=Math.round(hits/300*(1+bonus/100));
        var specitem=Math.floor(hits/3000);
        var up=Math.floor(Math.sqrt(specitem));
        var reshuffle=specitem-up;

        htm+='<div class="foundation-radius fightContainer foundation-base-font mobileDrops" style="text-align: center!important; width: 98.2%!important; margin:0!important;">';
        htm+='<div class="foundation-style small-10 columns"><p class="fightHead">Expected battle drops:</p></div>';
        htm+='<div class="dropsImage help" title="No idea what you have to do to get it." style="background:url(//cdn.e-sim.org//img/equipmentIcons/q6-small.png) no-repeat;"><b>Q6</b></div>';
        htm+=`<div class="dropsLabel"><b>${q6}</b></div>`;
        htm+='<div class="dropsImage help" title="Awarded to battle heroes. The more BH you got in the battle, the higher chance you have to receive Q5 item." style="background:url(//cdn.e-sim.org//img/equipmentIcons/q5-small.png) no-repeat;"><b>Q5</b></div>';
        htm+=`<div class="dropsLabel"><b>${q5}</b></div>`;
        htm+='<div class="dropsImage help" title="Awarded to top3 soldiers. The more top3 rounds you have, the higher chance you have to receive Q4 item." style="background:url(//cdn.e-sim.org//img/equipmentIcons/q4-small.png) no-repeat;"><b>Q4</b></div>';
        htm+=`<div class="dropsLabel"><b>${q4}</b></div>`;
        htm+='<div class="dropsImage help" title="Awarded to top10 soldiers. The more top10 rounds you have, the higher chance you have to receive Q3 item." style="background:url(//cdn.e-sim.org//img/equipmentIcons/q3-small.png) no-repeat;"><b>Q3</b></div>';
        htm+=`<div class="dropsLabel"><b>${q3}</b></div>`;
        htm+='<div class="dropsImage help" title="Awarded to everyone. The more hits you do, the higher chance you have to receive Q2 item." style="background:url(//cdn.e-sim.org//img/equipmentIcons/q2-small.png) no-repeat;"><b>Q2</b></div>';
        htm+=`<div class="dropsLabel"><b>${q2}</b></div>`;
        htm+='<div class="dropsImage help" title="" style="background:url(//cdn.e-sim.org//img/equipmentIcons/q1-small.png) no-repeat;"><b>Q1</b></div>';
        htm+=`<div class="dropsLabel"><b>${q1}</b></div>`;
        htm+='<div class="dropsImage help" title="Equipment parameter upgrade" style="background:url(//cdn.e-sim.org//img/specialItems/si_eq_u.png) no-repeat;"><b></b></div>';
        htm+=`<div class="dropsLabel"><b>${up}</b></div>`;
        htm+='<div class="dropsImage help" title="Equipment parameter reshuffle" style="background:url(//cdn.e-sim.org//img/specialItems/si_eq_rs.png) no-repeat;"><b></b></div>';
        htm+=`<div class="dropsLabel"><b>${reshuffle}</b></div>`;
        div.innerHTML=htm;

    })


  });