For those who go to The 2nd Monitor chatroom, you already know how bad I am at remembering everything. And, sometimes, the new visitors will wonder what something means.
For that, I've developed a very simple chat translator.
;(function(window, undefined){
'use strict';
var memes = {
'zombie': {
'title': 'Unanswered question (or with answers without upvotes)',
'href': 'http://meta.codereview.stackexchange.com/a/1511/',
'find': new RegExp('(zombie)','gi')
},
'Jamalized': {
'title': 'Being Jamalized means that Jamal edited your question/answer',
'href': 'http://meta.codereview.stackexchange.com/a/1675/',
'find': new RegExp('(jamalized)','gi')
},
'TS': {
'title': 'Theoretical Star (star it and say "RSA")',
'href': 'http://meta.codereview.stackexchange.com/a/1526/',
'find': new RegExp('(TS)','g')
},
'RSA': {
'title': 'Real Star Applied (you say it after staring a message with "TS")',
'href': 'http://meta.codereview.stackexchange.com/a/1526/',
'find': new RegExp('(RSA)','g')
},
'Thanks, Santa!': {
'title': 'When someone upvotes a post, and you don\'t know who, just say this',
'href': 'http://meta.codereview.stackexchange.com/a/1526/'
},
'IWNPFETTOLAI': {
'title': 'I will not provide further explanation than this overly long acronym itself',
'href': 'http://meta.codereview.stackexchange.com/a/1673/'
},
'Monking': {
'title': 'A greeting to the Monkey doing his monkey-business',
'href': 'http://meta.codereview.stackexchange.com/a/1678/',
'find': new RegExp('(monk(?:ing|ernoon|evening|night))','gi')
},
'TTQW': {
'title': 'Time To Quit Work',
'href': 'http://meta.codereview.stackexchange.com/a/1643/'
},
'TTGH': {
'title': 'Time To Go Home',
'href': 'http://meta.codereview.stackexchange.com/a/1643/'
},
'TTGTB': {
'title': 'Time To Go To Bed',
'href': 'http://meta.codereview.stackexchange.com/a/1643/'
},
'STM': {
'title': 'Smoking The Documentation',
'href': 'http://meta.codereview.stackexchange.com/a/1953/'
},
'overengineering': {
'title': 'A case of when something has become overly-engineered',
'href': 'http://meta.codereview.stackexchange.com/a/2520/'
},
'HOLY CARP': {
'title': 'Probably HOLY CRAP misspelled',
'href': 'http://meta.codereview.stackexchange.com/a/4928/'
},
'Malachi\'d': {
'title': 'Something amusing or entertaining that hasn\'t been starred yet',
'href': 'http://meta.codereview.stackexchange.com/a/1667/'
},
'JDQ': {
'title': 'JavaDeveloper Question',
'href': 'http://meta.codereview.stackexchange.com/a/2053/'
}
},
translate = function(){
var messages = document.querySelectorAll('#chat .message:not([data-checked="1"])'),
fragment = document.createDocumentFragment(),
tmp_content = document.createElement('div');
if( messages && messages.length )
{
for(var i = 0, l = messages.length; i < l; i++)
{
var message = messages[i];
message.setAttribute('data-checked', '1');
var content = message.querySelector('.content');
if( content && !content.firstChild.className || content.firstChild.className.indexOf('onebox') === -1 )
{
tmp_content.innerHTML = content.innerHTML;
for(var meme in memes)
{
var html = '';
for(var j = 0, m = tmp_content.childNodes.length; j < m; j++)
{
//text nodes only
if( tmp_content.childNodes[j].nodeType === 3 )
{
if( memes[meme].find )
{
html += tmp_content
.childNodes[j]
.nodeValue
.replace(memes[meme].find, '<a href="' +
( memes[meme].href || '#' ) +
'" target="_blank" title="' +
( memes[meme].title || '' ) +
'" style="color:inherit;border-bottom:1px dashed #000">$1</a>'
);
}
else
{
html += tmp_content
.childNodes[j]
.nodeValue
.replace(meme, '<a href="' +
( memes[meme].href || '#' ) +
'" target="_blank" title="' +
( memes[meme].title || '' ) +
'" style="color:inherit;border-bottom:1px dashed #000">'+
meme+
'</a>'
);
}
}
else if( tmp_content.childNodes[j].nodeType !== 8 )
{
html += tmp_content.childNodes[j].outerHTML;
}
}
tmp_content.innerHTML = html;
}
content.innerHTML = tmp_content.innerHTML;
}
}
}
}
translate();
setInterval(translate, 5000);
})(Function('return this')());
The idea is that the chat will be augmented, in a certain way, to add meanings to certain words or sentences.
Those will have a link and a descriptive title.
To run it, simply fire the console. Every 5 seconds, the chat will be scraped in search of new messages.
In terms of clarity and content, what can I change or improve?
'Probably HOLY CRAP misppelled'
: should be misspelt \$\endgroup\$misspelled
vsmisspellt
is a US vs UK English distinction. ( dictionary.cambridge.org/dictionary/british/misspell ). \$\endgroup\$