User:Collei/AjaxDelete.min.js

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t:"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.swal=t:e.swal=t}(this,function{return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function{return e.default}:function{return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=8)}}),function(e,t,n){n.dev=n.dev||{},n.AjaxDeleteReasons=n.AjaxDeleteReasons||[];const o=t.config.get(["wgNamespaceNumber","wgPageName","wgArticleId"]);(new t.Api).get({action:"query",meta:"userinfo",format:"json",uiprop:"rights"}).done(function(r){const i=2==o.wgNamespaceNumber&&1==e("#profile-right").length&&1==e("#profile-image").length;if(void 0===n.dev.AjaxDelete&&n.fdButtons&&-1!==o.wgNamespaceNumber&&0!==o.wgArticleId&&r.query.userinfo.rights.includes("delete")&&!i){const r={init:function{t.util.addCSS("           \n                        /* Based on the #filetoc Vector CSS */\n                        #AjaxDelete-deleting-notice {\n                            text-align: center;\n                            border: 1px solid #a2a9b1;\n                            background-color: #f8f9fa;\n                            padding: 5px;\n                            font-size: 95%;\n                            margin-bottom: 0.5em;\n                            margin-left: 0;\n                            margin-right: 0;\n                        }\n                        \n                        /*\n                        https://github.com/Wikia/app/blob/dev/skins/oasis/css/core/page.scss\n                        License: https://github.com/Wikia/app/blob/dev/COPYING\n                        */\n                        .wds-button {\n                            -webkit-box-align: center;\n                            -webkit-box-pack: center;\n                            align-items: center;\n                            -webkit-appearance: none;\n                            background: #ffc200;\n                            border: 1px solid #8e7650;\n                            border-radius: 3px;\n                            color: white;\n                            cursor: default;\n                            display: -webkit-inline-box;\n                            display: inline-flex;\n                            font-family: inherit;\n                            font-size: 12px;\n                            font-weight: 600;\n                            justify-content: center;\n                            letter-spacing: 0.15px;\n                            line-height: 16px;\n                            margin: 0;\n                            min-height: 18px;\n                            outline: none;\n                            padding: 7px 18px;\n                            text-decoration: none;\n                            text-transform: uppercase;\n                            vertical-align: top;\n                            font-family: sans-serif;\n                        }\n                    "),e("#mm-page-delete-page > a").attr("href",""),e("#mm-page-delete-page > a").on("click",function(e){e.preventDefault;var t=[];n.AjaxDeleteReasons.forEach(e=>{t.push(new OO.ui.MenuOptionWidget({data:e,label:e}))}),t.push(new OO.ui.MenuOptionWidget({data:"choose-other-reason-selected",label:"Input another reason"}));var o=new OO.ui.DropdownWidget({label:"Select deletion reason",id:"AjaxDelete-deletion-dropdown",menu:{items:t}});itemSelected=function(e){swal.close,"choose-other-reason-selected"==e.data?r.chooseOtherDeleteReason:r.deletePage(e.label)},swal({content:o.$element[0]}),o.getMenu.on("select",itemSelected)})},chooseOtherDeleteReason:function{OO.ui.prompt("Enter delete reason",{textInput:{placeholder:"Delete reason"}}).done(function(e){null!==e&&r.deletePage(e)})},deletePage:function(n){e("#mw-content-text").prepend(e(" ",{id:"AjaxDelete-deleting-notice",text:"Deleting, please wait a moment..."})),(new t.Api).post({action:"delete",title:o.wgPageName,reason:n+" (using AjaxDelete)",bot:!0,token:t.user.tokens.get("csrfToken")}).done(function(t){if(t.error)return e("#AjaxDelete-deleting-notice").remove,void OO.ui.alert("API error occurred! Error code: "+t.error.code+" - "+t.error.info);e("#AjaxDelete-deleting-notice").text("Deletion done, refreshing the page..."),location.reload}).fail(function{e("#AjaxDelete-deleting-notice").remove,swal("AJAX error occurred. This could be a temporary issue. Try deleting the page again. If this still persists, contact Collei on metawiki, and make sure to provide your browser logs.")})}};n.dev.AjaxDelete=r,t.loader.using(["mediawiki.util","mediawiki.api","oojs-ui-core"]).then(function{r.init})}}).fail(function(e){console.error(e),swal("AjaxDelete encountered an error when checking if you have delete permissions. If this repeatedly occurs, please contact Collei on metawiki for help. Make sure to provide any errors from your browser console.")})}(jQuery,mediaWiki,window);