diff --git a/src/components/Hyperchat.svelte b/src/components/Hyperchat.svelte index e146e1e9..c92607f3 100644 --- a/src/components/Hyperchat.svelte +++ b/src/components/Hyperchat.svelte @@ -40,7 +40,8 @@ enableStickySuperchatBar, lastOpenedVersion, selfChannelName, - enableHighlightedMentions + enableHighlightedMentions, + ytDark } from '../ts/storage'; import { version } from '../manifest.json'; @@ -56,7 +57,6 @@ let isAtBottom = true; let truncateInterval: number; const isReplay = paramsIsReplay; - let ytDark = false; const smelteDark = dark(); type MessageBlocker = (a: Chat.MessageAction) => boolean; @@ -226,7 +226,7 @@ $selfChannel = response.selfChannel; break; case 'themeUpdate': - ytDark = response.dark; + $ytDark = response.dark; break; case 'chatUserActionResponse': $alertDialog = { @@ -305,13 +305,13 @@ if (truncateInterval) window.clearInterval(truncateInterval); }); - $: updateTheme($theme, ytDark); + $: updateTheme($theme, $ytDark); // Scroll to bottom when any of these settings change $: ((..._a: any[]) => scrollToBottom())( $showProfileIcons, $showUsernames, $showTimestamps, $showUserBadges ); - const containerClass = 'h-screen w-screen text-black dark:text-white bg-ytbg-light dark:bg-ytbg-dark flex flex-col justify-between'; + const containerClass = 'h-screen w-screen text-black dark:text-white bg-white bg-ytbg-light dark:bg-ytbg-dark flex flex-col justify-between'; const isSuperchat = (action: Chat.MessageAction) => (action.message.superChat || action.message.superSticker); const isMembership = (action: Chat.MessageAction) => (action.message.membership || action.message.membershipGiftPurchase); diff --git a/src/components/StickyBar.svelte b/src/components/StickyBar.svelte index 7969a177..bb8d88ac 100644 --- a/src/components/StickyBar.svelte +++ b/src/components/StickyBar.svelte @@ -40,7 +40,7 @@ {#if open}
=> { const params = new URLSearchParams(); params.set('tabid', frameInfo.tabId.toString()); params.set('frameid', frameInfo.frameId.toString()); - if (frameIsReplay) params.set('isReplay', 'true'); + if (frameIsReplay()) params.set('isReplay', 'true'); const source = chrome.runtime.getURL( (isLiveTL ? 'hyperchat/index.html' : 'hyperchat.html') + `?${params.toString()}` diff --git a/src/scripts/chat-interceptor.ts b/src/scripts/chat-interceptor.ts index ed154cbe..e1aed302 100644 --- a/src/scripts/chat-interceptor.ts +++ b/src/scripts/chat-interceptor.ts @@ -47,7 +47,7 @@ const chatLoaded = async (): Promise => { // Register interceptor const port: Chat.Port = chrome.runtime.connect(); - port.postMessage({ type: 'registerInterceptor', source: 'ytc', isReplay }); + port.postMessage({ type: 'registerInterceptor', source: 'ytc', isReplay: isReplay() }); // Send JSON response to clients window.addEventListener('messageReceive', (d) => { diff --git a/src/ts/chat-utils.ts b/src/ts/chat-utils.ts index e66c1adf..df74ee29 100644 --- a/src/ts/chat-utils.ts +++ b/src/ts/chat-utils.ts @@ -9,9 +9,15 @@ export const createPopup = (url: string): void => { chrome.runtime.sendMessage({ type: 'createPopup', url }); }; -export const frameIsReplay = window.location.href.startsWith( - `${(location.protocol + '//' + location.host)}/live_chat_replay` -); +export const frameIsReplay = (): boolean => { + try { + return window.location.href.startsWith( + `${(location.protocol + '//' + location.host)}/live_chat_replay` + ); + } catch (e) { + return false; + } +}; /* * Type predicates diff --git a/src/ts/storage.ts b/src/ts/storage.ts index 92d7f3f3..1578e43d 100644 --- a/src/ts/storage.ts +++ b/src/ts/storage.ts @@ -75,6 +75,7 @@ export const isDark = derived(theme, ($theme) => { $theme === Theme.YOUTUBE && window.location.search.includes('dark') ); }); +export const ytDark = writable(false); export const currentProgress = writable(null as null | number); export const enableStickySuperchatBar = stores.addSyncStore('hc.enableStickySuperchatBar', true); export const enableHighlightedMentions = stores.addSyncStore('hc.enableHighlightedMentions', true);