diff --git a/src/sponsorblock.js b/src/sponsorblock.js index 11589b9d..bc8545b3 100644 --- a/src/sponsorblock.js +++ b/src/sponsorblock.js @@ -157,22 +157,35 @@ class SponsorBlockHandler { console.info('bringing back segments overlay'); this.slider.appendChild(this.segmentsoverlay); } + if (n === this.slider) { + console.info('Slider removed, watching again!'); + this.observer.disconnect(); + this.watchForSlider(); + } }); } }) }); + this.watchForSlider(); + } + + watchForSlider() { + if (this.sliderInterval) clearInterval(this.sliderInterval); this.sliderInterval = setInterval(() => { - this.slider = document.querySelector('.ytlr-progress-bar__slider'); + this.slider = document.querySelector('.ytlr-progress-bar__slider, .ytlr-multi-markers-player-bar-renderer'); + console.info('Looking for slider...'); if (this.slider) { + console.info('Found slider:', this.slider); clearInterval(this.sliderInterval); this.sliderInterval = null; - this.observer.observe(this.slider, { + this.observer.observe(this.slider.parentElement, { childList: true, + subtree: true, }); this.slider.appendChild(this.segmentsoverlay); } - }, 500); + }, 1000); } scheduleSkip() { diff --git a/src/ui.js b/src/ui.js index 5333e4af..a0ba0d87 100644 --- a/src/ui.js +++ b/src/ui.js @@ -14,13 +14,23 @@ uiContainer.setAttribute('tabindex', 0); uiContainer.addEventListener('focus', () => console.info('uiContainer focused!'), true); uiContainer.addEventListener('blur', () => console.info('uiContainer blured!'), true); +let cursorVisible = false; +document.addEventListener('cursorStateChange', (evt) => { + cursorVisible = evt.detail.visibility; + console.info('Cursor visibility:', cursorVisible); +}, false); + uiContainer.addEventListener("keydown", (evt) => { console.info('uiContainer key event:', evt.type, evt.charCode); if (evt.charCode !== 404 && evt.charCode !== 172) { if (evt.keyCode in ARROW_KEY_CODE) { navigate(ARROW_KEY_CODE[evt.keyCode]); } else if (evt.keyCode === 13) { // "OK" button - document.querySelector(':focus').click(); + // Key event is emitted when clicking with a cursor as well, which leads + // to double activation + if (!cursorVisible) { + document.querySelector(':focus').click(); + } } else if (evt.keyCode === 27) { // Back button uiContainer.style.display = 'none'; uiContainer.blur();