Utilisateur:Pmassot/lib.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.

 
function nouvelÉlément(nom) {
return document.createElement(nom);
}
function nouvelElément(nom) {
return nouvelÉlément(nom);
}
function nouveauTexte(texte) {
return document.createTextNode(texte);
}
function nouvelAttribut(nom) {
return document.createAttribute(nom);
}
 
function nouveauLien(href,label) {
var a = nouvelÉlément("a");
var h = nouvelAttribut("href");
h.value = href;
a.setAttributeNode(h);
a.title = label;
a.appendChild(nouveauTexte(label));
return a;
}
 
function nouveauLienEncapsulé(href,label) {
var li = nouvelÉlément("li");
li.appendChild(nouveauLien(href,label));
return li;
}
 
function $(id) {
if(document.getElementById)
return document.getElementById(id);
if(document.all)
return document.all[id];
return false;
}
 
function $$(name,obj) {
if (!obj) var obj = document;
return obj.getElementsByTagName(name);
}
 
function getElementsByTagNames(list,obj) { 
// http://www.quirksmode.org/dom/getElementsByTagNames.html
if (!obj) var obj = document;
var tagNames = list.split(',');
var resultArray = new Array();
for (var i=0;i<tagNames.length;i++) {
var tags = obj.getElementsByTagName(tagNames[i]);
for (var j=0;j<tags.length;j++) {
resultArray.push(tags[j]);
}
}
var testNode = resultArray[0];
if (!testNode) return [];
if (testNode.sourceIndex) {
resultArray.sort(function (a,b) {
return a.sourceIndex - b.sourceIndex;
});
}
else if (testNode.compareDocumentPosition) {
resultArray.sort(function (a,b) {
return 3 - (a.compareDocumentPosition(b) & 6);
});
}
return resultArray;
}
$$$ = getElementsByTagNames;
 
function sprintr(t) {
	s = "Array\n(\n";
	for(i in t) {
		s += "[" + i + "] =>" + t[i] + "\n";
	}
	return s;
}
 
function hideShow(o) {
if( o.initMouseEvent ) o = this.lastChild; // si le paramètre est un évènement clic 
if( o.style.display == "" || o.style.display == "block" ){
o.style.display = "none";
} else if( o.style.display == "none" ) {
o.style.display = "block";
}
}
 
/* Ajoute un lien devant les titres, ciblant l'ancre correspondante
* pour obtenir facilement l'URL de l'ancre.
* JavaScript 1.6 requis (p.ex. Firefox 1.5+).
*/
function ancres() {
var tagNames = ['h2','h3','h4','h5','h6'];
var classeLien = "lien-ancre-hn";
var texteLien = "§ ";
 
for each(var tag in tagNames) {
var headings = $$( tag, $("content") );
//var headings = getElementsByTagNames(tagNames.join(','),$("content"));
for each(var h in headings) {                   
if(
!(h &&
h.previousSibling &&
h.previousSibling.previousSibling &&
h.previousSibling.previousSibling.lastChild)
) continue;   
 
var id = h.previousSibling.previousSibling.lastChild.id;
//            \n    <p>        <a>
var spans = $$( "span",h );
for each( var span in spans ) {
if ( span.className != "mw-headline" ) continue;
var a = nouvelÉlément("a");
a.href = "#" + id;
a.title = a.href;
a.className = classeLien;
a.appendChild( nouveauTexte(texteLien) );
span.insertBefore(a,span.firstChild);
}
}
}
}
 
function tex(){
var images = $$("img");
for each(var i in images) {
if( !i.className || i.className != "tex" ) continue;
i.title = i.alt;
}
}
 
function liensRouges() {
if ( document.URL.indexOf('Whatlinkshere/') >= 0 ) return;
var A = $$("a");
for each(a in A) {
if( !a.className || a.className != "new" ) continue;
a.href = "/wiki/Special:Whatlinkshere/" + a.title;
}
}
 
function nsSearch() {
var form = $("searchform");
var div = form.firstChild;
while (div.firstChild) {
	div.removeChild(div.firstChild);
}
 
exec = nouvelÉlément( "button" );
exec.className = "searchButton";
exec.onclick = function() {
try{
champ = $("searchInput").value.replace(/(\d*)\^(\d*)/g,"Math.pow($1,$2)");
alert( eval(champ) ) ;
} catch(e) {
alert( "Expression mal formée !" );
}
return false;
}
exec.appendChild( nouvelÉlément("img") );
exec.lastChild.src = "http://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Gtk-execute.svg/60px-Gtk-execute.svg.png";
 
	var input = nouvelÉlément("input");
	input.type = "text";
	input.id = "searchInput";
	input.name = "search";
 
searchGoButton = nouvelÉlément("button");
searchGoButton.className = "searchButton";
searchGoButton.id = "searchGoButton";
searchGoButton.appendChild(nouvelÉlément("img"));
searchGoButton.lastChild.src = "http://upload.wikimedia.org/wikipedia/commons/thumb/f/f1/Exquisite-kfind.png/60px-Exquisite-kfind.png";
 
mw_searchButton = nouvelÉlément("button");
mw_searchButton.className = "searchButton";
mw_searchButton.id = "mw-searchButton";
mw_searchButton.onclick = function(){
	$("searchform").target = "search";
	$("searchform").submit();
	$("searchform").target = "";
	return false;
}
mw_searchButton.appendChild(nouvelÉlément("img"));
mw_searchButton.lastChild.src = "http://upload.wikimedia.org/wikipedia/commons/thumb/6/6a/Gtk-copy.svg/60px-Gtk-copy.svg.png";
 
div.appendChild(input);
div.appendChild(searchGoButton);
div.appendChild(mw_searchButton);
div.appendChild(exec);
}
 
function plieBoîtes() {
var boxes = ["p-navigation", "p-Contribuer", "p-tb", "p-search", "p-lang"];
for each(box in boxes) {
if( !$(box) ) continue;
var h = $$("h5",$(box))[0];
 
h.onclick = function(){
var pBody = $$("div",this.parentNode)[0];
hideShow(pBody);
}
}
}
 
function déplaceBoîtes() {
var boxes = ["p-navigation", "p-Contribuer"];
for each(box in boxes) {
var boîte = $(box);
boîte.parentNode.appendChild(boîte);
}
}
 
function contributions() { //ajoute un onglet ciblant les contributions d'un utilisateur
if ( document.title.indexOf('Utilisateur:') < 0 ) return;
var reg = new RegExp("Utilisateur:([^/]*)","gi");
var nom = reg.exec( $$("H1")[0].firstChild.nodeValue )[1];
var ul = $$( "ul", $("p-cactions") )[0];
var li = nouveauLienEncapsulé("/wiki/Special:Contributions/"+nom,"Contributions");
ul.appendChild(li); ;          
}
 
// Onglet Editcount
// Auteur : Educa33e /Suite à demande Fred.th? le 26 mars 2006, sur le bistro.
// Cette fonction ajoute un onglet "editcount" à partir de la page special:Contributions 
// d'un utilisateur, afin d'accèder directement au lien (site externe) des statistiques 
// d'édition de ce contributeur. 
//
//(refonte en DOM par Flo)
function addEditCountButton() {
if ( document.title.indexOf('Contributions de cet utilisateur') < 0 ) return;
var name = $$( "a",$("contentSub") )[0].innerHTML;
var ul = $$( "ul", $("p-cactions") )[0];
var li = nouveauLienEncapsulé(
"http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?user="+escape(name)+"&dbname=frwiki_p",
"Editcount");
ul.appendChild(li); ;          
}
 
function installWikEd() {
	var wikEd = document.createElement("script");
	wikEd.type = "text/javascript";
	wikEd.src="http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js" + "&action=raw&ctype=text/javascript&dontcountme=s";
	$$("head")[0].appendChild(wikEd);
}
 
function nouveauxOutilsPerso() {
var ul = $$( "ul", $("p-personal") );
ul[0].appendChild( nouveauLienEncapsulé("http://commons.wikimedia.org/wiki/Special:Watchlist","Liste de suivi Commons"));
}
 
function boîteàOutils() {
var UL = $$( "ul", $("p-tb") )[0];
UL.insertBefore( $("n-help"), $("t-upload") );
 
var ul = nouvelÉlément("UL");
ul.style.display = "none";
ul.appendChild( nouveauLienEncapsulé("/wiki/Aide:Formules_TeX","Formules TeX") );
ul.appendChild( nouveauLienEncapsulé("/wiki/Aide:Liste_de_caractères_spéciaux","Caractères spéciaux") );
ul.appendChild( nouveauLienEncapsulé("/wiki/Wikipédia:Conventions_typographiques","Conventions typo") );
ul.appendChild( nouveauLienEncapsulé("/wiki/Aide:Liste_des_modèles_spéciaux","Modèles spéciaux") );
ul.appendChild( $("t-upload") );
$("n-help").appendChild( ul );
$("n-help").className = "menuDeroulant";
$("n-help").onclick =hideShow;//function(){ hideShow(this.lastChild) };
 
ul = nouvelÉlément("UL");
ul.style.display = "none";
ul.appendChild( $("n-randompage") );
ul.appendChild( nouveauLienEncapsulé("/wiki/Special:Search","Recherche") );
ul.appendChild( nouveauLienEncapsulé("/wiki/Special:ExpandTemplates","Expansion des modèles") );
ul.appendChild( nouveauLienEncapsulé("/wiki/Special:Contributions","Contributions") );
if($("t-recentchangeslinked")) ul.appendChild( $("t-recentchangeslinked") );
$("t-specialpages").appendChild( ul );
$("t-specialpages").className = "menuDeroulant";
$("t-specialpages").onclick = hideShow; 
}