Skip to content

Instantly share code, notes, and snippets.

@GMMan
Last active August 29, 2015 14:17
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 GMMan/6e17b340355dfc79d50c to your computer and use it in GitHub Desktop.
Save GMMan/6e17b340355dfc79d50c to your computer and use it in GitHub Desktop.
Chat pinger for Groupees Chat

To use this code, first go on your active bundle page, and open a JavaScript console. On Firefox, it's Ctrl-Shift-K, while on Chrome it's Ctrl-Shift-J. Then paste in this line:

ChatPinger=function(){var b=this,d,e=[];this.notifyMyOwn=this.muted=!1;this.notifyActiveTab=!0;this.notifyActions=!1;this.play=function(){this.muted||d.play()};this.setSound=function(a){d=new Howl({urls:[a]})};var f=function(a){a=$.parseJSON(a).message;!a||"action"==a.kind&&!b.notifyActions||!b.notifyActiveTab&&a.chat_id==chatBoxer.prevChatId||!b.notifyMyOwn&&"regular"==a.kind&&a.user&&parseInt($(chatBox).data("user"))==a.user.id||b.play()};this.setSound("https://dl.dropboxusercontent.com/u/29365870/ding.wav");$(".chat").each(function(a,b){var c=$(this).data("channel");if(-1!=$.inArray(c,e))return!0;faye.subscribe(c,f);e.push(c)})};pinger=new ChatPinger;

and press Enter.

There are a few options you can set (square brackets indicate default value):
pinger.muted = true|[false] - Don't ping
pinger.notifyMyOwn = true|[false] - Ping when your own message gets sent
pinger.notifyActiveTab = [true]|false - Ping even when messages appear in your current chat tab
pinger.notifyActions = true|[false] - Ping when some gets chat powers applied to them

You can also set your own ping sound by typing pinger.setSound('url'), where url is the address of a sound file.

Warning: Current ping sound is fairly loud.

ChatPinger = function()
{
var that = this;
var audioUrl;
var howler;
var subscribed = [];
this.muted = false;
this.notifyMyOwn = false;
this.notifyActiveTab = true;
this.notifyActions = false;
this.play = function()
{
if (this.muted) return;
howler.play();
}
this.setSound = function(url)
{
audioUrl = url;
howler = new Howl({ urls: [ url ] });
}
var fayeCallback = function(message)
{
var o = $.parseJSON(message);
var msg = o.message;
if (!msg) return;
if (msg.kind == 'action' && !that.notifyActions) return;
if (!that.notifyActiveTab && msg.chat_id == chatBoxer.prevChatId) return;
if (!that.notifyMyOwn && msg.kind == 'regular' && msg.user && (parseInt($(chatBox).data('user')) == msg.user.id)) return;
that.play();
};
this.setSound('https://dl.dropboxusercontent.com/u/29365870/ding.wav');
// Easiest if I subscribe to messages myself
$('.chat').each(function (ind, obj)
{
var channel = $(this).data('channel');
if ($.inArray(channel, subscribed) != -1) return true;
faye.subscribe(channel, fayeCallback);
subscribed.push(channel);
});
}
pinger = new ChatPinger();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment