User:KMØ/wikia.js

$(document).ready(function {   if (wgCanonicalNamespace !== "") {        return;    }    $(".WikiaMenuElement").find("a#ca-delete").parent.after('Unclaimed Character');    $("#unclaimed-character").click(function { UnclaimedCharacterConfirmation; });   function UnclaimedCharacterConfirmation {        $.showCustomModal("Unclaimed Character", "Please verify that the page " + wgPageName.replace("_/g", " ") + " you are deleting is an unclaimed character page before continuing with the deletion!", { id: "unclaimed-character-confirmation", width: 350, buttons: [{ id: "delete-button", message: 'Delete', handler: function { $("#unclaimed-character-confirmation").closeModal; UnclaimedCharacterDelete; }           }, {                id: "cancel-button", message: "Cancel", defaultButton: true, handler: function { $("#unclaimed-character-confirmation").closeModal; return; }           }]        });    }    function UnclaimedCharacterDelete {        $.get(mw.util.wikiScript("api"), { action: "query", titles: wgPageName, prop: "revisions", rvprop: "user", rvdir: "newer", rvdiffto: "prev", format: "json" }, function(data) { for (var i in data.query.pages) break; var rv = data.query.pages[i].revisions[0]; $.post(mw.util.wikiScript("api"), {               action: "edit",                title: "User_talk:" + rv.user,                section: "new",                sectiontitle: "Unclaimed Character",                text: "Hello there!\n\nThis message is to let you know that since your character " + wgPageName.replace(/_/g, " ") + " hasn't gone through our claiming process, the character page has been deleted. In order to create a character and start roleplaying with them, your character must be approved in our claiming process first.\n\nIf you haven't already, feel free to take a look at our our guide to getting started, our claiming rules and guidelines, and the 101 on claims! Thank you and have a great day!\n\n(This is an automated message automatically sent with the deletion of your page; if you need any help, do not hesitate to message me or another available administrator!) ''\n\n" + "", summary: "Automated message about the deletion of the user's character page for their unclaimed character " + wgPageName.replace(/_/g, " ") + ".", token: mw.user.tokens.get("editToken") }).done(function(done) { if (!done.error) { new BannerNotification(rv.user + " has been successfully messaged!", "success").show; } else { new BannerNotification("An error occurred while messaging " + rv.user + " (" + done.error.code + " )!", "error").show; }           })            .fail(function { new BannerNotification("Failed to message " + rv.user + "!", "failure").show; });

new mw.Api.post({               action: "delete",                title: wgPageName,                reason: "Unclaimed Character",            }).done(function(done) {                if (!done.error) {                    new BannerNotification("The page " + wgPageName.replace(/_/g, " ") + " has been successfully deleted!", "success").show;                    window.location.pathname = "/wiki/";                } else {                    new BannerNotification("An error occurred while deleting the page" + wgPageName.replace(/_/g, " ") + " (" + done.error.code + ")!", "error").show;                }            }) .fail(function {               new BannerNotification("Failed to delete the page" + wgPageName.replace("_/g", " ") + ", please try again!", "failure").show;            }); });   } });