mirror of
https://github.com/SoPat712/videospeed.git
synced 2025-08-21 18:08:46 -04:00
switch to mutationobserver, check child nodes
This commit is contained in:
@@ -71,13 +71,6 @@
|
||||
margin-top: 60px;
|
||||
}
|
||||
|
||||
/* shift controller on Vine embeds: mute always visible */
|
||||
/* e.g. https://twitter.com/Vine_Football/status/550614684575858688 */
|
||||
.video-container .tc-videoController {
|
||||
margin-top: 12px;
|
||||
margin-left: 55px;
|
||||
}
|
||||
|
||||
/* shift controller on vine.co */
|
||||
/* e.g. https://vine.co/v/OrJj39YlL57 */
|
||||
.video-container .vine-video-container .tc-videoController {
|
||||
|
22
inject.js
22
inject.js
@@ -98,6 +98,7 @@ chrome.extension.sendMessage({}, function(response) {
|
||||
container.style.top = this.video.offsetTop+"px";
|
||||
|
||||
fragment.appendChild(container);
|
||||
this.video.classList.add('tc-initialized');
|
||||
this.video.parentElement.insertBefore(fragment, this.video);
|
||||
|
||||
var speed = parseFloat(tc.settings.speed).toFixed(2);
|
||||
@@ -181,14 +182,27 @@ chrome.extension.sendMessage({}, function(response) {
|
||||
return false;
|
||||
}, true);
|
||||
|
||||
document.addEventListener('DOMNodeInserted', function(event) {
|
||||
var node = event.target || null;
|
||||
if (node && node.nodeName === 'VIDEO') {
|
||||
var forEach = Array.prototype.forEach;
|
||||
function checkForVideo(node) {
|
||||
if (node.nodeName === 'VIDEO') {
|
||||
if (!node.classList.contains('tc-initialized')) {
|
||||
new tc.videoController(node);
|
||||
}
|
||||
} else if (node.children != undefined) {
|
||||
for (var i = 0; i < node.children.length; i++) {
|
||||
checkForVideo(node.children[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
var observer = new MutationObserver(function(mutations) {
|
||||
mutations.forEach(function(mutation) {
|
||||
forEach.call(mutation.addedNodes, function(node) {
|
||||
checkForVideo(node);
|
||||
})
|
||||
});
|
||||
});
|
||||
observer.observe(document, { childList: true, subtree: true });
|
||||
|
||||
var forEach = Array.prototype.forEach;
|
||||
var videoTags = document.getElementsByTagName('video');
|
||||
forEach.call(videoTags, function(video) {
|
||||
new tc.videoController(video);
|
||||
|
Reference in New Issue
Block a user