From 88c5b1f6cf1bf226b5f4d6f4406252f5d1a5eb01 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 22 Feb 2014 10:05:07 -0800 Subject: [PATCH] make Javascript work for videos added by autoupdate --- expandvideo.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/expandvideo.js b/expandvideo.js index 88689396..fb18fac8 100644 --- a/expandvideo.js +++ b/expandvideo.js @@ -164,10 +164,8 @@ function setupVideo(thumb, url) { } } -if (window.addEventListener) window.addEventListener("load", function(e) { - document.body.insertBefore(settingsMenu, document.body.firstChild); - - var thumbs = document.querySelectorAll("a.file"); +function setupVideosIn(element) { + var thumbs = element.querySelectorAll("a.file"); for (var i = 0; i < thumbs.length; i++) { if (/\.webm$/.test(thumbs[i].pathname)) { setupVideo(thumbs[i], thumbs[i].href); @@ -179,4 +177,25 @@ if (window.addEventListener) window.addEventListener("load", function(e) { } } } +} + +if (window.addEventListener) window.addEventListener("load", function(e) { + document.body.insertBefore(settingsMenu, document.body.firstChild); + setupVideosIn(document); + if (window.MutationObserver) { + var observer = new MutationObserver(function(mutations) { + for (var i = 0; i < mutations.length; i++) { + var additions = mutations[i].addedNodes; + if (additions == null) continue; + for (var j = 0; j < additions.length; j++) { + var node = additions[j]; + if (node.nodeType == 1) { + setupVideosIn(node); + } + } + } + }); + observer.observe(document.body, {childList: true, subtree: true}); + } }, false); +