User:DreamRimmer/BlankUserPage.js

//

var config = {};

$.when(   mw.loader.using(['mediawiki.util', 'mediawiki.api']),    $.ready ).then(function {

config.mw = mw.config.get([       "wgPageName",        "wgNamespaceNumber",    ]);

var API = new mw.Api({       ajax: {            headers: {                "Api-User-Agent": "userPageBlanking"            }        }    });

var isUserPage = config.mw.wgNamespaceNumber === 2 || config.mw.wgNamespaceNumber === 3; if (isUserPage) { mw.util.addPortletLink('p-cactions', "#", 'BlankPage', 'ca-blankUPage', "Blank User page", null, "#ca-move"); $('#ca-blankUPage').on('click', function {           mw.loader.load('User:DreamRimmer/test.css');            showBlankOptionsModal;        }); return; }

function showBlankOptionsModal { if ($('#blankOptionsModal').length > 0) { return; }

var modalContent = `  &times; BlankUserPage v2.0 Reason for blanking:    Add template. (See template documentation) Blank Page

`;

$('body').append(modalContent);

var modal = document.getElementById("blankOptionsModal"); var btn = document.getElementById("ca-blankUPage"); var span = document.getElementsByClassName("close")[0];

btn.onclick = function { modal.style.display = "block"; }

span.onclick = function { modal.style.display = "none"; }

window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; }       }

$('#blankButton').on('click', function {           var replaceContent = $('#replaceContentCheckbox').is(':checked');            var blankReason = $('#blankReasonInput').val;            if (replaceContent) {                blankUserPageWithReplacement(config.mw.wgPageName, blankReason);            } else {                blankUserPageWithoutReplacement(config.mw.wgPageName, blankReason);            }            modal.style.display = "none";        }); }

function blankUserPageWithReplacement(userPage, reason) { var textToAdd = "";

var queryParams = { action: "edit", text: textToAdd, summary: reason + " using BlankUserPage 2.0", nocreate: true, title: userPage };

API.postWithToken("csrf", queryParams).then(function {           location.reload; // Reload the page after blanking        }); }

function blankUserPageWithoutReplacement(userPage, reason) { var queryParams = { action: "edit", text: "", summary: reason + " using BlankUserPage 2.0", nocreate: true, title: userPage };

API.postWithToken("csrf", queryParams).then(function {           location.reload;         }); } }); //