Okay, well this has been a contentious debate but in the spirit of Friday, and the Friday opening a long weekend (here in the US anyway) I propose the following solution, which I hereby make Community Wiki so those jQuery experts out there can improve it:
To add support for the /me
command, if you so choose, bookmark the following:
javascript: var meRe=/^\/me .*$/;var doMe=function() { $('div.message').each(function() {var c=$(this).find('div.content');if(c.length && meRe.test(c[0].innerHTML)){var a=c[0].innerHTML.substr(3);var uc=c.parents('div.user-container');if(uc.find(".message").length>1){c.remove();uc=$('<div class="'+uc[0].className+'"></div>').append(uc.find("div.signature").clone()).append('<div class="message">'+a+'</div>').insertAfter(uc);}else{c.parents(".message").unwrap().html(a); }uc.css("font-style","italic").find('div.signature').children(".avatar,.username,.flair").hide().end().find(".tiny-signature").css("padding",0).show().find(".avatar").hide();}})};void(window.setInterval(doMe, 500))
Then, when in a chat room, open that bookmarklet and all /me
messages will be (very crudely) rewritten.
If you prefer greasemonkey (or the Chrome / Opera equivalent), then you get the luxury of a script that doesn't have to all fit on one line:
// ==UserScript==
// @name So Do Me
// @namespace http://shog9.com/greasemonkey/scripts
// @description Attractive display for comments prefixed with /me on SO Chat
// @version 1.1
// @include http://chat.meta.stackexchange.com/rooms/*
// @include http://chat.stackexchange.com/rooms/*
// ==/UserScript==
var script = document.createElement("script");
script.textContent = "(" + grease.toString() + ")()";
document.body.appendChild(script);
function grease()
{
var meRe = /^\/me .*$/;
var doMe = function ()
{
$('div.message').each(function ()
{
var c = $(this).find('div.content');
if (c.length && meRe.test(c[0].innerHTML))
{
var a = c[0].innerHTML.substr(3);
var uc = c.parents('div.user-container');
if ( uc.find(".message").length > 1 )
{
c.remove();
uc = $('<div class="' + uc[0].className + '"></div>')
.append(uc.find("div.signature").clone())
.append('<div class="message">' + a + '</div>')
.insertAfter(uc);
}
else
{
c.parents(".message").unwrap().html(a);
}
uc.css("font-style", "italic")
.find('div.signature')
.children(".avatar,.username,.flair")
.hide().end()
.find(".tiny-signature")
.css("padding",0)
.show()
.find(".avatar")
.hide();
}
})
};
window.setInterval(doMe, 500);
}
And if anyone wants to roll this code into the real system, feel free! Happy Friday...