// ==UserScript==
// @name            SokkerMonkey-SafeHolidays
// @namespace       http://www.mkvale.it/mk/sokker/
// @author          Mkcerusky
// @description     Version 0.1. - This script hides the results of plaied matches
// @include         http://online.sokker.org/glowna.php*
// @include         http://217.17.40.90/glowna.php*
// @include         http://online.sokker.org/matches.php*
// @include         http://217.17.40.90/matches.php*

var allLinks, thisLink, tables, newElement, newLink, bolds, team1, team2;
var pagina = window.location.pathname;

tables = document.getElementsByTagName('table');
if (tables) {
  for(i = 0; i<150; i++) {
    newElement = document.createElement('hr');
    tables[0].parentNode.insertBefore(newElement, tables[0].nextSibling);
  }
 }

if (tables) {
  newElement = document.createElement("div");    
  newElement.innerHTML = '<div><p>' +
    "<br><b>Note</b>: if you are viewing your main page the second link points to the most recent match." +
    "<br><br><i>Other scripts available at <a href='http://www.mkvale.it/mk/sokker'>Mkcerusky's sokker page</a>" +
    '</p></div>';
  tables[0].parentNode.insertBefore(newElement, tables[0].nextSibling);
  
 }


bolds = document.getElementsByTagName('b');

allLinks = document.evaluate(
    '//a[@href]',
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);
for (var i = 0; i < allLinks.snapshotLength; i++) {
  team1 = allLinks.snapshotItem(i-3);
  team2 = allLinks.snapshotItem(i-2);
  thisLink = allLinks.snapshotItem(i);
  if(thisLink.href.match(/comment.php\?matchID/i)) {
    var dummy = thisLink.href.split('ID=');
    var newHref = 'javascript:fullwin(' + dummy[1] + ')';  
    newLink = document.createElement("div"); 
    if(pagina == "/glowna.php") {
  	newLink.innerHTML = '<div><p><a href=' + newHref + '> Match ID = ' + dummy[1] + '</a> ' + thisLink.text + '</p></div>';
    }
    else
      newLink.innerHTML = '<div><p><a href=' + newHref + '> Match ID = ' + dummy[1] + '</a> ' + team1.text + ' - ' + team2.text + '</p></div>';
    tables[0].parentNode.insertBefore(newLink, tables[0].nextSibling);
  }
 }

if (tables) {
  newElement = document.createElement("div");    
  newElement.innerHTML = '<div><p>' +
    "<b>DO NOT SCROLL THIS PAGE</b> if you don't want to see in advance the results of your matches: they are reported after the orizontal lines.<br><br>"+
    "INFO: You are using the script <b><i>SokkerMonkey-SafeHolidays</i></b> by <a href='http://online.sokker.org/glowna.php?teamID=43778'>Mkcerusky</a>. Below you can find direct links to the live views of your matches listed in this page. The matches are listed from the most recent two matches to the oldest couples of matches. To prevent you to accidentally see the results of the matches in advance, don't scroll this page after the lines. Once you have finished using the script you can disable it from the Greasemonkey's 'Manage User Scripts' menù. Whenever you need it again you just have to enable it." +
    '<br><br><b>Your matches:</b>' +
    '</p></div>';
  tables[0].parentNode.insertBefore(newElement, tables[0].nextSibling);
  
 }


