User:Jim Carter/deletion sorting app.js

function defineLink(category){ mw.util.addPortletLink('pt-delsort', 'javascript:doDelsort("' + category + '")', category, ''); } if (wgPageName.indexOf('Wikipedia:Articles_for_deletion/') != -1 && wgPageName.indexOf('Wikipedia:Articles_for_deletion/Log/201') == -1) { mw.util.addPortletLink ('p-cactions', 'javascript:delsortIt', 'Delsort', 'pt-delsort', 'Perform deletion sorting'); defineLink("People");defineLink("Academics and educators"); defineLink("Actors and filmmakers");defineLink("Military");defineLink("Crime"); defineLink("Events");defineLink("Fashion");defineLink("Authors"); defineLink("Bands and musicians");defineLink("Businesspeople"); defineLink("Politicians");defineLink("Sportspeople"); defineLink("Organizations");defineLink("Football");defineLink("Martial arts"); defineLink("Albums and songs");defineLink("Television");defineLink("Music"); defineLink("Film");defineLink("United States of America"); defineLink("New York");defineLink("California");defineLink("United Kingdom"); defineLink("England");defineLink("India");defineLink("Christianity"); defineLink("Fictional elements");defineLink("Business");defineLink("Software"); defineLink("Internet");defineLink("Websites");defineLink("Australia"); } function delsortIt{x = prompt("Category: ");if (x !=null){doDelsort(x);} else{alert('Deletion sorting terminated!');}} function doDelsort(cat){ 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: "Added Deletion sort and enlisting at DELETION SORTING under " + cat + " (using nothing)", 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 );});}); $.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: "enlisting " + mw.config.get('wgPageName') + " (using Yet another handy tool for sorting)", 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('Deletion sorting completed successfully!.'); } ); } } } }