User:Aspallar/common.js

// window.nullEditDelay = 6000;

importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:PurgeButton/code.js',        'u:dev:MediaWiki:MassNullEdit/code.js',        'u:dev:MediaWiki:ClipboardCopy.js',        'u:dev:MediaWiki:AnalyticsShortcut.js'    ] });

// $('#mw-clearyourcache').remove; (function ($) {   'use strict';    console.log('OpenBlank A');    function openBlank(event) {        event.preventDefault;        $('a').attr('target', '_blank');    }    function addMyToolsOption {        var link = $('')            .append($('').attr({href: '#'}).text('Open Blank'))            .click(openBlank);         $('#my-tools-menu').prepend(link);    }    $(addMyToolsOption); }(jQuery));

(function($) {   'use strict';    /*global mw */

var pageName = mw.config.get('wgTitle'); if (pageName.substring(0, 6) !== 'Decks/') return;

$('.UserProfileActionButton > .wikia-menu-button > ul, .page-header__contribution-buttons .wds-list').append(       $('').append( $('', {               href: mw.util.getUrl('User:Aspallar/Sandbox/Deck', { deck: pageName.substring(6) }),                text: 'Test Builder',                title: 'Edit with the test deck builder'            }) )   ); }(jQuery));

// ============================================================================ // COPY FROM HERE TO END // ========================================================================== // ImportDeck // // Version 1.4.0 // Author: Aspallar // // Provides a user friendly way to import a deck from Magic Arena // without the user having to edit any wikitext. // // ** Please do not edit this code directly in the wikia. // ** Instead use the git repository https://github.com/Aspallar/WikiLua // // (function ($) { //    /* global mw*/ //     'use strict';

//    if (document.getElementById('mdw-import-deck') === null || $('#mdw-disabled-js').attr('data-importdeck-1-4-0')) //        return;

//    var newDeckTemplate = ''; //    var translation = null;

//    function wikiApiCall(data, method) { //        data.format = 'json'; //        return $.ajax({ //             data: data, //             dataType: 'json', //             url: mw.config.get('wgScriptPath') + '/api.php', //             type: method //         }); //    }

//    function removeIncludes(contents) { //        return contents.replace(/<[\/]?noinclude>|<[\/]?includeonly>/g, ''); //    }

//    function invalidTitle(title) { //        return /#|\?/g.test(title); //    }

//    function showWorking { //        $('#mdw-working').show; //    }

//    function hideWorking { //        $('#mdw-working').hide; //    }

//    function showForm { //        $('#mdw-import-deck').fadeIn(400); //    }

//    function showBadEntries(badEntries) { //        var safeBadEntries = []; //        badEntries.forEach(function (entry) { //             safeBadEntries.push(mw.html.escape(entry)); //         }); //        var content = safeBadEntries.join(' '); //        $('#mdw-import-badentries-content').html(content); //        $('#mdw-import-badentries').fadeIn(400); //    }

//    function hideBadEntries { //        $('#mdw-import-badentries').hide; //    }

//    function controlsDisabled(disabled) { //        $('#mdw-import-button').prop('disabled', disabled); //        $('input[name="mdw-import-lang"').prop('disabled', disabled); //    }

//    function disableControls { //        controlsDisabled(true); //    }

//    function enableControls { //        controlsDisabled(false); //    }

//    function showPreviewMessage(message, isError) { //        var span = $(' ').text(message); //        if (isError) span.addClass('mdw-error'); //        $('#mdw-import-preview-message').html(span); //        setTimeout(function  { //             $('#mdw-import-preview-message').empty; //         }, 3000); //    }

//    function fetchNewDeckTemplate { //        // var deferred = $.Deferred; //        // deferred.resolve('start/n$1/nend '); //        // return deferred.promise; //        return $.get(mw.util.getUrl('Template:NewDeck', {action: 'raw'})); //    }

//    function fetchTranslation(langCode) { //        return $.get(mw.util.getUrl('MediaWiki:Custom-Cards-' + langCode, {action: 'raw'})); //    }

//    function displayError(name, message) { //        $('#mdw-import-' + name + '-error').html('* ' + message); //        return false; //    }

//    function unexpectedError(message) { //        displayError('unexpected', 'An unexpected error occurred: ' + message); //    }

//    function validateDeckName { //        var name = $('#mdw-import-deckname').val.trim; //        if (name.length === 0) //            return displayError('deckname', 'A deck name is required.'); //        else if (invalidTitle(name)) //            return displayError('deckname', 'Invalid deck name.'); //        else //            return true; //    }

//    function validateDeckDef { //        var deckdef = $('#mdw-import-deckdef').val.trim; //        if (deckdef.length === 0) //            return displayError('deckdef', 'You must enter a deck definition'); //        else //            return true; //    }

//    function redirectToTitle(title) { //        window.location = mw.util.getUrl(title); //    }

//    function handleCreateError(error) { //        enableControls; //        if (error.code === 'articleexists') { //            displayError('deckname', 'Deck name already in use.'); //            $('#mdw-import-deckname').focus; //        } else if (error.code === 'invalidtitle') { //            displayError('deckname', 'Invalid deck name.'); //            $('#mdw-import-deckname').focus; //        } else { //            unexpectedError(error.info); //        } //     }

//    function replaceCurlyQuotesWithApostrophe(s) { //        return s.replace(/[\u2018\u2019]/g, '\''); //    }

//    function correctCardName(name) { //        return replaceCurlyQuotesWithApostrophe(name) //            .replace(/\/+/g, ' // ') //            .replace(/\s\s+/g, ' '); //    }

//    function translateCard(entry) { //        if (translation === null) //            return entry; //        var match = /(\d+)\s+(.*?)(?=\s+\/\/|\s+\(|$)/.exec(entry); //         if (!match) //             return entry; //         var translatedName = translation[match[2].toLowerCase.trim]; //         if (translatedName === undefined) //             return entry; //         return match[1] + ' ' + translatedName; //     }

//    function getDeckText(deckEntries) { //        var translated = []; //        deckEntries.forEach(function (entry) { //             translated.push(translateCard(entry)); //         }); //        return translated.join('\n'); //    }

//    function createDeckPage(name, deckEntries, originalText) { //        disableControls; //        showWorking; //        mw.loader.using('mediawiki.api').then(function  { //             var content = newDeckTemplate.replace('$1', getDeckText(deckEntries)) + //                 '\n\n'; //             var title = 'Decks/' + name; //             new mw.Api.post({ //                action: 'edit', //                title: title, //                summary: 'Imported deck', //                createonly: 'yes', //                text: content, //                token: mw.user.tokens.get('editToken') //            }).done(function(result) { //                hideWorking; //                if (result.error === undefined) { //                    redirectToTitle(title); //                } else { //                    handleCreateError(result.error); //                } //             }).fail(function(code, result) { //                unexpectedError(code + (code === 'http' ? ' ' + result.textStatus : '')); //            }); //         }); //     }

//    function parseDeckDef(deckdef) { //        var maxLength = $('#mdw-import-deck').attr('data-maxcardlength') || 40; //        var result = { validEntries: [], badEntries: [], sideboardCount: 0 }; //        deckdef.split('\n').forEach(function (entry) { //             entry = entry.trim; //             if (entry.length === 0) { //                 ++result.sideboardCount; //                 result.validEntries.push('--- sideboard ---'); //             } else if (entry.length > maxLength) { //                 result.badEntries.push(entry.substring(0, maxLength) + '... (too long)'); //            } else if (/^\d+\s+.*\S.*$/.test(entry)) { //                 result.validEntries.push(correctCardName(entry)); //             } else { //                 result.badEntries.push(entry); //             } //         }); //        return result; //    }

//    function clickImport { //        hideBadEntries; //        $('.mdw-error').html(''); //        var nameValid = validateDeckName ; //        var deckdefValid = validateDeckDef; //        if (deckdefValid) { //            var text = $('#mdw-import-deckdef').val.trim; //            var result = parseDeckDef(text); //            if (result.badEntries.length > 0) //                showBadEntries(result.badEntries); //            if (result.sideboardCount > 1) //                displayError('deckdef', 'Import contains more than one sideboard.'); //            if (nameValid && result.badEntries.length === 0 && result.sideboardCount <= 1) //                createDeckPage($('#mdw-import-deckname').val, result.validEntries, text); //        } //     }

//    function showTranslationLoadFail(langCode) { //        $.showCustomModal( //             'Load Error', //             ' Failed to load translation data (' + langCode + '). Defaulting back to English. ', { //             id: 'mdw-loadfail-dialog', //             width: 350, //             buttons: [{ //                 id: 'mdw-loadfail-dialog-ok', //                 message: 'OK', //                 defaultButton: true, //                 handler: function  { //                     $('#mdw-loadfail-dialog').closeModal; //                 } //             }] //         }); //    }

//    function parseTranslation(data) { //        var trans = {}; //        data.split('\n').forEach(function (entry) { //             var match = /^(.*)?\|(.*)$/.exec(entry); //             if (match) //                 trans[match[1].toLowerCase] = match[2]; //         }); //        return trans; //    }

//    function changeLanguage { //        /*jshint -W040 */ // allow old school jquery use of this //        var langCode = $(this).val; //        if (langCode === 'en') { //            translation = null; //        } else { //            disableControls; //            fetchTranslation(langCode).done(function (data) { //                 translation = parseTranslation(data); //                 enableControls; //             }).fail(function  { //                 showTranslationLoadFail(langCode); //                 $('#mdw-import-english').prop('checked', true); //                 translation = null; //                 enableControls; //             }); //        } //     }

//    function wikiParse(text) { //        var deferred = $.Deferred; //        wikiApiCall({ //             action: 'parse', //             disablepp: 1, //             prop: 'text', //             text: text //         }, 'POST').done(function (response) { //             if (response && response.parse && response.parse.text) { //                 var text = response.parse.text['*']; //                 deferred.resolve(text); //             } else { //                 deferred.reject('Unknown response from parse template'); //             } //         }).fail(function  { //             deferred.reject('Network error while parsing template'); //         }); //        return deferred.promise; //    }

//    function previewDeck(deckEntries) { //        var deckTemplate = ''; //        wikiParse(deckTemplate).done(function (deckHtml) { //             var deckPreview = $('#mdw-import-deck-preview'); //             deckPreview.html(deckHtml).find('a').attr('target', '_blank'); //             tooltips.applyTooltips(deckPreview.get(0)); //             $('#mdw-import-preview').show('fast', function { //                magicArena.charts.refresh; //            }); //         }).fail(function (error) { //             $('#mdw-db-preview-button').val('Preview Deck'); //             showPreviewMessage(error, true); //             $('#mdw-db-preview').hide; //         }); //    }

//    function clickPreview { //        /*jshint -W040 */ // allow old school jquery this //        hideBadEntries; //        $('.mdw-error').html(''); //        var deckdefValid = validateDeckDef; //        if (deckdefValid) { //            var text = $('#mdw-import-deckdef').val.trim; //            var result = parseDeckDef(text); //            if (result.badEntries.length > 0) //                showBadEntries(result.badEntries); //            if (result.sideboardCount > 1) //                displayError('deckdef', 'Import contains more than one sideboard.'); //            if (result.badEntries.length === 0 && result.sideboardCount <= 1) { //                $(this).val('Update Preview'); //                previewDeck(result.validEntries); //            } //         } //     }

//    function createForm { //        /*jshint multistr:true*/ //        $('#mdw-import-deckname-span') //            .append(''); //        $('#mdw-import-deckdef-span') //            .append(' '); //        var importBtn = $('') //            .click(clickImport); //        var previewBtn = $('') //            .click(clickPreview); //        $('#mdw-import-button-span').append(importBtn).append(' ').append(previewBtn); //        var languages = $('  English \ //              Deutsch \ //              Español \ //              Français \ //              Italiano \ //              Português '); //        languages.find('input[name="mdw-import-lang"]').change(changeLanguage); //        $('#mdw-lang-span').replaceWith(languages); //    }

//    function initialize { //        $('#mdw-working').html($(' ', { //            src: mw.config.get('stylepath') + '/common/images/ajax.gif' //        })); //         showWorking; //        fetchNewDeckTemplate.done(function (template) { //             newDeckTemplate = removeIncludes(template); //             createForm; //             hideWorking; //             showForm; //             $('#mdw-import-deckname').focus; //         }).fail(function  { //             hideWorking; //             $('#mdw-import-deck').html(' Failed to load new deck template. '); //            showForm; //         }); //    }

//    $(document).ready(initialize);

// }(jQuery));

// Continuos random page (function {    /*global mw*/    'use strict';

var timeout;

if (['User', 'Special', 'MediaWiki'].indexOf(mw.config.get('wgCanonicalNamespace')) !== -1) return;

function randomPage { window.location = '/wiki/Special:RandomPage'; }

function start { $('#mdw-random-page').text('Toggle Random (active)'); timeout = setTimeout(randomPage, 6000); }

function stop { $('#mdw-random-page').text('Toggle Random (inactive)'); clearTimeout(timeout); }

function toggleActive(event) { event.preventDefault; if (sessionStorage.getItem('random-page')) { sessionStorage.removeItem('random-page'); stop; } else { sessionStorage.setItem('random-page', 'yes'); start; }   }

$(function {        var link = $('').append($('').attr({href: '#', id: 'mdw-random-page'}).click(toggleActive));         $('#my-tools-menu').prepend(link);        if (sessionStorage.getItem('random-page'))            start;        else            stop;     });

});

// Deck deletion helper (function ($) {   /*global mw */    'use strict';

if (mw.config.get('wgAction') !== 'delete' || mw.config.get('wgTitle').substring(0, 6) !== 'Decks/') return;

function submitClick { /* jshint -W040 */ // allow old school jquery use of this var that = $(this); $('#wpReason').val(that.attr('data-other')); $('#wpDeleteReasonList').val(that.attr('data-reason')); }

function deleteButton(text, reason, otherText) { var input = $('<input type="submit" class="mdw-deckdelete-button">') .val(text) .attr('data-reason', reason) .attr('data-other', otherText) .click(submitClick); return $('   ').append($('<td class="mw-submit">').append(input)); }

function initialize { $('#mw-deleteconfirm-table tbody') .append(deleteButton('Random deck name', 'Housekeeping', 'Please don\'t give decks a name consisting of nothing but random characters')) .append(deleteButton('Not an arena deck', 'Housekeeping', 'Not an arena deck')) .append(deleteButton('Test deck', 'Housekeeping', 'Someone\'s test import')) .append(deleteButton('Too few cards', 'Housekeeping', 'Invalid deck, not enough cards')) .append(deleteButton('Too many cards', 'Housekeeping', 'Invalid deck, too many cards')) .append(deleteButton('Outdated Meta', 'Housekeeping', 'Outdated meta')) .append(deleteButton('Invalid deck', 'Housekeeping', 'Invalid deck')) .append(deleteButton('Poor deck name', 'Housekeeping', 'Poor deck name')) .append(deleteButton('Bad deck contents (Vandalism)', 'Vandalism', 'Unacceptable deck contents')) .append(deleteButton('Unacceptable deck name (Vandalism)', 'Vandalism', 'Unacceptable deck name')) .append(deleteButton('Test Cleanup', 'Housekeeping', 'Cleanup after test')); $('#wpWatch').prop('checked', false); }

$(initialize);

}(jQuery));

// List deck menu option (function($) {   'use strict';    /*global mw */    var pageName = mw.config.get('wgTitle');    if (pageName.substring(0, 6) !== 'Decks/')        return;

var author = $('#mw-content-text a[href^="/wiki/User:"'); author = (author.length > 0) ? author.attr('href').substring(11) : 'Anonymous';

$('.UserProfileActionButton > .wikia-menu-button > ul, .page-header__contribution-buttons .wds-list').append(       $('<li>').append( $('<a>', {               href: mw.util.getUrl('Deck List Editor', { author: author, deck: pageName.substring(6) }),                text: 'List Deck',                title: 'List the deck using the Deck List Editor'            }) )   );

}(jQuery));

(function($) {   'use strict';    /*global mw */    var pageName = mw.config.get('wgTitle');    if (pageName.substring(0, 6) !== 'Decks/')        return;

var author = $('#mw-content-text a[href^="/wiki/User:"'); author = (author.length > 0) ? author.attr('href').substring(11) : 'Anonymous';

$('.UserProfileActionButton > .wikia-menu-button > ul, .page-header__contribution-buttons .wds-list').append(       $('<li>').append( $('<a>', {               href: mw.util.getUrl('User:Aspallar/Sandbox/dle', { author: author, deck: pageName.substring(6) }),                text: 'List Deck (Test)',                title: 'List the deck using the Deck List Editor'            }) )   );

}(jQuery));