Skip to content

Instantly share code, notes, and snippets.

@Yantrio
Created April 1, 2016 18:04
Show Gist options
  • Save Yantrio/7adbf9a7007149e30eab6735489dd3f3 to your computer and use it in GitHub Desktop.
Save Yantrio/7adbf9a7007149e30eab6735489dd3f3 to your computer and use it in GitHub Desktop.
var postMessage = function(message) {
$("#robinSendMessage .c-form-control").val(message);
$("#robinSendMessage").submit();
}
function report() {
var textBox = $("#robinSendMessage .c-form-control");
var novote = $(".robin--vote-class--novote").length;
var abandon = $(".robin--vote-class--abandon").length;
var stay = $(".robin--vote-class--continue").length;
var grow = $(".robin--vote-class--increase").length;
var total = $(".robin-room-participant").length;
var output = `${howLongLeft()} Mins reamining. Status(Total:${total}): No-Vote:${novote}, Abandon:${abandon}, Stay:${stay}, Grow:${grow}`;
postMessage(output);
}
function howLongLeft() {
var remainingMessageContainer = $(".robin--user-class--system:contains('approx')");
var message = $(".robin-message--message", remainingMessageContainer).text();
var timestamp = $(".robin-message--timestamp",remainingMessageContainer).text();
var endTime = addMins(parseTime(timestamp),message.match(/\d+/)[0])
return Math.floor((endTime - new Date())/60/1000);
//grab the timestamp from the first post and then calc the difference using the estimate it gives you on boot
}
function addMins(date,mins) {
var newDateObj = new Date(date.getTime() + mins*60000);
return newDateObj;
}
function parseTime(timeStr, dt) {
if (!dt) {
dt = new Date();
}
var time = timeStr.match(/(\d+)(?::(\d\d))?\s*(p?)/i);
if (!time) {
return NaN;
}
var hours = parseInt(time[1], 10);
if (hours == 12 && !time[3]) {
hours = 0;
}
else {
hours += (hours < 12 && time[3]) ? 12 : 0;
}
dt.setHours(hours);
dt.setMinutes(parseInt(time[2], 10) || 0);
dt.setSeconds(0, 0);
return dt;
}
setInterval(function(){
report();
}, 30000);
setInterval(function() {
$("#robinChatWindow").scrollTop(1E10);
},500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment