diff --git a/src/assets/outline.svg b/src/assets/outline.svg new file mode 100644 index 00000000..2ccc0a80 --- /dev/null +++ b/src/assets/outline.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/components/HyperchatButton.svelte b/src/components/HyperchatButton.svelte index 669da916..e4eb7334 100644 --- a/src/components/HyperchatButton.svelte +++ b/src/components/HyperchatButton.svelte @@ -1,8 +1,7 @@ + +
+
+
+ {@html outline} +
+
+
HyperChat Settings
+
+ + \ No newline at end of file diff --git a/src/scripts/chat-injector.ts b/src/scripts/chat-injector.ts index d7b38259..8c0b0cae 100644 --- a/src/scripts/chat-injector.ts +++ b/src/scripts/chat-injector.ts @@ -1,9 +1,11 @@ import HcButton from '../components/HyperchatButton.svelte'; +import HcSettings from '../components/SettingsButton.svelte'; import { getFrameInfoAsync, isValidFrameInfo, frameIsReplay, checkInjected } from '../ts/chat-utils'; import { isLiveTL } from '../ts/chat-constants'; import { hcEnabled, autoLiveChat } from '../ts/storage'; // const isFirefox = navigator.userAgent.includes('Firefox'); +let hcSettings: HcSettings | null = null; const hcWarning = 'An existing HyperChat button has been detected. This ' + 'usually means both LiveTL and standalone HyperChat are enabled. ' + @@ -23,11 +25,44 @@ const chatLoaded = async (): Promise => { console.error('Failed to find #primary-content'); return; } - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const hcButton = new HcButton({ + new HcButton({ target: ytcPrimaryContent }); + // Inject HC settings + const injectSettings = (): void => { + const destroyButton = (): void => { + if (hcSettings !== null) { + try { + hcSettings.$destroy(); + } catch (_) {} + } + } + + const ytcItemMenu = document.querySelector('tp-yt-paper-listbox#items'); + if (ytcItemMenu) { + // Prevent duplicates + if (document.getElementById('hc-settings')) return; + + destroyButton(); + hcSettings = new HcSettings({ + target: ytcItemMenu + }); + + return; + } + + destroyButton(); + }; + + const chatApp = document.querySelector('yt-live-chat-app'); + if (chatApp) { + new MutationObserver(injectSettings).observe(chatApp, { + childList: true, + subtree: true + }); + } + // Everything past this point will only run if HC is enabled if (!hyperChatEnabled) return; diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts new file mode 100644 index 00000000..79ebb242 --- /dev/null +++ b/src/vite-env.d.ts @@ -0,0 +1,6 @@ +/// + +declare module '*.svg?raw' { + const content: string; + export default content; +}