Last active
August 29, 2015 14:27
-
-
Save rlemon/37933f0e58efb650a6f0 to your computer and use it in GitHub Desktop.
stupid converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NodeList.prototype[Symbol.iterator] = [][Symbol.iterator]; | |
const remap = { | |
'pls|plz' : 'please', | |
'halp' : 'help', | |
'u' : 'you', | |
'r' : 'are', | |
'totes' : 'totally', | |
// 'ur' : 'you are', // this could be problematic, ur could also be your | |
'iz' : 'it is', | |
'tnx|thx' : 'thanks', | |
'ppl' : 'people', | |
'bc' : 'because', | |
'b4' : 'before', | |
'i' : 'I', | |
'i\'m' : 'I\'m', | |
'alot' : 'a lot', | |
'yw' : 'you\'re welcome', | |
'k' : 'okay', | |
'thats' : 'that\'s', | |
'whats' : 'what\'s', | |
'txt' : 'text', | |
'y' : 'why', | |
'bcoz' : 'because', | |
'awsm' : 'awesome', | |
'rly' : 'really', | |
'gonna' : 'going to', | |
'isnt' : 'isn\'t', | |
'i c' : 'I see', | |
}; | |
const parseTextNodes = (container, callback) => { | |
let recurse = (node = container) => { | |
for (let n of node.childNodes) { | |
recurse(n); | |
} | |
if (node.nodeType === Node.TEXT_NODE && node.nodeValue !== '') { | |
callback(node); | |
} | |
}; | |
return recurse; | |
}; | |
const parseNode = node => { | |
if (node.classList && node.classList.contains('message')) { | |
for( let message of node.querySelectorAll('.content')) { | |
parseTextNodes(message, tNode => { | |
tNode.textContent = tNode.textContent.split(' ').map(w => { | |
// okay I need to return the original word or the replacement | |
for( let key in remap ) { | |
for( let k of key.split('|') ) { | |
if( w.toLowerCase() === k ) { | |
return remap[key]; | |
} | |
} | |
} | |
return w; | |
}).join(' '); | |
})(); | |
}; | |
} | |
}; | |
for(let node of document.querySelectorAll('#chat .message')) parseNode(node); | |
new MutationObserver(records => records.forEach(record => [].forEach.call(record.addedNodes, parseNode))).observe(chat, { | |
childList: true, | |
subtree: true | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment