Skip to content

Instantly share code, notes, and snippets.

@evilmarty
Last active December 21, 2015 20:29
Show Gist options
  • Save evilmarty/6361156 to your computer and use it in GitHub Desktop.
Save evilmarty/6361156 to your computer and use it in GitHub Desktop.
Campfire avatar userscript
// ==UserScript==
// @name Campfire Avatar
// @namespace http://firefromthefly.com
// @version 0.1
// @description Adds peoples avatars to the chatroom.
// @match https://*.campfirenow.com/room/*
// @copyright 2012+, You
// ==/UserScript==
var insertMessages = Campfire.Transcript.prototype.insertMessages;
function addAvatar(author) {
if (author.dataset.avatar) {
var html = ['<div class="avatar"><img height="32" src="', author.dataset.avatar, '" alt=""></div>'].join('');
author.insertAdjacentHTML('beforeend', html);
}
}
Campfire.Transcript.prototype.insertMessages = function() {
var messages = insertMessages.apply(this, arguments);
messages.forEach(function(message) {
if (message.kind === 'text') {
addAvatar(message._author);
}
});
return messages;
};
var style = document.createElement('style');
style.textContent = '.avatar{text-align:right;margin-top:5px;} .avatar img{border-radius:50%;box-shadow:0 1px 0 rgba(255, 255, 255, 0.5);}';
document.head.appendChild(style);
[].slice.call(document.querySelectorAll('.text_message .author[data-avatar]')).forEach(function(el) {
addAvatar(el);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment