7878asas / Empornium Random Button

// ==UserScript==
// @name        Empornium Random Button
// @namespace   7878asas
// @description Add a random button to Empornium. Discover new torrent. For best use, goto torrents page then click the random button.
// @include     http://www.empornium.me/*
// @include     http://www.empornium.sx/*
// @version     0.1.1
// @grant       none
// ==/UserScript==

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  return 0;
}
var maxid; //Ideal value: ID of the latest torrent released on Empornium
var minid=500; //This value is 500 because a lot of torrent are missing in the range (0-499). If you don't mind a slightly higher error ratio, make this 62
if(document.getElementsByClassName("torrent").item(0))
  maxid = document.getElementsByClassName("torrent").item(0).getElementsByTagName("a").item(2).href.split('=')[1];
else if(getQueryVariable("maxid"))
  maxid=getQueryVariable("maxid");
else
  maxid=245352;
nextid = Math.floor(Math.random()*(maxid-minid)+minid);
var newLinkLocation=window.location.protocol+"//"+window.location.host+"/torrents.php?id="+nextid+"&maxid="+maxid;
var newLink = "<li class='brackets'><a href='"+newLinkLocation+"' class='pager'>Random</a></li>";
document.getElementById("userinfo_username").insertAdjacentHTML("afterbegin",newLink);