Skip to content

Instantly share code, notes, and snippets.

@CodeBrauer
Created April 9, 2015 15:16
Show Gist options
  • Save CodeBrauer/7ba80220e2d53811639b to your computer and use it in GitHub Desktop.
Save CodeBrauer/7ba80220e2d53811639b to your computer and use it in GitHub Desktop.
finds html5 video sources and display them in little popup. can be used as a bookmarklet!
var videos = document.querySelectorAll('video');
var result = '';
Array.prototype.forEach.call(videos, function(video, i) {
// direct source
if (video.getAttribute('src') !== null) {
result += video.getAttribute('src') + '\n-------------------------\n';
}
// check multiple <source>-tags
var sources = video.querySelectorAll('source[src]');
Array.prototype.forEach.call(sources, function(source, j) {
if (source.getAttribute('src') !== null) {
result += source.getAttribute('src') + '\n-------------------------\n';
}
});
});
// create a popup and style it...
var popup = document.createElement("div");
popup.setAttribute('style', 'font-size: 11px; font-family: Helvetica, Arial, sans-serif; line-height: 1; padding: 10px; position: fixed; top: 70px; right: 10px; z-index: 99999; background: #fff; width: 400px; height: 200px; overflow: hidden;border: 1px solid #ccc;');
document.body.appendChild(popup);
// add links to textarea and add textarea to popup
var textarea = document.createElement("textarea");
textarea.setAttribute('style', 'width: 100%; height: 160px;font-size: 11px; font-family: Helvetica, Arial, sans-serif; line-height: 1;');
textarea.value = "Found HTML5 video sources:\n=====================================\n\n" + result;
popup.appendChild(textarea);
// add links to textarea and add textarea to popup
var closeBtn = document.createElement("button");
closeBtn.innerHTML = "Close";
// add option to close this...
closeBtn.addEventListener('click', function() {
popup.remove();
})
popup.appendChild(closeBtn);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment