Skip to content

Instantly share code, notes, and snippets.

@rlemon
Last active August 29, 2015 14:07
Show Gist options
  • Save rlemon/a9faa107b4f39e65c3ca to your computer and use it in GitHub Desktop.
Save rlemon/a9faa107b4f39e65c3ca to your computer and use it in GitHub Desktop.
SO Chatbot Auto remove command
(function() {
"use strict";
var chat = document.getElementById('chat');
function parseNode(node) {
if (node.classList && node.classList.contains('message') && !node.classList.contains('pending')) {
if( $(node).parents('.mine').length ) {
var prefix = $(node).find('.content').text().slice(0,3);
if( prefix !== '!!>' && prefix.indexOf('!!') === 0 ) {
// testing shows this needs a timeout to be reliable.
setTimeout(function() { $.post('/messages/' + node.id.split('-')[1] + '/delete', fkey()) }, 10);
}
}
}
}
[].forEach.call(chat.querySelectorAll('.user-container .message'), parseNode);
new MutationObserver(function(records) {
records.forEach(function(record) {
[].forEach.call(record.addedNodes, parseNode);
});
}).observe(chat, {
childList: true,
subtree: true
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment