From 8a6ab8316e72ca4ebda56f6d054554f0d12fe36f Mon Sep 17 00:00:00 2001 From: GooseOb Date: Fri, 6 Dec 2024 21:21:38 +0100 Subject: [PATCH] refactor keyup listener --- package.json | 2 +- src/index.ts | 46 ++++++++++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index f6efb87..23bc355 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "yt-defaulter", "author": "GooseOb", - "version": "1.11.0-alpha.11", + "version": "1.11.0-alpha.12", "repository": { "type": "git", "url": "git+https://github.com/GooseOb/YT-Defaulter.git" diff --git a/src/index.ts b/src/index.ts index 1400e82..8ae72c5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -65,28 +65,30 @@ document.addEventListener('click', onClick, { capture: true }); document.addEventListener( 'keyup', (e) => { - if (e.code === 'Enter') return onClick(e); - if (!e.ctrlKey || e.shiftKey) return; - if (config.value.flags.copySubs && e.code === 'KeyC') { - const plr = get.videoPlr(); - if (!plr?.classList.contains('ytp-fullscreen')) return; - const text = Array.from( - get.videoPlrCaptions(plr), - (line) => line.textContent - ).join(' '); - navigator.clipboard.writeText(text); - } else if (e.code === 'Space') { - e.stopPropagation(); - e.preventDefault(); - const channelCfg = config.channel.get(); - const customSpeedValue = channelCfg - ? channelCfg.customSpeed || - (!channelCfg.speed && config.value.global.customSpeed) - : config.value.global.customSpeed; - if (customSpeedValue) return valueSetters.customSpeed(customSpeedValue); - restoreFocusAfter(() => { - valueSetters[SPEED]((channelCfg || config.value.global)[SPEED]); - }); + if (e.code === 'Enter') { + onClick(e); + } else if (e.ctrlKey && !e.shiftKey) { + if (config.value.flags.copySubs && e.code === 'KeyC') { + const plr = get.videoPlr(); + if (plr?.classList.contains('ytp-fullscreen')) { + const text = Array.from( + get.videoPlrCaptions(plr), + (line) => line.textContent + ).join(' '); + navigator.clipboard.writeText(text); + } + } else if (e.code === 'Space') { + e.stopPropagation(); + e.preventDefault(); + const settings = computeSettings(false); + if (settings.speed) { + restoreFocusAfter(() => { + valueSetters.speed(settings.speed); + }); + } else if (settings.customSpeed) { + valueSetters.customSpeed(settings.customSpeed); + } + } } }, { capture: true }