Skip to content

Instantly share code, notes, and snippets.

@rlemon
Created September 24, 2014 19:58
Show Gist options
  • Save rlemon/ab7117b9c872480d737d to your computer and use it in GitHub Desktop.
Save rlemon/ab7117b9c872480d737d to your computer and use it in GitHub Desktop.
broscript
(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') ) {
node.textContent = node.textContent.replace(/[\s\!\?\.]+$/, '') + ', bro.';
}
}
[].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
});
}());
@CS1000
Copy link

CS1000 commented Sep 24, 2014

Now with more sugar 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') ) {
            node.textContent = node.textContent.replace(/((?:^|\s*)(?:[a-z'-]+))([\?\!\.]+$|[\?\!\.]+\s|\s*:.|\s*$)/gi, '$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
    });
}());

EDIT: Updated RegEx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment