Fetch `fkey` from localStorage

This commit is contained in:
Glorfindel 2017-07-27 15:50:06 +02:00
parent 1e39b80f35
commit aa99dc9356
1 changed files with 17 additions and 24 deletions

View File

@ -3,7 +3,7 @@
// @namespace https://github.com/Glorfindel83/ // @namespace https://github.com/Glorfindel83/
// @description Adds a 'Destroy spammer' link for moderator on user profiles with only deleted posts. // @description Adds a 'Destroy spammer' link for moderator on user profiles with only deleted posts.
// @author Glorfindel // @author Glorfindel
// @version 0.1 // @version 0.2
// @match *://*.stackexchange.com/users/* // @match *://*.stackexchange.com/users/*
// @match *://*.stackoverflow.com/users/* // @match *://*.stackoverflow.com/users/*
// @match *://*.superuser.com/users/* // @match *://*.superuser.com/users/*
@ -40,32 +40,25 @@
// Create Destroy link // Create Destroy link
var destroyLink = document.createElement('a'); var destroyLink = document.createElement('a');
var attribute = document.createAttribute("href");
attribute.value = "#";
destroyLink.setAttributeNode(attribute);
destroyLink.appendChild(document.createTextNode('Destroy spammer')); destroyLink.appendChild(document.createTextNode('Destroy spammer'));
destroyLink.onclick = function () { destroyLink.onclick = function () {
// 'Open' moderator menu // Ask for confirmation
$.get({ if (window.confirm('Are you sure?')) {
url: 'https://apple.stackexchange.com/admin/users/' + userID + '/moderator-menu?_=', $.post({
cache: false, url: 'https://apple.stackexchange.com/admin/users/' + userID + '/destroy',
success: function (html) { data: 'annotation=&deleteReasonDetails=&mod-actions=destroy&destroyReason=This+user+was+created+to+post+spam+or+nonsense+and+has+no+other+positive+participation&destroyReasonDetails=&fkey=' + window.localStorage["se:fkey"].split(",")[0],
// Find key success: function (data) {
var fkey = ($($.parseHTML(html)).find('input[name=fkey]').attr('value')); // Reload page
window.location.reload();
// Ask for confirmation },
if (window.confirm('Are you sure?')) { error: function (jqXHR, textStatus, errorThrown) {
$.post({ console.log('Error: ' + textStatus + ' ' + errorThrown);
url: 'https://apple.stackexchange.com/admin/users/' + userID + '/destroy',
data: 'annotation=&deleteReasonDetails=&mod-actions=destroy&destroyReason=This+user+was+created+to+post+spam+or+nonsense+and+has+no+other+positive+participation&destroyReasonDetails=&fkey=' + fkey,
success: function (data) {
// Reload page
window.location.reload();
},
error: function (jqXHR, textStatus, errorThrown) {
console.log('Error: ' + textStatus + ' ' + errorThrown);
}
});
} }
} });
}); }
}; };
// Add to document // Add to document