daniel_bloodbeak / GI Match Ticker (Table section)

// ==UserScript==
// @name        GI Match Ticker (Table section)
// @namespace   https://grid-iron.org/
// @description Loads division data for match ticker for league/AFLC games
// @include     https://grid-iron.org/home/competitions
// @include     https://grid-iron.org/home/competitions*
// @include     https://grid-iron.org/home/aflc
// @version     1
// @license     MIT
// @author      daniel_bloodbeak
// @grant       none
// ==/UserScript==
window.setTimeout(function () {

  var gameHunter = 0;
  var aflc = 0;
  var setDivision;
  var leagueFinder = document.getElementById("page_header");
  var leagueHeader = leagueFinder.getElementsByTagName("div")[0].innerHTML;
  var compFinder, compHeader;
  var teamDetails = [];
  var pushArray = [];
  var weatherArr = [];

  var x = 2;

  var teamName, teamCountry;
  var teamFlag = 0;
  var teamWin = 0;
  var teamLoss = 0;

  for (var a = 0; a < 10; a++) {
    var getTeam = document.getElementsByClassName("row_cell")[x];
    var nameClean = getTeam.innerHTML.split(">");
    teamName = nameClean[1].slice(0, -3);
    if (nameClean[1].search(/font/i) !== -1) {
      teamName = nameClean[3].slice(0, -3);
    }
    if (nameClean[0].search(/<b/i) !== -1) {
      teamName = nameClean[2].slice(0, -3);
    }
    var getFlag = document.getElementsByClassName("row_cell")[x + 1];
    var flagClean = getFlag.innerHTML.split("png");
    teamFlag = flagClean[1].slice(1, -1);
    var countryClean = flagClean[2].split(" title");
    teamCountry = countryClean[0].slice(7, -1);
    var getWin = document.getElementsByClassName("row_cell")[x + 2];
    var getLoss = document.getElementsByClassName("row_cell")[x + 3];
    teamWin = getWin.innerHTML;
    teamLoss = getLoss.innerHTML;
    if (teamWin === "-") {
      teamWin = 0;
    }
    if (teamLoss === "-") {
      teamLoss = 0;
    }
    pushArray.push(teamName, teamFlag, teamCountry, teamWin, teamLoss);
    teamDetails.push(pushArray);
    pushArray = [];
    x += 13;
  }

  sessionStorage.setItem("leagueDetails", JSON.stringify(teamDetails));

  if (leagueHeader.match(/AFLC/i)) {
    setDivision = "AFLC";
  }
  else {
    compFinder = document.getElementById("select_div");
    compHeader = compFinder.getElementsByTagName("option")[0].innerHTML;
    if (leagueHeader.match(/Africa/i)) {
      leagueHeader = "Africa & Arab Peninsula";
    }
    if (leagueHeader.match(/Balkan/i)) {
      leagueHeader = "Balkan Region";
    }
    if (leagueHeader.match(/Atlant/i)) {
      leagueHeader = "Atlantic & Scandinavian Europe";
    }
    if (leagueHeader.match(/South /i)) {
      leagueHeader = "Central & South America";
    }
    setDivision = leagueHeader + " " + compHeader;
  }
  sessionStorage.setItem("leagueHeader", setDivision);

  var storeItem = ["match1", "match2", "match3", "match4", "match5", "match6", "match7", "match8"];
  for (var aa = 0; aa < 8; aa++) {
    sessionStorage.setItem(storeItem[aa], 0);
    sessionStorage.setItem("aflc", 0);
  }

  var gameNumber = 0;
  var pathArray = window.location.pathname.split('/');
  var leagueType = pathArray[2];
  if (leagueType !== "aflc") {
    gameHunter = 131;
    gameNumber = 5;
  }
  else {
    gameHunter = 109;
    gameNumber = 8;
    aflc = 1;
  }
  sessionStorage.setItem("aflc", aflc);

  for (var f = 0; f < gameNumber; f++) {
    if (aflc == 1 && f == 4) {
      gameHunter = 241;
    }
    var cellLocate = document.getElementsByClassName("row_cell")[gameHunter];
    var cellString = cellLocate.innerHTML;
    var strSplit = cellString.split('/');
    var strClean = strSplit[4].substr(0, 7);
    sessionStorage.setItem(storeItem[f], strClean);
    gameHunter += 3;
  }
}, 100);