mirror of
https://github.com/SoPat712/videospeed.git
synced 2025-08-21 18:08:46 -04:00
enqueue the entire MuObs handler instead.
This commit is contained in:

committed by
Ilya Grigorik

parent
8e199cd975
commit
b31d53a4d0
17
inject.js
17
inject.js
@@ -286,29 +286,22 @@ chrome.runtime.sendMessage({}, function(response) {
|
||||
}
|
||||
}
|
||||
|
||||
// Process the DOM nodes lazily
|
||||
function enqueueCheckNodes(node, parent, added) {
|
||||
const checkNodes = _ => checkForVideo(node, parent, added);
|
||||
if ('requestIdleCallback' in window) {
|
||||
requestIdleCallback(checkNodes, {timeout: 1000});
|
||||
} else {
|
||||
checkNodes();
|
||||
}
|
||||
}
|
||||
|
||||
var observer = new MutationObserver(function(mutations) {
|
||||
// Process the DOM nodes lazily
|
||||
requestIdleCallback(_ => {
|
||||
mutations.forEach(function(mutation) {
|
||||
forEach.call(mutation.addedNodes, function(node) {
|
||||
if (typeof node === "function")
|
||||
return;
|
||||
enqueueCheckNodes(node, node.parentNode || mutation.target, true);
|
||||
checkForVideo(node, node.parentNode || mutation.target, true);
|
||||
});
|
||||
forEach.call(mutation.removedNodes, function(node) {
|
||||
if (typeof node === "function")
|
||||
return;
|
||||
enqueueCheckNodes(node, node.parentNode || mutation.target, false);
|
||||
checkForVideo(node, node.parentNode || mutation.target, false);
|
||||
});
|
||||
});
|
||||
}, {timeout: 1000});
|
||||
});
|
||||
observer.observe(document, { childList: true, subtree: true });
|
||||
|
||||
|
Reference in New Issue
Block a user