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;

var lastYear; var lastMonth; var lastDay; var lastHour; var lastMinute; var lastSecond;

var lastUser; var lastComment;

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

// Social buttons document.getElementById("firstHeading").innerHTML += "" + " "; }

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;

lastUser = xmlDoc.getElementsByTagName("rev")[0].attributes.getNamedItem("user").nodeValue; lastComment = xmlDoc.getElementsByTagName("rev")[0].attributes.getNamedItem("comment").nodeValue; var lastHead1 = lastTimeStamp.split("T")[0]; lastYear = lastHead1.substring(0, 4); lastMonth = lastHead1.substring(5, 7); lastDay = lastHead1.substring(8, 10);

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

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); UpdatePage; }  setTimeout("CheckLastRevision", 5000); // 5000 <- millisecondi }

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 + ")"; document.getElementById("footer-info-lastmod").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; UpdateLastEditText; }

function UpdateLastEditText { document.getElementById("footer-info-lastmod").innerHTML = "This page was last modified on " + lastDay + "/" + lastMonth + "/" + lastYear + ", at " + lastHour + ":" + lastMinute + " by " + lastUser + ""; if (lastComment != "") { document.getElementById("footer-info-lastmod").innerHTML += " &laquo;" + lastComment + "&raquo;"; }  document.getElementById("footer-info-lastmod").innerHTML += " "; }

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