MediaWiki:FindAndReplace/code.js

$(function {   'use strict';    importArticle({ type: "style", article: "u:dev:FindAndReplace/code.css" });   var lng = {        // English        en: {            far: 'Find and replace',            findthis: 'Find this:',            replacewith: 'Replace with:',            linebreak: 'Append line break',            globalm: 'Global matching.',            casesensitive: 'Case sensitive.',            undoedits: 'Undo edits',            undoinfo: 'All edits, not only replaces',            collapse: 'Collapse',            expend: 'Expend',            lbwarning: 'Warning: pressing Enter key\nwill publish your edits'        },        // Français        fr: {            far: 'Trouver et remplacer',            findthis: 'Trouver ceci :',            replacewith: 'Et le remplacer avec :',            linebreak: 'Ajouter un retour à la ligne',            globalm: 'Recherche globale.',            casesensitive: 'Sensible à la casse',            undoedits: 'Annuler les modifications',            undoinfo: 'Toutes, pas seulement les remplacements', collapse: 'Masquer', expend: 'Afficher', lbwarning: 'Attention : appuyer sur la\ntouche Entrée entrainera une\npublication des modifications' },       // Occitan oc: { far: 'Trobar e remplaçar', findthis: 'Trovar aquò', replacewith: 'E lo remplaçar amb :', linebreak: 'Apondre un retorn a la ligna', globalm: 'Recèrca globala.', casesensitive: 'Sensible a la cassa', undoedits: 'Desfar las edicions', undoinfo: 'Totas, pas sonque los remplaçaments', collapse: 'Amagar', expend: 'Afichar', lbwarning: 'Atencion : apiejar sus "Enter" publicarà\nlas edicions' },   };    lng = $.extend(lng.en, lng[mw.config.get('wgContentLanguage')], lng[mw.config.get('wgUserLanguage')]); $('.rail-auto-height').prepend(' ' + lng.far + ' (' + lng.expend + ')  ' + lng.findthis + ' ' + lng.linebreak + '   ' + lng.replacewith + '' + lng.linebreak + '   ' + lng.globalm + '' + lng.casesensitive + '    ' + lng.undoedits + '</a><img src=\"http://img2.wikia.nocookie.net/__cb20141207003419/harrypotter/fr/images/thumb/6/6c/Icone-aide.png/12px-Icone-aide.png\" alt=\"Icone-aide\" class=\"lzyPlcHld lzyTrns lzyLoaded\" data-image-key=\"Icone-aide.png\" data-image-name=\"Icone-aide.png\" data-src=\"http://img2.wikia.nocookie.net/__cb20141207003419/harrypotter/fr/images/thumb/6/6c/Icone-aide.png/12px-Icone-aide.png\" width=\"12\" height=\"12\">  ');    var placeholder = lng.lbwarning;    $('.far-module textarea').attr('value', placeholder);    $('.far-module textarea').focus(function{ if($(this).val === placeholder){ $(this).attr('value', ''); $(this).css('color', 'black'); }   });    $('.far-module textarea').blur(function{ if($(this).val ===''){ $(this).attr('value', placeholder); $(this).css('color', 'grey'); }        });    $('#find-and-replace').click(function  { var searchfor = '', searchexp, $textarea = $('.editpage-editarea textarea'), replacewith = $('#replace_with').val.replace(/\r/gi, ''), text = $textarea.val.replace(/\r/gi, ''), flagg = 'g', flagi = 'i'; if ($('#globl').prop('checked') === false) { flagg = ''; }       if ($('#case_sen').prop('checked') === true) { flagi = ''; }       var flags = flagg + flagi + 'm'; searchfor = $('#find_this').val.replace(/\r/gi, '').replace(/([.*+?^=!:${}|\[\]\/\\])/g,'\\$1'); searchexp = new RegExp(searchfor, flags); var rcount = 0; var matched = text.match(searchexp); if (matched !== null) { rcount = matched.length; }       text = text.replace(searchexp, replacewith); $textarea.val(text); $('#far-found').innerHTML( rcount + ' found and replaced.' ); });   function getOldContent {        $.getJSON("/api.php?action=query&format=json&prop=revisions&titles=" + encodeURIComponent(wgPageName.replace(/ /g,"_")) + "&rvprop=content&cb=" + new Date.getTime, function(data) { var pageData = data.query.pages; for (var pageid in pageData) { var pageContent = pageData[pageid].revisions[0]["*"]; // updated page content $('.editpage-editarea textarea').val(pageContent); }       });    }    $('a#far-alb').click(function { $('#replace_with').val($('#replace_with').val+'\n'); })   $('a#far-albi').click(function { $('#find_this').val($('#find_this').val+'\n'); })   $('a#far-undo').click(function  { getOldContent; });   $(".far-module h3").click(function  { var $header = $(this); var $content = $header.next; $('#triangle').css('background-image', function {            return $('#triangle').css('background-image') == 'url("https://upload.wikimedia.org/wikipedia/commons/0/0f/%D0%98%D0%BA%D0%BE%D0%BD%D0%BA%D0%B0_%D1%88%D0%B5%D0%B2%D1%80%D0%BE%D0%BD%D0%B0_%D0%B2%D0%B2%D0%B5%D1%80%D1%85_%28ei%29.svg")' ? 'url(\'https://upload.wikimedia.org/wikipedia/commons/4/48/%D0%98%D0%BA%D0%BE%D0%BD%D0%BA%D0%B0_%D1%88%D0%B5%D0%B2%D1%80%D0%BE%D0%BD%D0%B0_%D0%B2%D0%BD%D0%B8%D0%B7_%28ei%29.svg\')' : 'url("https://upload.wikimedia.org/wikipedia/commons/0/0f/%D0%98%D0%BA%D0%BE%D0%BD%D0%BA%D0%B0_%D1%88%D0%B5%D0%B2%D1%80%D0%BE%D0%BD%D0%B0_%D0%B2%D0%B2%D0%B5%D1%80%D1%85_%28ei%29.svg")';        }); $header.find('span').text(function {            return $content.is(":visible") ? lng.far + " (" + lng.expend + ")" : lng.far + " (" + lng.collapse + ")";        }); $content.slideToggle(500); }); });