Created
September 24, 2014 23:20
-
-
Save CS1000/7d9826ab0d9f72bfec82 to your computer and use it in GitHub Desktop.
Bro Script (so chat)
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
Paste in SO chat room console bro: | |
(function() { | |
"use strict"; | |
var chat = document.getElementById('chat'); | |
function parseNode(node) { | |
if (node.classList | |
&& node.classList.contains('message') | |
&& !node.classList.contains('pending') | |
&& !node.querySelector('.onebox') | |
&& !node.querySelector('pre') | |
) { | |
var regex = /((?:^|\s*)(?:[a-z'-]+))([\?\!\.]+$|[\?\!\.]+\s|\s*:.|\s*$)/gi; | |
node.textContent = node.textContent.replace(regex, '$1 bro$2'); | |
} | |
} | |
[].forEach.call(chat.querySelectorAll('.user-container .message'), parseNode); | |
new MutationObserver(function(records) { | |
records.forEach(function(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