User:Orgus Ordo/common.js

/** Own buttons */   mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "https://vignette.wikia.nocookie.net/starwars/images/0/07/Redirectbutton.png/revision/latest?cb=20190116185758&path-prefix=ka", "speedTip": "Redirect", "tagOpen": "#REDIRECT ",		"tagClose": "", "sampleText": "Some text" };	mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "https://upload.wikimedia.org/wikipedia/commons/a/a2/Emdash-button-bg.png ", "speedTip": "—", "sampleText": " — ", };

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "https://upload.wikimedia.org/wikipedia/commons/0/0c/Button_Link_DifferentName.png", "speedTip": "Brackets 2", "tagOpen": "|",		"tagClose": "", "sampleText": "Brackets" };	mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "https://vignette.wikia.nocookie.net/starwars/images/d/d5/Wikibutton.png/revision/latest?cb=20190824171915&path-prefix=ka", "speedTip": "Wikipedia", "tagOpen": "",		"tagClose": "", "sampleText": "Sample text" };

/** * Name:       WhatLinksHere * Version:    v1.1 * Author:     KockaAdmiralac <1405223@gmail.com> * Description: Adds a link to Special:WhatLinksHere below the edit dropdown */ (function {   'use strict';    var $list = $('.page-header__contribution-buttons .wds-list, .UserProfileActionButton .WikiaMenuElement');    if (!$list.exists || window.WhatLinksHereLoaded) {        return;    }    window.WhatLinksHereLoaded = true;    var config = mw.config.get([ 'wgPageName', 'wgUserLanguage' ]);   mw.hook('dev.fetch').add(function(fetch) { fetch('whatlinkshere').then(function(text) {           var url = mw.util.getUrl('Special:WhatLinksHere/' + config.wgPageName);            $list.append( $('', {                   id: 'ca-whatlinkshere'                }).append(                    $('', { href: url, text: text })               )            );            if (mw.util.getParamValue('redirect') === 'no') {                $('.redirectText').append( $(' '),                   $(' ', {                        id: 'redirectWLH'                    }).append(                        '→ ',                        $('', { 'class': 'redirectWLH-link', href: url, text: text })                   )                );            }        });    });    importArticle({ type: 'script', article: 'u:dev:MediaWiki:Fetch.js' }); });

/** Find and replace */

$(function {   'use strict';    importArticle({ type: 'style', article: 'u:dev:MediaWiki:FindAndReplace.css' });   var st = JSON.parse(localStorage.getItem("FindAndReplace")),        cvGM = window.cvGlobalMatching || 'checked',        cvCS = window.cvCaseSensitive || 'unchecked',        cvRG = window.cvEnableRegex || 'unchecked',        selectedText = "",        contengut = document.getElementById("wpTextbox1"),        debuta,        fin;    if (typeof st !== 'object' || st === null) st = {sh: false, gm: true, cs: false};    if (window.FindAndReplaceLoaded) {        return;    }    window.FindAndReplaceLoaded = true;    importArticle({ type: 'script', article: 'u:dev:MediaWiki:I18n-js/code.js' });   mw.hook('dev.i18n').add(function(i18no) { i18no.loadMessages('FindAndReplace').then(function(i18n) {   $('.rail-auto-height').prepend(' ' + i18n.msg('far').escape + ' (' + (st.sh ? i18n.msg('collapse').escape : i18n.msg('expand').escape) + ')   ' + i18n.msg('findthis').escape + '  ' + i18n.msg('replacewith').escape + '      ' + i18n.msg('selectedtext').escape + '  ' + i18n.msg('undoedits').escape + '   ');    $(window).resize(function { $('#findfielddiv').height($(window).height - 250 - $('.module_content').height); });   $(window).trigger('resize');    $('#find-and-replace').click(function  { var searchfor = '', searchexp, $textarea = $('#wpTextbox1'), replacewith = $('#replace_with').val.replace(/\r/gi, ''), text = $textarea.val.replace(/\r/gi, ''), flagg = 'g', flagi = 'i', enableregex = 0; if ($('#globl').prop('checked') === false) { flagg = ''; }       if ($('#case_sen').prop('checked') === true) { flagi = ''; }       if ($('#regex_search').prop('checked') === true) { enableregex = 1; }       var flags = flagg + flagi + 'm'; if(enableregex === 1) { searchfor = $('#find_this').val; } else { 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').text( rcount + ' ' + i18n.msg('farfound').escape ); });   function getSelectedText {        var texte = "";        if (window.getSelection) {            texte = window.getSelection.toString;        } else if (document.selection && document.selection.type != "Control") {            texte = document.selection.createRange.text;        }        if(texte === "") {            texte = selectedText;        }        return texte;    }    $('#wpTextbox1').bind('mouseup keyup mouseleave', function{ selectedText = getSelectedText; debuta = contengut.selectionStart; fin = contengut.selectionEnd; $('#texteselectionne').text(selectedText); });   $('#find-and-replace-selected').click(function  { if(selectedText === "") { alert(i18n.msg('noselected').escape); }       var searchfor = '', searchexp, searchexp2, letexte, selectedText2, $textarea = $('#wpTextbox1'), replacewith = $('#replace_with').val.replace(/\r/gi, ''), text = $textarea.val.replace(/\r/gi, ''), flagg = 'g', flagi = 'i', enableregex = 0; if ($('#globl').prop('checked') === false) { flagg = ''; }       if ($('#case_sen').prop('checked') === true) { flagi = ''; }       var flags = flagg + flagi + 'm'; if(enableregex === 1) { searchfor = $('#find_this').val; } else { searchfor = $('#find_this').val.replace(/\r/gi, '').replace(/([.*+?^=!:${}|\[\]\/\\])/g,'\\$1'); }       searchexp = new RegExp(searchfor, flags); selectedText2 = selectedText.replace(/\r/gi, '').replace(/([.*+?^=!:${}|\[\]\/\\])/g,'\\$1'); searchexp2 = new RegExp(selectedText2, 'im'); var rcount = 0; var matched = selectedText.match(searchexp); if (matched !== null) { rcount = matched.length; }       letexte = selectedText.replace(searchexp, replacewith); text = text.substring(0, debuta) + letexte + text.substring(fin); $textarea.val(text); $('#far-found').text( rcount + ' ' + i18n.msg('farfound').escape ); selectedText = letexte; $('#texteselectionne').text(selectedText); });   function getOldContent {        $("#wpTextbox1").val($("#wpTextbox1").text);    }    $('a#far-undo').click(function  { if (confirm(i18n.msg('undomsg').escape)) getOldContent; });   $(".far-module h3").click(function  { var $header = $(this); var $content = $header.next; var $visible = $content.is(":visible"); $header.find('span').text(i18n.msg('far').escape + " (" + ($visible ? i18n.msg('expand').escape : i18n.msg('collapse').escape) + ")"); $header.find(".chevron").addClass($visible ? "expand" : "collapse").removeClass($visible ? "collapse" : "expand"); $content.stop.slideToggle(500); });   $(window).bind("beforeunload", function{ localStorage.setItem("FindAndReplace", JSON.stringify({sh: $("#findfielddiv").is(":visible") })); });}); });});