Created
October 21, 2015 17:39
-
-
Save bananu7/2b0351b74eba685c1534 to your computer and use it in GitHub Desktop.
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
//if (hljs) console.log("HLJS OK"); | |
function messageObserverCb(evts) { | |
evts.forEach(function(evt) { | |
for (var i = 0; i < evt.addedNodes.length; i++) { | |
var monologueMsg = evt.addedNodes[i]; | |
if (!monologueMsg) return; | |
// for each added message in a monologue, colour its blocks | |
$(monologueMsg).children('pre').each(function(i, block) { | |
hljs.highlightBlock(block); | |
}); | |
} | |
}); | |
} | |
function mainChatObserverCb(evts) { | |
evts.forEach(function(evt) { | |
var userContainer = evt.addedNodes[0]; | |
if (!userContainer) return; | |
var msg = $(userContainer).children("div.messages").first().get(); | |
console.log(msg[0]); | |
var msgObserver = new MutationObserver(messageObserverCb).observe(msg[0], { childList: true }); | |
// Remove the observer after 5 minutes, where no edits can be made anymore | |
// and the monologue won't happen. | |
setTimeout(function() { | |
msgObserver.disconnect(); | |
delete msgObserver; | |
}, 1000 * 60 * 5); | |
}); | |
} | |
setTimeout(function() { | |
var $chat = document.getElementById("chat"); | |
if (!$chat) | |
return; | |
var mainChatObserver = new MutationObserver(mainChatObserverCb).observe($chat, { childList: true }); | |
}, 1000); | |
console.log("SnackChat loaded"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment