Utilisateur:Jereemy/monobook.js
Note : après avoir enregistré tes préférences, tu devras forcer son rechargement complet en ignorant le contenu actuel du cache de ton explorateur pour voir les changements : Mozilla / Firefox / Konqueror / Safari : maintiens la touche Majuscule (Shift) en cliquant le bouton Actualiser (Reload,) ou presse Maj-Ctrl-R (Maj-Cmd-R sur Apple Mac) ; Internet Explorer / Opera : maintiens la touche Ctrl en cliquant le bouton Actualiser ou presse Ctrl-F5.
// Warning! This gadget also use other projects. // Original version: // - QuickEditCounter script by [[:pl:User:ChP94]] // - Released under the [http://www.gnu.org/licenses/gpl.txt GNU Public License (GPL)] // Modified by: [[:pl:User:Beau]], [[:pl:User:Rzuwig]] // Importé et modifié par: [[fr:Utilisateur:Linedwell]] window.qecGadget = { version: 9, init: function() { if ( mw.config.get( 'wgNamespaceNumber' ) != 2 && mw.config.get( 'wgNamespaceNumber' ) != 3 ) { return; } if ( mw.util.getParamValue('printable') == 'yes' ) { return; } this.username = mw.config.get( 'wgTitle' ).replace(/\/.*$/, ''); if ( mw.config.get( 'wgTitle' ) != this.username ) { return; } var that = this; var request = { action: 'query', list: 'users', usprop: 'editcount|gender', format: 'json', ususers: this.username, requestid: new Date().getTime() }; jQuery.getJSON( mw.util.wikiScript( 'api' ), request, function(result) { jQuery(document).ready(function() { if (result) { that.showResults(result); } }); }); }, showResults: function(data) { data = data.query.users[0]; if (!data || data.name != this.username || data.invalid != null || data.editcount === undefined) return; var firstHeading; var headers = document.getElementsByTagName( 'h1' ); for ( var i = 0; i < headers.length; i++ ) { var header = headers[i]; if(header.className == "firstHeading" || header.id == "firstHeading" || header.className == "pagetitle") { firstHeading = header; break; } } if( !firstHeading ) { firstHeading = document.getElementById("section-0"); } if( !firstHeading ) { return; } var html = 'Cet utilisateur a effectué'; var lang = 'fr'; var wiki = 'wikimini'; var m; if (m = mw.config.get( 'wgServer' ).match(/^(?:http:)?\/\/(.+?).([^.]+).org$/)) { lang = m[1]; wiki = m[2]; } else if (m = mw.config.get( 'wgScriptPath' ).match(/\/(.+?)\/(.+?)\//)) { lang = m[2]; wiki = m[1]; } //html += ' <a href="//tools.wmflabs.org/xtools/pcount/index.php?name=' + encodeURIComponent(this.username) + '&wiki=' + encodeURIComponent(wiki) + '&lang=' + encodeURIComponent(lang) + '">' + format(data.editcount) + '</a> éditions.'; html += ' ' + format(data.editcount) + '</a> éditions.'; var div = document.createElement("div"); div.style.cssText = "font-size:0.5em;line-height:1em"; div.className = 'plainlinks'; div.innerHTML = html; if ( mw.config.get( 'skin' ) == 'modern' ) { div.style.marginLeft = "10px"; div.style.display = "inline-block"; } firstHeading.appendChild(div); } }; //retourne une String contenant le nombre donné mis en forme (avec espace séparant les milliers) - auteur: [[fr:User:Linedwell]] function format(nbr) { var nombre = String(parseInt(nbr)); //conversion de nbr en String var nombreF = ''; //la String contenant le nombre mis en forme var spc = 3 - nombre.length%3; //position du premier espace for (var i = 0; i < nombre.length; i++) { //a chaque fois qu'un bloc de 3 nombres est atteint (à l'exception du 1er) if (spc == 3) { nombreF += ' '; //ajout d'un espace spc = 0; } spc++; nombreF += nombre[i]; //recopie du nombre dans la String résultante } return(nombreF); } qecGadget.init();