mirror of
https://github.com/SoPat712/videospeed.git
synced 2025-08-21 18:08:46 -04:00
Fallback if requestIdleCallback is not available
This commit is contained in:
11
inject.js
11
inject.js
@@ -321,8 +321,7 @@ chrome.runtime.sendMessage({}, function(response) {
|
||||
}
|
||||
|
||||
var observer = new MutationObserver(function(mutations) {
|
||||
// Process the DOM nodes lazily
|
||||
requestIdleCallback(_ => {
|
||||
function mutationObserverHandler() {
|
||||
mutations.forEach(function(mutation) {
|
||||
forEach.call(mutation.addedNodes, function(node) {
|
||||
if (typeof node === "function")
|
||||
@@ -335,7 +334,13 @@ chrome.runtime.sendMessage({}, function(response) {
|
||||
checkForVideo(node, node.parentNode || mutation.target, false);
|
||||
});
|
||||
});
|
||||
}, {timeout: 1000});
|
||||
}
|
||||
// Process the DOM nodes lazily
|
||||
if ('requestIdleCallback' in window) {
|
||||
requestIdleCallback(mutationObserverHandler, {timeout: 1000});
|
||||
} else {
|
||||
mutationObserverHandler();
|
||||
}
|
||||
});
|
||||
observer.observe(document, { childList: true, subtree: true });
|
||||
|
||||
|
Reference in New Issue
Block a user