allow the intro skip button to be confirmed with the Enter key (#170)
This commit is contained in:
parent
fc805da85e
commit
1dbb80ec28
@ -1,4 +1,5 @@
|
|||||||
let introSkipper = {
|
let introSkipper = {
|
||||||
|
allowEnter: true,
|
||||||
skipSegments: {},
|
skipSegments: {},
|
||||||
videoPlayer: {},
|
videoPlayer: {},
|
||||||
// .bind() is used here to prevent illegal invocation errors
|
// .bind() is used here to prevent illegal invocation errors
|
||||||
@ -56,6 +57,7 @@ introSkipper.d = function (msg) {
|
|||||||
}
|
}
|
||||||
introSkipper.injectCss();
|
introSkipper.injectCss();
|
||||||
introSkipper.injectButton();
|
introSkipper.injectButton();
|
||||||
|
document.body.addEventListener('keydown', introSkipper.eventHandler, true);
|
||||||
introSkipper.videoPlayer = document.querySelector("video");
|
introSkipper.videoPlayer = document.querySelector("video");
|
||||||
if (introSkipper.videoPlayer != null) {
|
if (introSkipper.videoPlayer != null) {
|
||||||
introSkipper.d("Hooking video timeupdate");
|
introSkipper.d("Hooking video timeupdate");
|
||||||
@ -222,4 +224,28 @@ introSkipper.secureFetch = async function (url) {
|
|||||||
if (res.status !== 200) { throw new Error(`Expected status 200 from ${url}, but got ${res.status}`); }
|
if (res.status !== 200) { throw new Error(`Expected status 200 from ${url}, but got ${res.status}`); }
|
||||||
return await res.json();
|
return await res.json();
|
||||||
}
|
}
|
||||||
|
/** Handle keydown events. */
|
||||||
|
introSkipper.eventHandler = function (e) {
|
||||||
|
const skipButton = document.querySelector("#skipIntro");
|
||||||
|
if (!skipButton) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const embyButton = skipButton.querySelector(".emby-button");
|
||||||
|
// Ignore all keydown events
|
||||||
|
if (!introSkipper.allowEnter) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
// The Enter key has been pressed and the Intro Skip button is visible
|
||||||
|
else if (e.key === "Enter" && embyButton.style.opacity !== '0') {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
introSkipper.doSkip();
|
||||||
|
// Do not allow any keydown events
|
||||||
|
introSkipper.allowEnter = false
|
||||||
|
// Wait 5 seconds to allow keydown events again
|
||||||
|
setTimeout(() => {
|
||||||
|
introSkipper.allowEnter = true;
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
introSkipper.setup();
|
introSkipper.setup();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user