Skip to content

Instantly share code, notes, and snippets.

@rlemon
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlemon/9eeb9fb09578d230cd75 to your computer and use it in GitHub Desktop.
Save rlemon/9eeb9fb09578d230cd75 to your computer and use it in GitHub Desktop.
ping bot
(function() {
"use strict";
var pingWho = "@username";
var pingMessage = " edit ping script";
var pingDelay = 1000;
var length = pingMessage.length;
var pos = 0;
var roomId = Number(/\d+/.exec(location)[0]);
send('/chats/' + roomId + '/messages/new')
.done(function() {
setTimeout(function() {
var id = [].slice.call(document.querySelectorAll('.user-container.mine .messages .message')).pop().id.match(/(\d+)/)[0];
edit('/messages/' + id);
}, 2000);
});
function send(destination) {
return $.ajax({
type: "POST",
url: destination,
data: {
fkey: fkey().fkey,
text: pingWho + ' ' + pingMessage.substr(0, pos)
}
});
}
function edit(destination) {
send(destination).fail(function() {
setTimeout(function() {
edit(destination);
}, pingDelay);
}).done(function() {
pos++;
if (pos <= length) {
setTimeout(function() {
edit(destination);
}, pingDelay);
}
});
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment