Skip to content

Instantly share code, notes, and snippets.

@rlemon
Last active August 29, 2015 14:11
Show Gist options
  • Save rlemon/9eda798ca5c0fdbeeb3f to your computer and use it in GitHub Desktop.
Save rlemon/9eda798ca5c0fdbeeb3f to your computer and use it in GitHub Desktop.
SO Chat room KeepAlive Plus
// ==UserScript==
// @name SO Chat room KeepAlive Plus
// @author Robert Lemon
// @version 0.0.3
// @namespace
// @description make rooms not die
// @include http://chat.stackoverflow.com/rooms/*
// @include http://chat.stackexchange.com/rooms/*
// @include http://chat.meta.stackexchange.com/rooms/*
// ==/UserScript==
(function() {
var roomID = 1; // the room you are targeting
var messageTime = '59 59 23'; // seconds minutes hours
var parts = messageTime.split(' ');
var endTime = getEndTime();
ticker(); // start the ticker
// returns todays date at the specified time from `messageTime`
function getEndTime() {
var time = new Date();
// the days are the same. increment the `time` by one day
// to prevent spam we should not allow this to trigger more than once a day
if ( endTime && time.getDate() === endTime.getDate() ) {
time.setDate(time.getDate()+1);
}
time.setHours(parts[2]);
time.setMinutes(parts[1]);
time.setSeconds(parts[0]);
console.log( 'SO Chat room KeepAlive Plus' );
console.log( 'new end time', time )
return time;
}
function ticker() {
if( Date.now() >= endTime ) {
endTime = getEndTime();
$.post('/chats/' + roomID + '/messages/new',{ text : 'this is an automated message. ' + (new Date()), fkey: fkey({}).fkey })
}
setTimeout(ticker, 500);
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment