Skip to content

Instantly share code, notes, and snippets.

@evilmarty

evilmarty/userscript.js

Last active Dec 21, 2015
Embed
What would you like to do?
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