-
-
Save rlemon/4de02f623170987c690f to your computer and use it in GitHub Desktop.
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"; | |
// 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 | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
still a work in progress. doesn't catch every one... should be using websockets.