Skip to content

Commit

Permalink
refactor keyup listener
Browse files Browse the repository at this point in the history
  • Loading branch information
GooseOb committed Dec 6, 2024
1 parent 535d927 commit 8a6ab83
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
46 changes: 24 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 8a6ab83

Please sign in to comment.