User:343TheGuiltyProphet/wikia.js

/*!    * Original script: 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 mediaWiki */ if (mediaWiki.config.get("wgAction") === "view" && mediaWiki.config.get("wgNamespaceNumber") !== -1 && mediaWiki.config.get("wgUserName") !== null) { (function ($, mw, window, document) {                   "use strict";                    var wgServer = mw.config.get("wgServer"),                            wgPageNameEncoded = window.encodeURIComponent(mw.config.get("wgPageName"));                    // uses MW API to automatically edit the page and insert the delete template at the top                    function setDeleteNotice(deleteReason) {                            var xhr = new XMLHttpRequest,                                    summary = "Adding template: {" + "{" + deleteReason + "}}",                                    content = "{" + "{" + deleteReason + "}}",                                    editToken = mw.user.tokens.get("editToken"),                                    url = wgServer + "/api.php?action=edit&title=" + wgPageNameEncoded + "&summary=" + window.encodeURIComponent(summary) + "&format=json&appendtext=" + window.encodeURIComponent(content) + "&token=" + window.encodeURIComponent(editToken); xhr.open("POST", url); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function { if (this.readyState === 4) { window.location.reload; }                           };                            xhr.send; }                   // adds a "Mark for deletion" button to the user's toolbar function initDeleteNoticeButton { var $button, toolbar, $mytoolsLI, $customizeLI; // create button $button = $('Filespace Project'); $button.click(function deleteNoticeButtonClickHandler {                                   var promptedDeleteReason = "User:343 TheGuiltyProphet/Attention";                                    if (typeof window.c === "object" && window.Template !== null && typeof window.Template.promptedDeleteReason === "string") {                                            promptedDeleteReason = window.Template.promptedDeleteReason;                                    }                                    var deleteReason = window.prompt("Enter template name here - Signature must already be in the template - Don't add extra  – ", promptedDeleteReason);                                    if (typeof deleteReason === "string" && deleteReason.length > 0) {                                            setDeleteNotice(deleteReason);                                    }                            }); // add button to toolbar toolbar = document.getElementById("WikiaBarWrapper"); if (toolbar !== null) { // oasis $mytoolsLI = $(toolbar).find("li.mytools"); if ($mytoolsLI.length > 0) { // insert link before My Tools $mytoolsLI.before($button); } else { // try to insert link before Customize $customizeLI = $(toolbar).find("a.tools-customize").parent; $customizeLI.before($button); }                           } else { // monobook toolbar = document.getElementById("p-tb"); if (toolbar !== null) { $(toolbar).find("ul").append($button); }                           }                    }                    // add button on DOMReady $(initDeleteNoticeButton); }(jQuery, mediaWiki, window, document));   }