User:Jet forever/global.js

$( document ).ready(function {       if (mw.config.get("wgCanonicalSpecialPageName") === "Chat") {            var pseudos = [],                surnoms = [];            function getNicknames {                var tornar = "";                $.ajaxSetup({ async: false });               $.getJSON("/api.php?action=query&format=json&prop=revisions&titles=User:" + encodeURIComponent(mw.config.get("wgUserName").replace(/ /g,"_")) + "/surnoms&rvprop=content&cb=" + new Date.getTime, function(data) { var pageData = data.query.pages; for (var pageid in pageData) { if(pageid === "-1") { tornar = 0; } else { tornar = pageData[pageid].revisions[0]["*"]; }                   }                });                return tornar;            }            function actualiserSurnoms {                if(getNicknames !== 0) {                    var contengut = getNicknames,                        splitted = contengut.split('\n');                    pseudos = [];                    surnoms = [];                    for(var i in contengut.split('\n')) {                        if(splitted[i] != "") {                            surnoms.push(splitted[i].split("=>")[1]);                            pseudos.push(splitted[i].split("=>")[0]);                        }                    }                    console.log(surnoms);                    console.log(pseudos);                }            }            actualiserSurnoms;            function remplacer {                $( '.Chat .username' ).each(function { //alert($(this).text + " : " + pseudos.indexOf($(this).text) != -1); if(pseudos.indexOf($(this).text) != -1) { $(this).text(surnoms[pseudos.indexOf($(this).text)]); }               });            }            setInterval(function { remplacer; }, 2000);           function publier(pseudo, surnom) {                $.ajax({ url: mw.util.wikiScript( 'api' ), data: { format: 'json', action: 'edit', section: 'new', title: 'User:' + encodeURIComponent(mw.config.get("wgUserName").replace(/ /g,"_")) + '/surnoms', text: pseudo + '=>' + surnom, token: mw.user.tokens.get("editToken") },                   dataType: 'json', type: 'POST', success: function(data) { if(data && data.edit && data.edit.result == 'Success') { actualiserSurnoms; } else if ( data && data.error ) { alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info ); } else { alert( 'Error: Unknown result from API.' ); }                   },                    error: function( xhr ) { alert( 'Error: Request failed.' ); }               });            }            $('#WikiChatList li').on('click', function { $('.UserStatsMenu').on('DOMNodeInserted', function {                    if (!$('.surnommer-custom').length) {                        var boutonSurnommer = $('.kick').clone.addClass('surnommer-custom').removeClass('kick');                        $(this).children('.actions').children('.regular-actions').append(boutonSurnommer);                        $( '.surnommer-custom .label' ).text('Surnommer');                        $('.surnommer-custom').on('click', function { var pseudo = $(this).parents.eq(2).children('.info').children('ul').children('.username').text, surnom = prompt('Comment voulez-vous surnommer ' + pseudo + ' ?'); publier(pseudo, surnom); });                   }                });            });        }    }); }) (this.jQuery, this.mediaWiki); importArticles( { type: 'script', articles: [ 'u:dev:MediaWiki:ChatOptions/code.js', 'u:dev:NewMessageCount.js', 'u:dev:MediaWiki:WorkingMoreUsersCount.js' ] } );
 * (function($, mw) {