Skip to content

Instantly share code, notes, and snippets.

@GMMan
Last active August 29, 2015 14:16
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/90fd4731859ebb26c072 to your computer and use it in GitHub Desktop.
Save GMMan/90fd4731859ebb26c072 to your computer and use it in GitHub Desktop.
Add bundle chat to active bundle pages on Groupees

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:

addChatTab=function(b,d,g){for(var a=Object.keys(chatBoxer.chats),c,e=0;e<a.length;++e){var f=chatBoxer.chats[a[e]];if("common"===f.type){c=f.el;break}}a=c.clone();c=c.prev().clone();c.attr("data-chat-id",b);c.find(".caption").html(g);a.attr("id","chat-"+b);a.attr("class","chat");a.attr("data-channel","/bundles/"+d);a.attr("data-id",b);a.find("form").attr("action","/chats/"+b+"/messages");a.find(".log").empty();d=c.prop("outerHTML")+"\n"+a.prop("outerHTML");chatBoxer.addPrivateChat(d);b=chatBoxer.chats[b];b.type="custom";b.subscribe();b.type="common";return d};

and press Enter. Next, go to the bundle you want to copy the chat tab from, and open a JavaScript console. Enter this:

(function(){var a=$(".chat.currentPage"),b=a.data("id"),c=a.data("channel").replace("/bundles/",""),a=a.prev().find(".caption").html();return"addChatTab("+b+", "+c+", '"+a+"');"})();

The console will display the command you need to type in the first (active bundle) page. Do that, and the chat from the bundle you wanted to copy from will appear as a tab in your chat box.

addChatTab = function(id, bundleId, name)
{
// Get a chat tab. Grab the last one, pretty much guaranteed to be a common tab
var cbKeys = Object.keys(chatBoxer.chats);
var el;
for (var i = 0; i < cbKeys.length; ++i)
{
var c = chatBoxer.chats[cbKeys[i]];
if (c.type === 'common')
{
el = c.el;
break;
}
}
var clonedEl = el.clone();
var tabSpan = el.prev().clone();
// Update tab
tabSpan.attr('data-chat-id', id);
tabSpan.find('.caption').html(name);
// Update cloned element
clonedEl.attr('id', 'chat-' + id);
clonedEl.attr('class', 'chat');
clonedEl.attr('data-channel', '/bundles/' + bundleId);
clonedEl.attr('data-id', id);
// Update form
clonedEl.find('form').attr('action', '/chats/' + id + '/messages');
// Clear cloned tab's innards
clonedEl.find('.log').empty();
// Add to chatBoxer
var finalHtml = tabSpan.prop('outerHTML') + '\n' + clonedEl.prop('outerHTML');
chatBoxer.addPrivateChat(finalHtml);
// Change chat type and subscribe
var chat = chatBoxer.chats[id];
chat.type = 'custom';
chat.subscribe();
chat.type = 'common';
return finalHtml;
};
getAddTabCommand = function()
{
var cp = $('.chat.currentPage')
var a = cp.data('id')
var b = cp.data('channel').replace('/bundles/', '')
var c = cp.prev().find('.caption').html()
return 'addChatTab(' + a + ', ' + b + ', \'' + c + '\');';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment