User:Paperluigi ttyd/common.js

/*! * QuickDeleteTimer * * Quickly adds and  to pages * Click the button and enter the date in Month Day, Year format, ex: January 1, 2017 * * Based on MarkForDeletion * http://dev.wikia.com/wiki/MarkForDeletion */

/*jshint forin:true, noempty:true, eqeqeq:true, bitwise:true, strict:true, undef:true, unused:true, curly:true, browser:true, jquery:true */ /*global mw, skin, BannerNotification */

$(function {   "use strict";    if(mw.config.get("wgAction") !== "view" || mw.config.get("wgNamespaceNumber") === -1 || mw.config.get("wgUserName") === null) {        return;    }    var ug = mw.config.get('wgUserGroups');    if (ug.indexOf('sysop') + ug.indexOf('staff') + ug.indexOf('helper') + ug.indexOf('VSTF') + ug.indexOf('content-moderator') < -5) {        return;    }    var i18n = {        /* English */        en: {            buttonTitle: "Add deletion timer",            summaryPrefix: "Article stub - added timer",            spam: "January 1, 2000",            prompt: "Enter a date to quickly add a deletion timer to this page",            error: "An error occurred while adding a deletion timer to this page"        }    };    function setDeleteNotice(deleteReason) {        $.ajax({ type: "POST", url: mw.util.wikiScript('api'), data: { action: "edit", title: mw.config.get("wgPageName"), summary: i18n.summaryPrefix + ": " + deleteReason, token: mw.user.tokens.get("editToken"), prependtext: "{" + "{stub}}" + "{" + "{DeletionTimer|onemonth = " + deleteReason + "}}", 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        if (skin === "oasis") {            $toolbar = $("#WikiaBarWrapper");            $insertLinkHere = $toolbar.find("li.mytools");            if ($insertLinkHere.length > 0) {                // insert link before My Tools                $insertLinkHere.before($button);            } else {                // try to insert link before Customize                $insertLinkHere = $toolbar.find("a.tools-customize").parent;                $insertLinkHere.before($button);            }        } else {            $toolbar = $("#p-tb");            if ($toolbar.length > 0) {                $toolbar.find("ul").append($button);            }        }        $("#mark-for-deletion-link").wrap("");    }    initializeI18N;    initDeleteNoticeButton; });