Last active
August 29, 2015 14:18
-
-
Save rlemon/3b370467864778f04845 to your computer and use it in GitHub Desktop.
webm inline player for so chat
This file contains hidden or 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
(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