mirror of
https://github.com/SoPat712/videospeed.git
synced 2025-08-21 18:08:46 -04:00
refactor apple tv specific mutationObserver into second mutationObserver
This commit is contained in:
58
inject.js
58
inject.js
@@ -448,20 +448,34 @@
|
|||||||
// Process the DOM nodes lazily
|
// Process the DOM nodes lazily
|
||||||
requestIdleCallback(_ => {
|
requestIdleCallback(_ => {
|
||||||
mutations.forEach(function(mutation) {
|
mutations.forEach(function(mutation) {
|
||||||
forEach.call(mutation.addedNodes, function(node) {
|
switch (mutation.type) {
|
||||||
if (typeof node === "function")
|
case 'childList':
|
||||||
return;
|
forEach.call(mutation.addedNodes, function(node) {
|
||||||
checkForVideo(node, node.parentNode || mutation.target, true);
|
if (typeof node === "function")
|
||||||
});
|
return;
|
||||||
forEach.call(mutation.removedNodes, function(node) {
|
checkForVideo(node, node.parentNode || mutation.target, true);
|
||||||
if (typeof node === "function")
|
});
|
||||||
return;
|
forEach.call(mutation.removedNodes, function(node) {
|
||||||
checkForVideo(node, node.parentNode || mutation.target, false);
|
if (typeof node === "function")
|
||||||
});
|
return;
|
||||||
|
checkForVideo(node, node.parentNode || mutation.target, false);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'attributes':
|
||||||
|
if (mutation.attributeName == 'aria-hidden' && (mutation.target.tagName == 'APPLE-TV-PLUS-PLAYER') && (mutation.target.attributes['aria-hidden'].value == "false")) {
|
||||||
|
var node = queryShadowVideo(document.querySelector('apple-tv-plus-player'))[0]
|
||||||
|
if (!node.previousElementSibling) {
|
||||||
|
checkForVideo(node, node.parentNode || mutation.target, true);
|
||||||
|
} else {
|
||||||
|
checkForVideo(node, node.parentNode || mutation.target, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}, {timeout: 1000});
|
}, {timeout: 1000});
|
||||||
});
|
});
|
||||||
observer.observe(document, { childList: true, subtree: true });
|
observer.observe(document, { attributes: true, childList: true, subtree: true });
|
||||||
|
|
||||||
if (tc.settings.audioBoolean) {
|
if (tc.settings.audioBoolean) {
|
||||||
var mediaTags = document.querySelectorAll('video,audio');
|
var mediaTags = document.querySelectorAll('video,audio');
|
||||||
@@ -480,28 +494,6 @@
|
|||||||
initializeWhenReady(childDocument);
|
initializeWhenReady(childDocument);
|
||||||
});
|
});
|
||||||
|
|
||||||
//look for video in shadowRoot for apple tv
|
|
||||||
var apple_tv = document.querySelector('apple-tv-plus-player')
|
|
||||||
if (apple_tv) {
|
|
||||||
var observer = new MutationObserver(function(mutations) {
|
|
||||||
mutations.forEach(function(mutation) {
|
|
||||||
if (mutation.attributeName == 'aria-hidden' && (apple_tv.getAttribute('aria-hidden') == 'false')) {
|
|
||||||
var node = queryShadowVideo(document.querySelector('apple-tv-plus-player'))[0]
|
|
||||||
if (!node.previousElementSibling) {
|
|
||||||
checkForVideo(node, node.parentNode || mutation.target, true);
|
|
||||||
} else {
|
|
||||||
checkForVideo(node, node.parentNode || mutation.target, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(apple_tv, {
|
|
||||||
attributes: true
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function runAction(action, document, value, e) {
|
function runAction(action, document, value, e) {
|
||||||
|
Reference in New Issue
Block a user