User:Mainframe98/common.js

/** */ ( function ( mw, $ ) {
 * Adds a Sandbox button, originally from https://www.wikidata.org/wiki/MediaWiki:Gadget-mySandbox.js, but that version used a localized subpagename.
 * Tweaked to remove redundancy

$( document ).ready( function {        var conf, title, url;        var lang = mw.user.options.get( 'language' );

var transconf = { 'en': { portletLabel: 'Sandbox', portletTooltip: 'Go to your sandbox', },           'nl': { portletLabel: 'Zandbak', portletTooltip: 'Ga naar je zandbak', }       };        if ( transconf [ lang ] ) { conf = transconf[ lang ]; } else { conf = transconf[ 'en' ]; }       title = new mw.Title( 'Special:MyPage/Sandbox' );

url = new mw.Uri( title.getUrl );

mw.util.addPortletLink(           'p-personal',            url,            conf.portletLabel,            'pt-mysandbox',            conf.portletTooltip,            null,            '#pt-preferences'        ); }); }( mediaWiki, jQuery ) ); /* Mark for (Speedy) Deletion Adapted to use Template:Speedy */ /* Customization */ window.MarkForDeletion = { promptedDeleteReason: "Out of project scope" }; /* Source: http://dev.wikia.com/wiki/MarkForDeletion, used revision 47639 */ $(function {   "use strict";    if(mw.config.get("wgAction") !== "view" || mw.config.get("wgNamespaceNumber") === -1 || mw.config.get("wgUserName") === null) {        return;    }    var i18n = {        /* English */        en: {            buttonTitle: "Mark for speedy deletion",            spam: "spam",            prompt: "Enter delete reason to quickly mark this page for speedy deletion",            error: "An error occurred while marking the page for speedy deletion"        }    };    function setDeleteNotice(deleteReason) {        $.ajax({ type: "POST", url: mw.util.wikiScript('api'), data: { action: "edit", title: mw.config.get("wgPageName"), summary: "Marked for speedy deletion because: " + deleteReason, token: mw.user.tokens.get("editToken"), prependtext: "{" + "{speedy|" + deleteReason + "}}\n", format: "json" },           success: function(d) { if(d && d.error && d.error.code) { new BannerNotification(i18n.error + ": " + d.error.code, 'error').show; } else { window.location.reload; }           },            error: function { new BannerNotification(i18n.error, 'error').show; }       });    }    function initializeI18N {        var lang = mw.config.get("wgUserLanguage"),            base = lang.split("-")[0];        if(i18n[lang]) {            i18n = i18n[lang];        } else if(i18n[base]) {            i18n = i18n[base];        } else {            i18n = i18n.en;        }    }    function initDeleteNoticeButton {        // don't create duplicate buttons        if ($("#mark-for-deletion-link").length > 0) {            return;        }        var $button = $(mw.html.element("a", {            id: "mark-for-deletion-link",            style: "cursor: pointer;"        }, i18n.buttonTitle)), $toolbar, $insertLinkHere;        // create button        $button.click(function { var promptedDeleteReason = i18n.spam; if (window.MarkForDeletion && typeof window.MarkForDeletion.promptedDeleteReason === "string") { promptedDeleteReason = window.MarkForDeletion.promptedDeleteReason; }           var deleteReason = window.prompt(i18n.prompt, promptedDeleteReason); if (typeof deleteReason === "string" && deleteReason.length > 0) { setDeleteNotice(deleteReason); }       });        // add button to toolbar        $toolbar = $("#p-tb");        if ($toolbar.length > 0) {            $toolbar.find("ul").append($button);        }        $("#mark-for-deletion-link").wrap("");    }    initializeI18N;    initDeleteNoticeButton; });