andrizz / TM Leagues navigator and youth pulls infos

// ==UserScript==
// @name             TM Leagues navigator and youth pulls infos
// @version          1.0
// @description      Easily navigates between leagues
// @author           Andrizz aka Banana aka Jimmy il Fenomeno
// @downloadURL      https://openuserjs.org/install/andrizz/TM_Leagues_navigator_and_youth_pulls_infos.user.js
// @include          https://trophymanager.com/league/*
// @license          MIT
// ==/UserScript==

var pathn = new String(location.pathname.match(/\d+\/\d+/));
if (pathn == "null") {
    pathn = $(".box_sub_header").find("span:first").attr("onclick");
    var serie = parseInt(pathn.match(/\d+/g)[0]);
    var girone = parseInt(pathn.match(/\d+/g)[1]);
    var nazione = pathn.match(/(?<=')\w{2}(?=')/);
} else {
    serie = parseInt(pathn.split(/\//)[0],10);
    girone = parseInt(pathn.split(/\//)[1],10);
    nazione = new String(location.pathname.match(/(?<=\/)\w{2}(?=\/)/));
}
if (serie == 5) var max = 256;
if (serie == 4) max = 64;
if (serie == 3) max = 16;
if (serie == 2) max = 4;
if (serie == 1) max = 1;
var nextG = girone+1;
if (nextG > max) { nextG = 1; var nextS = serie+1; } else { nextS = serie; }
if (nextS > 5) { nextS = 5; }
var linkNext = "https://trophymanager.com/league/"+nazione+"/"+nextS+"/"+nextG+"/#pa";
var prevG = girone-1;
if (prevG < 1) { prevG = max/4; var prevS = serie-1; } else { prevS = serie; }
if (prevS < 1) { prevS = 1; }
var linkPrev = "https://trophymanager.com/league/"+nazione+"/"+prevS+"/"+prevG+"/#pa";
if (serie != 1) var aPrev = "<a href='"+linkPrev+"'><img src='https://trophymanager.com/pics/cf_mini_arrow_left.png' style='height:10px; margin-right:2px;'/></a>";
var aNext = "<a href='"+linkNext+"'><img src='https://trophymanager.com/pics/cf_mini_arrow_right.png' style='height:10px; margin-left:2px;'/></a>";
$("span.faux_link.normal:eq(1)").before(aPrev);
$("span.faux_link.normal:eq(1)").after(aNext);