Skip to content

Commit

Permalink
move listeners to listeners/ dir
Browse files Browse the repository at this point in the history
  • Loading branch information
GooseOb committed Dec 6, 2024
1 parent 681d28d commit fb11054
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 46 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.15",
"version": "1.11.0-alpha.16",
"repository": {
"type": "git",
"url": "git+https://github.com/GooseOb/YT-Defaulter.git"
Expand Down
41 changes: 3 additions & 38 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { restoreFocusAfter } from './utils';
import * as config from './config';
import { text, translations } from './text';
import { style } from './style';
import { valueSetters } from './player';
import { computeSettings } from './compute-settings';
import * as config from './config';
import * as get from './element-getters';
import { onVideoPage } from './on-video-page';
import { onClick } from './on-click';
import { onClick, onKeyup, onVideoPage } from './listeners';

Object.assign(text, translations[document.documentElement.lang]);

Expand All @@ -25,36 +20,6 @@ setInterval(() => {
}, 1_000);

document.addEventListener('click', onClick, { capture: true });
document.addEventListener(
'keyup',
(e) => {
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 }
);
document.addEventListener('keyup', onKeyup, { capture: true });

document.head.append(style);
3 changes: 3 additions & 0 deletions src/listeners/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './on-click';
export * from './on-keyup';
export * from './on-video-page';
2 changes: 1 addition & 1 deletion src/on-click.ts → src/listeners/on-click.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { value } from './config';
import { value } from '../config';

export const onClick = (e: Event) => {
const { shortsToUsual, newTab } = value.flags;
Expand Down
34 changes: 34 additions & 0 deletions src/listeners/on-keyup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { restoreFocusAfter } from '../utils';
import { valueSetters } from '../player';
import { computeSettings } from '../compute-settings';
import * as config from '../config';
import * as get from '../element-getters';
import { onClick } from './on-click';

export const onKeyup = (e: KeyboardEvent) => {
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);
}
}
}
};
12 changes: 6 additions & 6 deletions src/on-video-page.ts → src/listeners/on-video-page.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { untilAppear } from './utils';
import { applySettings, plr } from './player';
import { computeSettings } from './compute-settings';
import * as get from './element-getters';
import * as config from './config';
import * as menu from './menu';
import { untilAppear } from '../utils';
import { applySettings, plr } from '../player';
import { computeSettings } from '../compute-settings';
import * as get from '../element-getters';
import * as config from '../config';
import * as menu from '../menu';

export const onVideoPage = async () => {
const aboveTheFold = await untilAppear(get.aboveTheFold);
Expand Down

0 comments on commit fb11054

Please sign in to comment.