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:
38
inject.js
38
inject.js
@@ -448,6 +448,8 @@
|
||||
// Process the DOM nodes lazily
|
||||
requestIdleCallback(_ => {
|
||||
mutations.forEach(function(mutation) {
|
||||
switch (mutation.type) {
|
||||
case 'childList':
|
||||
forEach.call(mutation.addedNodes, function(node) {
|
||||
if (typeof node === "function")
|
||||
return;
|
||||
@@ -458,10 +460,22 @@
|
||||
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});
|
||||
});
|
||||
observer.observe(document, { childList: true, subtree: true });
|
||||
observer.observe(document, { attributes: true, childList: true, subtree: true });
|
||||
|
||||
if (tc.settings.audioBoolean) {
|
||||
var mediaTags = document.querySelectorAll('video,audio');
|
||||
@@ -480,28 +494,6 @@
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user