Skip to content

Commit

Permalink
refactor page change listener
Browse files Browse the repository at this point in the history
  • Loading branch information
GooseOb committed Dec 6, 2024
1 parent 32042a3 commit b9c3a89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 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.13",
"version": "1.11.0-alpha.14",
"repository": {
"type": "git",
"url": "git+https://github.com/GooseOb/YT-Defaulter.git"
Expand Down
25 changes: 12 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,23 @@ import * as get from './element-getters';

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

if (config.update(config.value)) config.saveLS(config.value);

const isMusicChannel = (aboveTheFold: HTMLElement) =>
!!get.artistChannelBadge(aboveTheFold);

const onPageChange = async () => {
if (location.pathname !== '/watch') return;
if (config.update(config.value)) {
config.saveLS(config.value);
}

const onVideoPage = async () => {
const aboveTheFold = await untilAppear(get.aboveTheFold);
config.channel.username =
(await untilAppear(get.channelUsernameElementGetter(aboveTheFold))).href ||
'';

await plr.set(await untilAppear(get.plr));

applySettings(
computeSettings(
config.value.flags.standardMusicSpeed && isMusicChannel(aboveTheFold)
)
);
const doNotChangeSpeed =
config.value.flags.standardMusicSpeed &&
!!get.artistChannelBadge(aboveTheFold);

applySettings(computeSettings(doNotChangeSpeed));

if (menu.value.element) {
menu.controls.updateThisChannel(config.channel.get());
Expand All @@ -41,7 +38,9 @@ let lastHref: string;
setInterval(() => {
if (lastHref !== location.href) {
lastHref = location.href;
setTimeout(onPageChange, 1_000);
if (location.pathname === '/watch') {
setTimeout(onVideoPage, 1_000);
}
}
}, 1_000);

Expand Down

0 comments on commit b9c3a89

Please sign in to comment.