Skip to content

Instantly share code, notes, and snippets.

@rlemon
Last active August 29, 2015 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlemon/3b370467864778f04845 to your computer and use it in GitHub Desktop.
Save rlemon/3b370467864778f04845 to your computer and use it in GitHub Desktop.
webm inline player for so chat
(function() {
"use strict";
function parseNode(node) {
if (node.classList && node.classList.contains('message') && !node.classList.contains('pending')) {
var content = node.querySelector('.content');
if ([].filter.call(content.childNodes, function(child) {
return (child.nodeType === 1 || child.nodeType === 3)
}).length > 1) return; // shut up
var link = content.querySelector('a');
if (!link || !/(webm|gifv)$/.test(link.href)) return;
var video = document.createElement('video');
video.controls = true;
video.src = link.href.replace(/(gifv)$/, 'webm');
video.width = 320;
video.height = 240;
link.parentNode.replaceChild(video, link);
}
}
var chat = document.getElementById('chat');
[].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