INNER CODE UNIT · TypeScript
startVideoObserver
sindresorhus/caprine · source/autoplay.ts:128
function startVideoObserver(element: Element): void {
videoObserver.observe(element, {
childList: true,
subtree: true,
});
}
// A way to hold reference to conversation part of the document
// Used to refresh `videoObserver` after the conversation reference is lost
let conversationWindow: Element;
const conversationDivObserver = new MutationObserver(_ => {
let conversation = document.querySelector(`#${conversationId}`);
// Fetch it using `querySelector` if no luck with the `conversationId`
conversation ||= document.querySelector(selectors.conversationSelector);
// If we have a new reference
if (conversation && conversationWindow !== conversation) {