mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
Refactor videoElement getter into a provider with callback
This commit is contained in:
@ -1,25 +1,10 @@
|
||||
let videoElement = null;
|
||||
const { ontimeupdate } = require("../../providers/video-element");
|
||||
|
||||
const observer = new MutationObserver((mutations, observer) => {
|
||||
if (!videoElement) {
|
||||
videoElement = document.querySelector("video");
|
||||
}
|
||||
|
||||
if (videoElement) {
|
||||
videoElement.ontimeupdate = () => {
|
||||
if (videoElement.currentTime === 0 && videoElement.duration !== NaN) {
|
||||
// auto-confirm-when-paused plugin can interfere here if not disabled!
|
||||
videoElement.pause();
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
function observeVideoElement() {
|
||||
observer.observe(document, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
module.exports = () => {
|
||||
ontimeupdate((videoElement) => {
|
||||
if (videoElement.currentTime === 0 && videoElement.duration !== NaN) {
|
||||
// auto-confirm-when-paused plugin can interfere here if not disabled!
|
||||
videoElement.pause();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = observeVideoElement;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user