Skip to content

Commit

Permalink
move menu creation out of onPageChange
Browse files Browse the repository at this point in the history
  • Loading branch information
GooseOb committed Dec 1, 2024
1 parent 48f02f5 commit c92aab5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
57 changes: 30 additions & 27 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,32 +537,7 @@ const applySettings = (settings: Cfg) => {
});
};

const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
const onPageChange = async () => {
if (location.pathname !== '/watch') return;

/* ---------------------- apply settings ---------------------- */

const aboveTheFold = await untilAppear(getAboveTheFold);
const channelUsername = await untilChannelUsernameAppear(aboveTheFold);

channelConfig = cfg.channels[channelUsername] ||= {};

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

applySettings(
computeSettings(
cfg.flags.standardMusicSpeed && isMusicChannel(aboveTheFold)
)
);

/* ---------------------- settings menu ---------------------- */

if (menu.element) {
menuControls.updateThisChannel();
return;
}

const createMenu = async (updateChannelConfig: () => void) => {
menu.element = div({
id: MENU_ID,
});
Expand Down Expand Up @@ -764,7 +739,7 @@ const onPageChange = async () => {
updateCfg(newCfg);
localStorage[STORAGE_NAME] = raw;
cfg = newCfg;
channelConfig = cfg.channels[channelUsername] ||= {};
updateChannelConfig();
} catch (e) {
updateControlStatus('Import: ' + e.message);
return;
Expand Down Expand Up @@ -816,6 +791,34 @@ const onPageChange = async () => {
sections.style.maxWidth = sections.offsetWidth + 'px';
};

const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
const onPageChange = async () => {
if (location.pathname !== '/watch') return;

const aboveTheFold = await untilAppear(getAboveTheFold);
const channelUsername = await untilChannelUsernameAppear(aboveTheFold);

const updateChannelConfig = () => {
channelConfig = cfg.channels[channelUsername] ||= {};
};

updateChannelConfig();

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

applySettings(
computeSettings(
cfg.flags.standardMusicSpeed && isMusicChannel(aboveTheFold)
)
);

if (menu.element) {
menuControls.updateThisChannel();
} else {
await createMenu(updateChannelConfig);
}
};

let lastHref: string;
setInterval(() => {
if (lastHref !== location.href) {
Expand Down
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.1",
"version": "1.11.0-alpha.2",
"repository": {
"type": "git",
"url": "git+https://github.com/GooseOb/YT-Defaulter.git"
Expand Down

0 comments on commit c92aab5

Please sign in to comment.