From b2f45dc70e96491e653f73803b511ff98d8220f3 Mon Sep 17 00:00:00 2001 From: Flummi Date: Thu, 23 Dec 2021 07:18:33 +0100 Subject: [PATCH] mediakeys lol --- public/s/js/f0ck.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/public/s/js/f0ck.js b/public/s/js/f0ck.js index a549368..cae9fbb 100644 --- a/public/s/js/f0ck.js +++ b/public/s/js/f0ck.js @@ -1,6 +1,7 @@ (() => { + let video; if(elem = document.querySelector("#my-video")) { - const video = new v0ck(elem); + video = new v0ck(elem); document.addEventListener("keydown", e => { if(e.key === " " && e.target.tagName !== "INPUT") { video[video.paused ? 'play' : 'pause'](); @@ -161,7 +162,7 @@ }, false); // - // + // if(audioElement = document.querySelector("audio")) { const canvas = document.createElement("canvas"); const ctx = canvas.getContext("2d"); @@ -204,5 +205,25 @@ audioCtx.resume(); }; } - // + // + + // + if(elem = document.querySelector("#my-video") && "mediaSession" in navigator) { + const playpauseEvent = () => { + video[video.paused ? 'play' : 'pause'](); + document.querySelector('.v0ck_overlay').classList[video.paused ? 'remove' : 'add']('v0ck_hidden'); + }; + navigator.mediaSession.setActionHandler('play', playpauseEvent); + navigator.mediaSession.setActionHandler('pause', playpauseEvent); + navigator.mediaSession.setActionHandler('stop', playpauseEvent); + navigator.mediaSession.setActionHandler('previoustrack', () => { + if(link = document.querySelector(".pagination > .prev:not(.disabled)")) + changePage(link); + }); + navigator.mediaSession.setActionHandler('nexttrack', () => { + if(link = document.querySelector(".pagination > .next:not(.disabled)")) + changePage(link); + }); + } + // })();