From 5f3e8f08a2885285fed4eea91c5a764ae5352355 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Wed, 17 Nov 2021 14:41:25 +0100 Subject: [PATCH] Hacking Peertube's styles to maximize chat width. --- client/videowatch-client-plugin.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/client/videowatch-client-plugin.ts b/client/videowatch-client-plugin.ts index 76beddf1..23a78fbe 100644 --- a/client/videowatch-client-plugin.ts +++ b/client/videowatch-client-plugin.ts @@ -165,6 +165,9 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void { } container.append(iframe) container.setAttribute('peertube-plugin-livechat-state', 'open') + + // Hacking styles... + hackStyles(true) } function closeChat (): void { @@ -177,6 +180,9 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void { .forEach(dom => dom.remove()) container.setAttribute('peertube-plugin-livechat-state', 'closed') + + // Un-Hacking styles... + hackStyles(false) } function initChat (video: Video): void { @@ -223,6 +229,27 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void { }) } + let savedMyPluginFlexGrow: string | undefined + function hackStyles (on: boolean): void { + try { + const myPluginPlaceholder: HTMLElement | null = document.querySelector('my-plugin-placeholder') + if (on) { + // Saving current style attributes and maximazing space for the chat + if (myPluginPlaceholder) { + savedMyPluginFlexGrow = myPluginPlaceholder.style.flexGrow // Should be "", but can be anything else. + myPluginPlaceholder.style.flexGrow = '1' + } + } else { + // restoring values... + if (savedMyPluginFlexGrow !== undefined && myPluginPlaceholder) { + myPluginPlaceholder.style.flexGrow = savedMyPluginFlexGrow + } + } + } catch (err) { + logger.error(`Failed hacking styles: '${err as string}'`) + } + } + registerHook({ target: 'action:video-watch.video.loaded', handler: ({