Last active
August 29, 2015 14:07
-
-
Save rlemon/a9faa107b4f39e65c3ca to your computer and use it in GitHub Desktop.
SO Chatbot Auto remove command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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