Skip to content

Instantly share code, notes, and snippets.

@rlemon
Last active August 29, 2015 14:17
Show Gist options
  • Save rlemon/4de02f623170987c690f to your computer and use it in GitHub Desktop.
Save rlemon/4de02f623170987c690f to your computer and use it in GitHub Desktop.
(function() {
"use strict";
// setup
var phrase = "java script";
var chat = document.getElementById('chat'),
room = document.forms[0].elements.room.value;
new MutationObserver(function(records) {
records.forEach(function(record) {
[].forEach.call(record.addedNodes, function parseNode(node) {
if (node.classList && node.classList.contains('message') && !node.classList.contains('pending')) {
var re = new RegExp(phrase, "gi");
var mText = node.textContent;
var offender = node.parentNode.parentNode.querySelector('.username').textContent;
if (re.test(mText)) {
var id = node.id.split('-')[1];
$.post("/admin/movePosts/" + room, fkey({
ids: [id],
to: 23262
})).done(function() {
setTimeout(function() {
var mid = [].slice.call(document.querySelectorAll('.user-container.mine .messages .message')).pop().id.match(/(\d+)/)[0];
console.log('postback', id);
if (!mid) return; // so I don't blow up. this should never fail tho.
$.post('/messages/' + mid, {
text: offender + ' meant to say: ' + mText.replace(re, 'JavaScript'),
fkey: fkey().fkey
});
}, 3000);
}).error(function() {
setTimeout(parseNode.bind(null,node), 2000);
});
}
}
});
});
}).observe(chat, {
childList: true,
subtree: true
});
}());
@rlemon
Copy link
Author

rlemon commented Mar 13, 2015

still a work in progress. doesn't catch every one... should be using websockets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment