kachrison / dotabuff

// ==UserScript==
// @name        dotabuff
// @namespace   db
// @include     http://www.dotabuff.com/matches/*
// @version     2
// @run-at      document-end
// @grant       none
// ==/UserScript==
try{
  var h=['','Abaddon','Alchemist','Ancient Apparition','Anti-Mage','Axe','Bane','Batrider','Beastmaster','Bloodseeker','Bounty Hunter','Brewmaster','Bristleback','Broodmother','Centaur Warrunner','Chaos Knight','Chen','Clinkz','Clockwerk','Crystal Maiden','Dark Seer','Dazzle','Death Prophet','Disruptor','Doom','Dragon Knight','Drow Ranger','Earthshaker','Earth Spirit','Elder Titan','Ember Spirit','Enchantress','Enigma','Faceless Void','Gyrocopter','Huskar','Invoker','Io','Jakiro','Juggernaut','Keeper of the Light','Kunkka','Legion Commander','Leshrac','Lich','Lifestealer','Lina','Lion','Lone Druid','Luna','Lycan','Magnus','Medusa','Meepo','Mirana','Morphling','Naga Siren',"Nature's Prophet",'Necrophos','Night Stalker','Nyx Assassin','Ogre Magi','Omniknight','Oracle','Outworld Devourer','Phantom Assassin','Phantom Lancer','Phoenix','Puck','Pudge','Pugna','Queen of Pain','Razor','Riki','Rubick','Sand King','Shadow Demon','Shadow Fiend','Shadow Shaman','Silencer','Skywrath Mage','Slardar','Slark','Sniper','Spectre','Spirit Breaker','Storm Spirit','Sven','Techies','Templar Assassin','Terrorblade','Tidehunter','Timbersaw','Tinker','Tiny','Treant Protector','Troll Warlord','Tusk','Undying','Ursa','Vengeful Spirit','Venomancer','Viper','Visage','Warlock','Weaver','Windranger','Winter Wyvern','Witch Doctor','Wraith King','Zeus'];
  var alph = ['q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m'];
  var picks = document.querySelectorAll('.picks-inline');
  var PICK=[['0','0','0','0','0'],['0','0','0','0','0']],BAN=[['0','0','0','0','0'],['0','0','0','0','0']];
  if(picks.length===0){
    picks = [document.querySelectorAll('.team-results .radiant .image-container-hero img'),document.querySelectorAll('.team-results .dire .image-container-hero img')];
    for(let l=0;l<2;l++){
        for(let k=0,kl=picks[l].length,r;k<kl;k++){
          r=h.indexOf(picks[l][k].getAttribute('alt')).toString();
          PICK[l][PICK[l].indexOf('0')]=r;
        }
     }
  }
  else{
    for(let l=0;l<2;l++){
      for(let k=0,kl=picks[l].children.length,p,r;k<kl;k++){
        p=picks[l].children[k];
        r=h.indexOf(p.querySelector('img').getAttribute('alt')).toString();
        if(p.classList[0]==='ban')BAN[l][BAN[l].indexOf('0')]=r;
        else if(p.classList[0]==='pick')PICK[l][PICK[l].indexOf('0')]=r;
      }
    }
  }
  var hash = '000000', nhash = '';
  for(let y = 0; y < 5; y++){
    for(let x = 0; x < 2; x++){
      hash += new Array(4 - PICK[x][y].length).join('0') + PICK[x][y];
      hash += new Array(4 - BAN[x][y].length).join('0') + BAN[x][y];
    }
  }

  hash += '000001';

  for(var i = 0, l = hash.length - 1, o = 0; i <= l; i++){
    if(hash[i] === '0' && ++o < 26 && i < l)continue;
    else{
      if(o > 1)nhash += alph[o - 1];
      else if(o === 1)nhash += '0';
      if(o < 26 && i <= l)nhash += hash[i];
      o = 0;
    }
  }
  hash = '#' + nhash;
  let div=document.createElement('A');
  div.style.position='fixed';
  div.style.top='0';
  div.style.left='0';
  div.href='http://outpicker.com/'+hash;
  div.style.backgroundColor='black';
  div.style.color='white';
  div.style.zIndex='100';
  div.innerHTML='OUTPICKER';
  div.setAttribute('target','_blank');
  document.body.appendChild(div);
}catch(e){alert(e);console.log(e)}