User:Walrus068/cat delete.js

function delete_cat_members(category, reason) { "use strict"; var xhr = new XMLHttpRequest, token = encodeURIComponent(mw.user.tokens.get('editToken')), //delete token is the same api = mw.config.get('wgScript') + "?format=json"; reason = encodeURIComponent(reason);

xhr.open("GET", api, "&action=query&list=categorymembers&cmtitle=" +		encodeURIComponent(category)); xhr.onload = function { var i, e, member, xhr, members = JSON.parse(this.responseText).query.categorymembers, onload = function { if (this.responseText.indexOf("error") !== -1) { e = JSON.parse(this.responseText).error; prompt(e.code + ":\n" + e.info); }			};

for (i = 0; i < members.length; i += 1) { member = members[i]; xhr = new XMLHttpRequest; xhr.open("POST", api, false); //yes i want to block xhr.onload = onload; xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send("action=delete&pageid=" + member.pageid + "&token=" + token + "&reason=" + reason); }	};	xhr.send; }