mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
Refactor videoElement getter into a provider with callback
This commit is contained in:
22
providers/video-element.js
Normal file
22
providers/video-element.js
Normal file
@ -0,0 +1,22 @@
|
||||
let videoElement = null;
|
||||
|
||||
module.exports.ontimeupdate = (cb) => {
|
||||
const observer = new MutationObserver((mutations, observer) => {
|
||||
if (!videoElement) {
|
||||
videoElement = document.querySelector("video");
|
||||
if (videoElement) {
|
||||
observer.disconnect();
|
||||
videoElement.ontimeupdate = () => cb(videoElement);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!videoElement) {
|
||||
observer.observe(document, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
});
|
||||
} else {
|
||||
videoElement.ontimeupdate = () => cb(videoElement);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user