Gebruiker:Valhallasw/watchlisttracker.js

Uit Wikipedia, de vrije encyclopedie

Opmerking: nadat u de wijzigingen hebt gepubliceerd is het wellicht nodig uw browsercache te legen.

  • Firefox / Safari: houd Shift ingedrukt terwijl u op Vernieuwen klikt of druk op Ctrl-F5 of Ctrl-R (⌘-Shift-R op een Mac)
  • Google Chrome: druk op Ctrl-Shift-R (⌘-Shift-R op een Mac)
  • Internet Explorer / Edge: houd Ctrl ingedrukt terwijl u op Vernieuwen klikt of druk op Ctrl-F5
  • Opera: druk op Ctrl-F5.
//<pre>
/*****************************************************************************************
 NL.WIKIPEDIA WATCHLIST TRACKER
 (C)2006 Valhallasw
 Licenced under GPL. Please add [[nl:Gebruiker:Valhallasw]] when you use it in other scripts.

 Usage: Put

 document.write('<script type="text/javascript" src="'
           + 'http://nl.wikipedia.org/w/index.php?title=Gebruiker:Valhallasw/watchlisttracker.js'
           + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

 in your monobook.js

 FOR USE ON OTHER WIKIPEDIA PROJECTS EDITING IS REQUIRED (hardcoded nl.wikipedia links etc)
*****************************************************************************************/

// Load dependencies
// cross-browser XML reader
document.write('<script type="text/javascript" src="'
        + 'http://nl.wikipedia.org/w/index.php?title=Gebruiker:Valhallasw/importxml.js'
        + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

// Cookie manipulate functions
document.write('<script type="text/javascript" src="'
        + 'http://nl.wikipedia.org/w/index.php?title=Gebruiker:Valhallasw/cookies.js'
        + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');



function mainWatchlistTracker() {
//haal datum op
var now = new Date();
var expiredate = new Date();
expiredate.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); // 1 jaar

if (document.location.toString().indexOf("&token=") == -1) {   //als er een token is mag niets gedaan worden

if ((document.location == "http://nl.wikipedia.org/wiki/Speciaal:Volglijst") || (document.location.toString().indexOf("http://nl.wikipedia.org/w/index.php?title=Speciaal:Volglijst") != -1)) {
	//clear boxkoekje
	deleteCookie("watchlistShowBox", "/");

	//(re)set last visit cookie
	setCookie("watchlistLastVisit", now, expiredate, "/");
} else {
	//haal koekjes op
	var lastVisit = getCookie("watchlistLastVisit");
	var lastCheck = getCookie("watchlistLastCheck");

	var showBox = getCookie("watchlistShowBox");
	doShowBox(showBox);

	if (!showBox) {
		// niet geset
		// check of er niet al minder dan een minuut geleden is gecheckt
		if (lastCheck) var lastCheckDate = Date.parse(lastCheck);
		if (lastVisit) { //alleen als lastVisit bestaat is de opzoekactie zinvol
			if ((!lastCheck) || (now - lastCheckDate) > 10) {  // THIS SETS THE MINIMUM TIME BETWEEN WATCHLIST CHECKS
				setCookie("watchlistLastCheck", now, expiredate, "/");
				var lastVisitDate = Date.parse(lastVisit);
				var watchlistURL = "http://nl.wikipedia.org/w/index.php?title=Speciaal:Volglijst&days="+((((now - lastVisitDate)/1000)/3600)/24).toString();
				importXML(watchlistURL,'processWatchlist');

			}

		} else { //(anders dumpen we die box er gewoon ;))
			setCookie("watchlistShowBox", 1, expiredate, "/");
			doShowBox(1);
		}
	}
}
}}

function doShowBox(show) {
	if (show) {
		var siteSub = document.getElementById("siteSub");
		var newStuff = document.createElement("table");
		newStuff.setAttribute("align","center");
		newStuff.setAttribute("class","usermessage");
		newStuff.setAttribute("width","100%");
		newStuff.innerHTML = "<tr><td>Er is een wijziging op uw <a href='http://nl.wikipedia.org/wiki/Speciaal:Watchlist'>volglijst</a>!</td></tr>"
		var parentDiv = siteSub.parentNode;
		parentDiv.insertBefore(newStuff, siteSub);
	}
}

function processWatchlist(xmlDoc) {
	var now = new Date();
	var expiredate = new Date();
	expiredate.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); // 1 jaar

	//var images = xmlDoc.document.getElementsByTagName("img");
      var images = xmlDoc.getElementsByTagName("img") // test, firefox fix, hopelijk werkt het in opera
	for(i=0;i<images.length;i++) {
		if (images[i].getAttribute("src") == "/skins-1.5/common/images/Arr_.png") {
			setCookie("watchlistShowBox", 1, expiredate, "/");
			doShowBox(1);
			break;
		}
	}
}

window.addEventListener("DOMContentLoaded", mainWatchlistTracker, false);

//</pre>