Utilisateur:Dreoven/monobook.js

Un article de Wikipédia, l'encyclopédie libre.

Note : Après avoir publié la page, vous devrez forcer son rechargement pour voir les changements : Mozilla / Konqueror / Firefox : Shift-Ctrl-R, Internet Explorer / Opera : Ctrl-F5, Safari : Cmd-R.

loadJs('User:EDUCA33E/LiveRC.js');
 
 
// Fusion display of Wikipedia user contributions history
// Copyright 2006, Marc Mongenet
//
// 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.
//
// See http://www.gnu.org/licenses/gpl.html
 
// TODO: Special:Log
 
var fus = new Object(); // fus is used as namespace.
fus.main_contributor = undefined; // main contributor name
fus.contributors_list = new Object(); // XHTML list of contributors
fus.contribs_limit = 0; // 0 means default value
fus.count = 0; // number of fusionned contribs
fus.colors = [ "", "#FFB", "#FBF", "#BFF", "#DDF", "#DFD", "#FDD",
                   "#EEA", "#EAE", "#AEE", "#CCE", "#CEC", "#ECC",
                   "#DD9", "#D9D", "#9DD", "#BBD", "#BDB", "#DBB" ];
 
fus.contributors_list.init = function() {
	this.elm = document.createElement("ol");
}
 
fus.contributors_list.add = function(contributor) {
	// UI components
	var li = document.createElement("li");
	li.fus = new Object();
	li.fus.contributor = contributor;
	li.style.backgroundColor = fus.colors[fus.count];
	li.appendChild(document.createTextNode(contributor));
	var a = document.createElement("a");
	a.href = "http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=frwiki_p&user=" + contributor;
	a.appendChild(document.createTextNode(" editcount"));
	li.appendChild(a);
	this.elm.appendChild(li);
}
 
fus.monthNameToNum = function(m) {
	if (m == "janvier") return 0;
	if (m == "février") return 1;
	if (m == "mars") return 2;
	if (m == "avril") return 3;
	if (m == "mai") return 4;
	if (m == "juin") return 5;
	if (m == "juillet") return 6;
	if (m == "août") return 7;
	if (m == "septembre") return 8;
	if (m == "octobre") return 9;
	if (m == "novembre") return 10;
	if (m == "décembre") return 11;
	return 12;
}
 
// Return Date of contribution listed in this li element.
fus.contribTimeRegex = /(\d+)\s+(\S+)\s+(\d{4})\D+(\d+)\D+(\d{2})/;
fus.parseContribTime = function(li) {
	var datetime = li.firstChild.nodeValue.match(fus.contribTimeRegex);
	datetime[2] = fus.monthNameToNum(datetime[2]);
	return new Date(parseInt(datetime[3]),
		            datetime[2],
	                parseInt(datetime[1]),
	                parseInt(datetime[4], 10),
	                parseInt(datetime[5], 10));
}
 
fus.fuse = function(ul1, ul2, contributor, color) {
	contributor = " -- " + contributor;
	var li1 = ul1.firstChild;
	for (var li22 = ul2.firstChild; li22; li22 = li22.nextSibling) {
		if (li22.nodeType == 1) {
			var li2 = li22.cloneNode(true);
			li2.appendChild(document.createTextNode(contributor));
			li2.style.backgroundColor = color;
			var time2 = fus.parseContribTime(li2).getTime();
 
			while (li1) {
				if (li1.nodeType == 1) {
					var time1 = fus.parseContribTime(li1).getTime();
					if (time1 <= time2) {
						if (time1 == time2) {
							li1.style.borderLeftWidth = li2.style.borderLeftWidth = "0.25em";
							li1.style.borderLeftStyle = li2.style.borderLeftStyle = "solid";
							li1.style.borderLeftColor = li2.style.borderLeftColor = "red";
						}
						break;
					}
				}
				li1 = li1.nextSibling;
			}
			ul1.insertBefore(li2, li1);
		}
	}
}
 
fus.getElementById = function(elm, id) {
	var res = null;
	if (elm.id == id) res = elm;
	for (var child = elm.firstChild; !res && child; child = child.nextSibling)
		if (child.nodeType == 1)
			res = fus.getElementById(child, id);
	return res;
}
 
fus.onFusionWith = function(contributor) {
	++fus.count;
	fus.contributors_list.add(contributor);
 
	// Load fusionned page with synchronous XMLHttpRequest
	var http_request;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType)
			http_request.overrideMimeType('text/xml');
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	http_request.open('GET', "/w/index.php?title=Special:Contributions&target="+contributor+"&limit="+fus.contribs_limit, false);
	http_request.send(null);
 
	// Get both contributions histories
	var ul1 = document.getElementById("bodyContent");
	ul1 = ul1.getElementsByTagName("ul")[0];
 
	var ul2 = http_request.responseXML;
	if (!ul2.getElementById) { // MSIE
		ul2 = document.createElement("div");
		ul2.innerHTML = http_request.responseText;
		ul2 = fus.getElementById(ul2, "bodyContent");
	} else {
		ul2 = ul2.getElementById("bodyContent");
	}
	ul2 = ul2.getElementsByTagName("ul")[0];
 
	// Fusion
	fus.fuse(ul1, ul2, contributor, fus.colors[fus.count]);
}
 
fus.parseContribUrlTarget = function(url) {
	var target = url.match(/&target=([^&]+)/);
	if (!target)
		target = url.match(/Special:Contributions\/(\S+)/);
	return target[1];
}
 
fus.parseContribUrlLimit = function(url) {
	var limit = url.match(/&limit=(\d+)/);
	if (limit)
		return parseInt(limit[1]);
	return 0;
}
 
fus.onContribPage = function(url) {
	fus.main_contributor = fus.parseContribUrlTarget(url);
	fus.contribs_limit = fus.parseContribUrlLimit(url);
 
	// UI components
	fus.contributors_list.init();
	fus.contributors_list.add(fus.main_contributor);
 
	var input = document.createElement("input");
	input.type = "text";
 
	var submit = document.createElement("input");
	submit.type = "submit";
 
	var form = document.createElement("form");
	form.onsubmit = function() {
		fus.onFusionWith(input.value);
		return false;
	}
 
	// UI components layout
	submit.value = "Fusionner";
	var fusion = document.createTextNode("Fusionner avec les contributions de ");
	form.appendChild(fusion);
	form.appendChild(input);
	form.appendChild(submit);
	var bodyContent = document.getElementById("bodyContent");
	bodyContent.insertBefore(form, bodyContent.firstChild);
	bodyContent.insertBefore(fus.contributors_list.elm, bodyContent.firstChild);
}
 
fus.testForContribPage = function() {
	var url = window.location.href;
	if (url.match(/\/Special:Contributions\/|title=Special:Contributions/)) {
		try {
			fus.onContribPage(url);
		} catch (e) { /* Something went wrong. */ }
	}
}
 
if (window.addEventListener) {
	window.addEventListener("load", fus.testForContribPage, false);
}
else if (window.attachEvent) {
	window.attachEvent("onload", fus.testForContribPage);
}
 
 
// Parental content filter for Wikipedia
// Copyright 2006, Marc Mongenet
//
// 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.
//
// See http://www.gnu.org/licenses/gpl.html
 
/*
 * How it works:
 *  - For all divs with a "contentFilter" class:
 *   - If contentFilter cookie is on, hide content and display button to turn off filtering;
 *   - else show content and display button to turn on filtering
 *  - It provide a function to be called by the on/off filter button.
 */
 
var cflt = new Object(); // cflt is used as namespace.
 
cflt.nextYearGMT = function() {
	var nextYear = new Date();
	nextYear.setFullYear(nextYear.getFullYear() + 1);
	return nextYear.toGMTString();
}
 
cflt.getParentalCheck = function() {
	// If password present, ask for it.
	var start;
	if (document.cookie && (start = document.cookie.indexOf("contentFilterPassword=")) != -1) {
		start += 22;
		var end = document.cookie.indexOf(";", start);
		if (end == -1) end = document.cookie.length;
		if (start != end) {
			var cookie_pass = document.cookie.substring(start, end);
			for (var retry = 0; retry < 3; ++retry) {
				var user_pass = window.prompt("Entrez le mot de passe");
				if (user_pass == cookie_pass) {
					var is_suppr = !window.confirm("Conserver le mot de passe ?");
					if (is_suppr) {
						document.cookie = "contentFilterPassword=; path=/; expire=Fri, 02-Jan-1970 00:00:00 GMT";
						return "NO CONTROL";
					}
					return "PASSED";
				}
			}
			return "FAILED";
		}
	}
 
	// Propose to set a password
	var is_pass = window.confirm("Activer le contrôle parental par mot de passe ?");
	if (is_pass) {
		var pass = window.prompt("Entrez un nouveau mot de passe");
		document.cookie = "contentFilterPassword=" + pass + "; path=/; expire=" + cflt.nextYearGMT();
		return "SET";  // Do not display filtered content after setting password
	}
	return "NO CONTROL";
}
 
cflt.setFilter = function(on) {
	if (!on) {
		var check = cflt.getParentalCheck();
		if (check == "NO CONTROL") {
			document.cookie = "contentFilter=off; path=/; expires=" + cflt.nextYearGMT();
			cflt.lookForFilteredContent(false);
		}
		if (check == "PASSED") {
			cflt.lookForFilteredContent(false);
		}
	}
	else {
		document.cookie = "contentFilter=0; path=/; expire=Fri, 02-Jan-1970 00:00:00 GMT";
		cflt.lookForFilteredContent(true);
	}
}
 
cflt.filterContent = function(div, is_on) {
	// Put content filtering UI if not already there.
	if (!div.contentFilteredUI) {
		div.contentFilteredUI = true;
 
		var on_button = document.createElement("button");
		on_button.appendChild(document.createTextNode("Montrer les contenus sensibles"));
		on_button.onclick = function() { cflt.setFilter(false); }
		div.insertBefore(on_button, div.firstChild);
 
		var off_button = document.createElement("button");
		off_button.appendChild(document.createTextNode("Cacher les contenus sensibles"));
		off_button.onclick = function() { cflt.setFilter(true); }
		div.insertBefore(off_button, div.firstChild);
	}
 
	// Show/hide UI depending on filter state.
	var subdivs = div.getElementsByTagName("div");
	subdivs[0].style.display = is_on ? "block" : "none";  // content box title
	subdivs[1].style.display = is_on ? "none" : "block";  // filtered content
	var buttons = div.getElementsByTagName("button");
	buttons[0].style.display = is_on ? "none" : "inline"; // hide button
	buttons[1].style.display = is_on ? "inline" : "none"; // show button
}
 
cflt.lookForFilteredContent = function(is_on) {
	// Call cflt.filterContent() on all <div class="contentFilter">
	var bodyContent = document.getElementById("bodyContent");
	var divs = bodyContent.getElementsByTagName("div");
	for (var d = 0; d < divs.length; ++d) {
		if (divs[d].className == "contentFilter") {
			cflt.filterContent(divs[d], is_on);
		}
	}
}
 
cflt.handleFilteredContent = function() {
	try {
		var is_on = true; // filter on by default
		if (document.cookie) {
			is_on = document.cookie.indexOf("contentFilter=off") == -1;
		}
		cflt.lookForFilteredContent(is_on);
	} catch (e) { /* Something went wrong. */ }
}
 
// We set here the cflt class on the html element so that filtering
// CSS rules are applied before the content is displayed but only
// if JavaScript is active. This way, the content is still accessible
// without JavaScript but does not appear in a flash before the
// script hides it.
try {
	cflt.html = document.getElementsByTagName("html")[0];
	cflt.html.className = "cflt " + cflt.html.className;
} catch (e) { /* Something went wrong. */ }
 
// Register functions
if (window.addEventListener) {
	window.addEventListener("load", cflt.handleFilteredContent, false);
}
else if (window.attachEvent) {
	window.attachEvent("onload", cflt.handleFilteredContent);
}
 
function Bistro() {
	var a = document.getElementById("p-navigation");
	if (a) {
		a = a.getElementsByTagName("ul");
		if(a.length > 0) {
			a[0].innerHTML = a[0].innerHTML + '<li><a id="n-bistro" title="Wikipédia:Le Bistro" href="/w/index.php?title=Wikip%C3%A9dia:Le_Bistro&action=purge">Bistro</a></li>';
		}
	}
}
addLoadEvent(Bistro);