Skip to content

Instantly share code, notes, and snippets.

@rlemon
Last active December 15, 2015 06:29
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlemon/e2ff662e4731ecf81a95 to your computer and use it in GitHub Desktop.
Save rlemon/e2ff662e4731ecf81a95 to your computer and use it in GitHub Desktop.
bulk trash
// ==UserScript==
// @name BULK TRASH
// @author Robert Lemon
// @version 1.0
// @namespace
// @description Adds a bulk trash button to the chat.
// @include http://chat.stackoverflow.com/rooms/*
// ==/UserScript==
function exec(fn) {
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = '(' + fn + ')();';
document.body.appendChild(script); // run the script
}
exec(function() {
var btn = $('<button class="button">Bulk Trash</button>'),
room = document.forms[0].elements.room.value;
btn.on('click', function() {
var modal = $('<div><h4>Trash Who?</h4></div>'),
$users = $('#present-users:not(.more)').clone();
modal.append($users).addClass('popup room-popup').css({
bottom: btn.position().top,
left: btn.position().left
}).on('click', function(e) {
if (confirm("Would you like to trash all posts by " + e.target.title)) {
var id = $(e.target).closest('li').prop('id').split('-')[2],
all = [];
$('.user-' + id + '.monologue .message').each(function() {
all.push(this.id.split('-')[1]);
});
$.post("/admin/movePosts/" + room, fkey({
ids: all.join(','),
to: 23262
}));
modal.remove();
}
return false;
});
$(document.body).append(modal);
return false;
});
$('#chat-buttons').append(btn);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment