User:AlexDj94/Wikipedia More Alive.js

/* Copyright (C) 2011 Alessio Dionisi 

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to

Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor Boston, MA  02110-1301, USA.

var PageTitle = mw.config.get("wgPageName"); var WikiURL = document.location.href.split("/"); var currDate = null;

function RealTimeWiki { var d = new Date; currDate = new Date(d.getUTCFullYear, d.getUTCMonth + 1, d.getUTCDate, d.getUTCHours, d.getUTCMinutes, d.getUTCSeconds); //UpdatePage; setTimeout("CheckLastRevision", 3000); }

function CheckLastRevision { if (window.XMLHttpRequest) // IE7+, Firefox, Chrome, Opera, Safari {     xmlhttp = new XMLHttpRequest; }  else // IE6, IE5 {     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }  try { var urlText = ""; for (i = 3; i < WikiURL.length; i++) { if (i != WikiURL.length) { urlText += "../"; }     }      xmlhttp.open("GET", urlText + "w/api.php?action=query&prop=revisions&titles=" + PageTitle + "&format=xml", false); xmlhttp.send(null); }  catch(e) { alert("== Javascript Error ==\n" + e.toString); }  xmlDoc = xmlhttp.responseXML; var lastTimeStamp = xmlDoc.getElementsByTagName("rev")[0].attributes.getNamedItem("timestamp").nodeValue; var lastHead1 = lastTimeStamp.split("T")[0]; //var lastYear = lastHead1.split["-"][0]; var lastYear = lastHead1.substring(0, 4); //var lastMonth = lastHead1.split["-"][1]; var lastMonth = lastHead1.substring(5, 7); //var lastDay = lastHead1.split["-"][2]; var lastDay = lastHead1.substring(8, 10); //alert("debug: " + lastYear + " " + lastMonth + " " + lastDay);

var lastHead2 = lastTimeStamp.split("T")[1]; //var lastHour = lastHead2.split[":"][0]; var lastHour = lastHead2.substring(0, 2); //var lastMinute = lastHead2.split[":"][1]; var lastMinute = lastHead2.substring(3, 5); //var lastSecond = lastHead2.split[":"][2]; var lastSecond = lastHead2.substring(6, 8); //alert("debug: " + lastHour + " " + lastMinute + " " + lastSecond);

var lastDate = new Date(lastYear, lastMonth, lastDay, lastHour, lastMinute, lastSecond);

//alert("Pagina: " + xmlDoc.getElementsByTagName("page")[0].attributes.getNamedItem("title").nodeValue +   //   "\nUltima modifica: " + lastTimeStamp);

if (lastDate > currDate) { var d = new Date; currDate = new Date(d.getUTCFullYear, d.getUTCMonth + 1, d.getUTCDate, d.getUTCHours, d.getUTCMinutes, d.getUTCSeconds); //alert("pagina modificata alle " + lastHour + ":" + lastMinute + ":" + lastSecond); UpdatePage; }  setTimeout("CheckLastRevision", 5000); }

var hex = 255; function FadeText { var textDiv = document.getElementsByClassName("mw-content-ltr")[0]; if (hex > 0) { //If color is not black yet hex -= 11; // increase color darkness textDiv.style.color = "rgb(" + hex + "," + hex + "," + hex + ")"; setTimeout("FadeText", 20); }  else { hex = 255; //reset hex value } }

function UpdatePage { if (window.XMLHttpRequest) // IE7+, Firefox, Chrome, Opera, Safari {     xmlhttp = new XMLHttpRequest; }  else // IE6, IE5 {     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }  try { var urlText = ""; for (i = 3; i < WikiURL.length; i++) { if (i != WikiURL.length) { urlText += "../"; }     }      xmlhttp.open("GET", urlText + "w/index.php?action=render&title=" + PageTitle, false); xmlhttp.send(null); }  catch(e) { alert("== Javascript Error ==\n" + e.toString); }  var text = xmlhttp.responseText; //var text = xmlDoc.getElementsByTagName("text")[0].nodeValue;

var textDiv = document.getElementsByClassName("mw-content-ltr")[0]; FadeText; textDiv.innerHTML = text; /*var divs = document.getElementById("bodyContent").getElementsByTagName("div"); //alert(divs.lenght); for (i = 0; i < divs.lenght; i++) { alert(divs[i].className); if (divs[i].className == "mw-content-ltr") { alert("modifica"); //divs[i].innerHTML = "Testo Nuovo"; }  }*/ }

$(document).ready(RealTimeWiki); //jQuery(RealTimeWiki);