User:Rebbing/script/deletion-sorting-helper.js

if (mw.config.get('wgPageName').indexOf('Wikipedia:Articles_for_deletion/') != -1 &&       mw.config.get('wgPageName').indexOf('Wikipedia:Articles_for_deletion/Log/201') == -1) {

var delsortTag = "(deletion-sorting-helper)";

function doDelsort(cat) { if (!confirm("Add deletion sorting category " + cat + "?")) { return; }

var url = "//en.wikipedia.org/w/api.php?action=tokens&format=json&type=edit"; var xhr = new XMLHttpRequest; xhr.open("GET", url); xhr.send; xhr.onreadystatechange = function { if (xhr.readyState == 4 && xhr.status == 200) { var resp = JSON.parse(xhr.responseText); console.log("Token first: ", resp.tokens.edittoken); $.each(resp, function(i, v) {                   console.log(i, "=", v);                }); var etoken = resp.tokens.edittoken; console.log("The token is: ", etoken); if (cat != null) { var editData = { action: "edit", format: "json", summary: "Listed at WP:DELSORT under " + cat + ". " + delsortTag, token: etoken, title: mw.config.get('wgPageName'), appendtext: "\{\{subst:Delsort|" + cat + "|\~\~\~\~\}\}" };                   $.each(editData, function(i, v) {                        console.log(i, "=", v);                    }); $.post('//en.wikipedia.org/w/api.php',                           editData,                            function(data) {                                jQuery.each(data, function(index, value) { console.log("index", index, "value", value); });                           });

// Add to the Delsort page // First, get the content $.post('//en.wikipedia.org/w/api.php',                       {                            action: 'query',                            format: 'json',                            prop: 'revisions',                            rvprop: 'content',                            rvlimit: '1',                            titles: 'Wikipedia:WikiProject Deletion sorting/' + cat                        },                        function(data) {                            $.each(data.query.pages, function(i, v) { window.editContent = v.revisions[0]['*'] .replace('directly below this line -->',                                                   'directly below this line -->\n\{\{' +                                                    mw.config.get('wgPageName') + '\}\}'); });

var editData = { action: "edit", format: "json", token: etoken, summary: "Listed " + mw.config.get('wgPageName') + ". " + delsortTag, title: 'Wikipedia:WikiProject Deletion sorting/' + cat, text: window.editContent };

$.each(editData, function (i, v) {                               console.log(i, "=", v);                            });

$.post('//en.wikipedia.org/w/api.php',                                   editData,                                    function (data) {                                        jQuery.each(data, function(index, value) { console.log("index", index, "value", value); });                                   });                            alert('Delsort complete.'); });               }            }        }    }

function delsortIt { var cat = prompt("Category: "); if (cat != null) { doDelsort(cat); } else { alert("Delsort cancelled."); }   }

function defineLink(category) { var link = mw.util.addPortletLink("pt-delsort", "#", "Sort: " + category); $(link).click(function(e) {           e.preventDefault;            doDelsort(category);        }); }

mw.util.addPortletLink('p-cactions', 'javascript:delsortIt', 'Delsort', 'pt-delsort', 'Perform deletion sorting');

defineLink("Academics and educators"); defineLink("Actors and filmmakers"); defineLink("Albums and songs"); defineLink("Australia"); defineLink("Authors"); defineLink("Bands and musicians"); defineLink("Business"); defineLink("Businesspeople"); defineLink("California"); defineLink("Christianity"); defineLink("Cuba"); defineLink("England"); defineLink("Fictional elements"); defineLink("Film"); defineLink("Food and drink"); defineLink("Football"); defineLink("India"); defineLink("Internet"); defineLink("Martial arts"); defineLink("Music"); defineLink("New York"); defineLink("Organizations"); defineLink("People"); defineLink("Politicians"); defineLink("Software"); defineLink("Sportspeople"); defineLink("Television"); defineLink("United Kingdom"); defineLink("United States of America"); defineLink("Websites"); }