Skip to content

Commit

Permalink
Separate content context from utils
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Aug 14, 2024
1 parent c6a9638 commit ddd8f13
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
7 changes: 1 addition & 6 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const controlsWithEventListeners: HTMLElement[] = [];
let headerLoaded = false;
setupPageLoadingListener();

setupVideoModule();
setupVideoModule({ videoIDChange, channelIDChange, resetValues, videoElementChange });
setupThumbnailListener();

/**
Expand Down Expand Up @@ -1463,11 +1463,6 @@ function checkPreviewbarState(): void {
createPreviewBar();
}

export function updatePlayerBar() {
updatePreviewBar();
updateVisibilityOfPlayerControlsButton();
}

/**
* Returns info about the next upcoming sponsor skip
*/
Expand Down
24 changes: 13 additions & 11 deletions src/utils/video.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import * as documentScript from "../../dist/js/document.js";
import Config from "../config";
import { isSafari } from "../config/config";
import {
channelIDChange,
videoIDChange as contentVideoIDChange,
resetValues as resetContentValues,
videoElementChange,
} from "../content";
import { newThumbnails } from "../thumbnail-utils/thumbnailManagement";
import { waitFor } from "./";
import { addCleanupListener, setupCleanupListener } from "./cleanup";
Expand Down Expand Up @@ -55,7 +49,15 @@ let pageType: PageType = PageType.Unknown;
let channelIDInfo: ChannelIDInfo;
let waitingForChannelID = false;

export function setupVideoModule() {
let contentMethod = {
videoIDChange: () => {},
channelIDChange: (channelID) => channelID,
resetValues: () => {},
videoElementChange: (newVideo) => newVideo,
};

export function setupVideoModule(method) {
contentMethod = method;
setupCleanupListener();

// Direct Links after the config is loaded
Expand Down Expand Up @@ -151,13 +153,13 @@ async function videoIDChange(id: VideoID | null): Promise<boolean> {
// Update whitelist data when the video data is loaded
void whitelistCheck();

contentVideoIDChange();
contentMethod.videoIDChange();

return true;
}

function resetValues() {
resetContentValues();
contentMethod.resetValues();

videoID = null;
pageType = PageType.Unknown;
Expand Down Expand Up @@ -208,7 +210,7 @@ export async function whitelistCheck() {
// }

waitingForChannelID = false;
channelIDChange(channelIDInfo);
contentMethod.channelIDChange(channelIDInfo);
}

let lastMutationListenerCheck = 0;
Expand Down Expand Up @@ -268,7 +270,7 @@ async function refreshVideoAttachments(): Promise<void> {
videosSetup.push(video);
}

videoElementChange(isNewVideo);
contentMethod.videoElementChange(isNewVideo);
setupVideoMutationListener();

if (document.URL.includes("/embed/")) {
Expand Down

0 comments on commit ddd8f13

Please sign in to comment.