Created
November 25, 2009 16:35
-
-
Save jackregnart/242857 to your computer and use it in GitHub Desktop.
Chatrbox Fluid Userscript
This file contains hidden or 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
// ==UserScript== | |
// @name Chatrbox | |
// @namespace http://chatrboxapp.com | |
// @description Simple Badge Icon script for Chatrbox | |
// @include * | |
// @author http://twitter.com/jackregnart | |
// ==/UserScript== | |
(function () { | |
if(window.fluid) { | |
var lastGrowl; | |
var loggedInAt = new Date(); | |
function checkForMessages() { | |
var pageTitle = document.title | |
// Get message count from page title | |
getMessages = pageTitle.match(/Chatrbox - \((\d+)\)/) | |
// If there are new messages get them or set to 0 | |
newMessages = (getMessages == null) ? 0 : getMessages[1] | |
// Update fluid badge | |
window.fluid.dockBadge = (newMessages == 0) ? '' : newMessages; | |
// Now to figure out how to check for @replies | |
// Find message container | |
message = $('.messages_container div.highlight:last') | |
console.log(message) | |
posted = $('abbr', message).attr('title') | |
// Was this here when we logged in? | |
if(replyInPast(posted)) { | |
// Get message id | |
at_reply = message.attr('id') | |
// Find message | |
message = $('p', message).text() | |
// Find length to shorten string with | |
length = (message.length - 5) | |
// Remove Reply from message | |
message = message.substring(0, length) | |
// If this is a new @ do a growl | |
if(at_reply != lastGrowl) { | |
fluid.showGrowlNotification({ | |
title: "Chatrbox : Unread Message", | |
description: message, | |
priority: 0, | |
sticky: false | |
}); | |
// Remember last growl | |
lastGrowl = at_reply | |
} | |
} | |
} | |
function replyInPast(posted) { | |
date = posted.split(/-/) | |
time = date[2].split(/T/) | |
days = time[0] | |
time = time[1].substring(0, 8).split(/:/) | |
// Get this horrific date thing over with. | |
date = new Date(date[0], (parseInt(date[1])-1), days, time[0], time[1], time[2]) | |
if(date >= loggedInAt) { | |
return true; | |
} else { return false; } | |
} | |
// Repeat every 5 seconds | |
window.setInterval(function(){checkForMessages();}, 5 * 1000); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment