From e823cb539bd1d3014ecbcdc50dc4fa5a602621e8 Mon Sep 17 00:00:00 2001 From: VampireChicken12 Date: Fri, 26 Apr 2024 18:55:58 -0400 Subject: [PATCH] feat: Hide live stream chat #452 --- public/locales/ca-ES.json | 4 +++ public/locales/cs-CZ.json | 4 +++ public/locales/de-DE.json | 4 +++ public/locales/en-GB.json | 4 +++ public/locales/en-US.json | 4 +++ public/locales/en-US.json.d.ts | 1 + public/locales/es-ES.json | 4 +++ public/locales/fa-IR.json | 4 +++ public/locales/fr-FR.json | 4 +++ public/locales/he-IL.json | 4 +++ public/locales/hi-IN.json | 4 +++ public/locales/it-IT.json | 4 +++ public/locales/ja-JP.json | 4 +++ public/locales/pl-PL.json | 4 +++ public/locales/pt-BR.json | 4 +++ public/locales/ru-RU.json | 4 +++ public/locales/sv-SE.json | 4 +++ public/locales/tr-TR.json | 4 +++ public/locales/zh-CN.json | 4 +++ public/locales/zh-TW.json | 4 +++ src/components/Settings/Settings.tsx | 20 +++++++---- src/features/hideLiveStreamChat/index.css | 3 ++ src/features/hideLiveStreamChat/index.ts | 42 +++++++++++++++++++++++ src/i18n/index.ts | 18 +++++----- src/pages/content/index.ts | 5 +++ src/pages/embedded/index.ts | 16 +++++++-- src/types/index.ts | 2 ++ src/utils/constants.ts | 2 ++ 28 files changed, 168 insertions(+), 17 deletions(-) create mode 100644 src/features/hideLiveStreamChat/index.css create mode 100644 src/features/hideLiveStreamChat/index.ts diff --git a/public/locales/ca-ES.json b/public/locales/ca-ES.json index 1e85de17..428c4afa 100644 --- a/public/locales/ca-ES.json +++ b/public/locales/ca-ES.json @@ -209,6 +209,10 @@ "label": "Automatic theater mode", "title": "Automatically enables theater mode when you load a video" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Hide scrollbar", "title": "Hides the pages scrollbar" diff --git a/public/locales/cs-CZ.json b/public/locales/cs-CZ.json index bcd5b668..a60584d7 100644 --- a/public/locales/cs-CZ.json +++ b/public/locales/cs-CZ.json @@ -209,6 +209,10 @@ "label": "Automatic theater mode", "title": "Automatically enables theater mode when you load a video" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Hide scrollbar", "title": "Hides the pages scrollbar" diff --git a/public/locales/de-DE.json b/public/locales/de-DE.json index 7f6832f9..0a6c334e 100644 --- a/public/locales/de-DE.json +++ b/public/locales/de-DE.json @@ -209,6 +209,10 @@ "label": "Automatischer Theatermodus", "title": "Automatisch den Theatermodus aktivieren, wenn ein Video geladen wird" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Scrollbar ausblenden", "title": "Versteckt die Scrollleiste" diff --git a/public/locales/en-GB.json b/public/locales/en-GB.json index 99ccbeae..31ec1812 100644 --- a/public/locales/en-GB.json +++ b/public/locales/en-GB.json @@ -209,6 +209,10 @@ "label": "Automatic theatre mode", "title": "Automatically enables theatre mode when you load a video" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Hide scrollbar", "title": "Hides the pages scrollbar" diff --git a/public/locales/en-US.json b/public/locales/en-US.json index d9def660..9353729a 100644 --- a/public/locales/en-US.json +++ b/public/locales/en-US.json @@ -209,6 +209,10 @@ "label": "Automatic theater mode", "title": "Automatically enables theater mode when you load a video" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Hide scrollbar", "title": "Hides the pages scrollbar" diff --git a/public/locales/en-US.json.d.ts b/public/locales/en-US.json.d.ts index cce3ae13..66fc7a0f 100644 --- a/public/locales/en-US.json.d.ts +++ b/public/locales/en-US.json.d.ts @@ -143,6 +143,7 @@ interface EnUS { label: "Automatic theater mode"; title: "Automatically enables theater mode when you load a video"; }; + hideLiveStreamChat: { label: "Hide live stream chat"; title: "Hides the live stream chat" }; hideScrollbar: { label: "Hide scrollbar"; title: "Hides the pages scrollbar" }; hideShorts: { label: "Hide shorts"; title: "Hides all shorts" }; loopButton: { diff --git a/public/locales/es-ES.json b/public/locales/es-ES.json index bd234c31..1178f31e 100644 --- a/public/locales/es-ES.json +++ b/public/locales/es-ES.json @@ -209,6 +209,10 @@ "label": "Modo cine automático", "title": "Activar automáticamente el modo cine al cargar un vídeo" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Ocultar barra de desplazamiento", "title": "Oculta la barra de desplazamiento de la página" diff --git a/public/locales/fa-IR.json b/public/locales/fa-IR.json index c204892e..ac01d8a4 100644 --- a/public/locales/fa-IR.json +++ b/public/locales/fa-IR.json @@ -209,6 +209,10 @@ "label": "Automatic theater mode", "title": "Automatically enables theater mode when you load a video" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Hide scrollbar", "title": "Hides the pages scrollbar" diff --git a/public/locales/fr-FR.json b/public/locales/fr-FR.json index 561a1897..48c4fd43 100644 --- a/public/locales/fr-FR.json +++ b/public/locales/fr-FR.json @@ -209,6 +209,10 @@ "label": "Mode cinéma automatique", "title": "Activer automatiquement le mode cinéma lorsque vous chargez une vidéo" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Cacher la barre de défilement", "title": "Cache la barre de défilement des pages" diff --git a/public/locales/he-IL.json b/public/locales/he-IL.json index 172e01fa..14fd8e7b 100644 --- a/public/locales/he-IL.json +++ b/public/locales/he-IL.json @@ -209,6 +209,10 @@ "label": "Automatic theater mode", "title": "Automatically enables theater mode when you load a video" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Hide scrollbar", "title": "Hides the pages scrollbar" diff --git a/public/locales/hi-IN.json b/public/locales/hi-IN.json index faf86555..3f69d8d1 100644 --- a/public/locales/hi-IN.json +++ b/public/locales/hi-IN.json @@ -209,6 +209,10 @@ "label": "Automatic theater mode", "title": "Automatically enables theater mode when you load a video" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Hide scrollbar", "title": "Hides the pages scrollbar" diff --git a/public/locales/it-IT.json b/public/locales/it-IT.json index 67391e7d..97ebaf05 100644 --- a/public/locales/it-IT.json +++ b/public/locales/it-IT.json @@ -209,6 +209,10 @@ "label": "Modalità teatro automatica", "title": "Attiva automaticamente la modalità teatro quando carichi un video" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Nascondi barra scorrimento", "title": "Nasconde la barra di scorrimento delle pagine" diff --git a/public/locales/ja-JP.json b/public/locales/ja-JP.json index 46eef3bb..b0f27db2 100644 --- a/public/locales/ja-JP.json +++ b/public/locales/ja-JP.json @@ -209,6 +209,10 @@ "label": "自動シアターモード", "title": "動画の読み込み時に自動的にシアターモードを有効にする" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "スクロールバー隠す機能", "title": "ページのスクロールバーを隠す" diff --git a/public/locales/pl-PL.json b/public/locales/pl-PL.json index bf0808e8..6b620aa1 100644 --- a/public/locales/pl-PL.json +++ b/public/locales/pl-PL.json @@ -209,6 +209,10 @@ "label": "Automatic theater mode", "title": "Automatically enables theater mode when you load a video" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Hide scrollbar", "title": "Hides the pages scrollbar" diff --git a/public/locales/pt-BR.json b/public/locales/pt-BR.json index 9a49b81a..54029035 100644 --- a/public/locales/pt-BR.json +++ b/public/locales/pt-BR.json @@ -209,6 +209,10 @@ "label": "Modo teatro automático", "title": "Ativar automaticamente o modo teatro quando você carregar um vídeo" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Ocultar a barra de rolagem", "title": "Oculta a barra de rolagem da página" diff --git a/public/locales/ru-RU.json b/public/locales/ru-RU.json index d9d53098..12f04f02 100644 --- a/public/locales/ru-RU.json +++ b/public/locales/ru-RU.json @@ -209,6 +209,10 @@ "label": "Включить автоматический режим кинотеатра", "title": "Автоматически включать режим кинотеатра при загрузке видео" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Включить скрытие полосы прокрутки страницы", "title": "Скрывает полосу прокрутки страницы" diff --git a/public/locales/sv-SE.json b/public/locales/sv-SE.json index 74fa7151..215ff66b 100644 --- a/public/locales/sv-SE.json +++ b/public/locales/sv-SE.json @@ -209,6 +209,10 @@ "label": "Automatiskt teaterläge", "title": "Aktiverar automatiskt teaterläge när du startar en video" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Dölj rullningslisten", "title": "Döljer sidornas rullningsfält" diff --git a/public/locales/tr-TR.json b/public/locales/tr-TR.json index 115b2d22..acad519f 100644 --- a/public/locales/tr-TR.json +++ b/public/locales/tr-TR.json @@ -209,6 +209,10 @@ "label": "Otomatik tiyatro modu", "title": "Video yüklediğinizde tiyatro modunu otomatik olarak etkinleştirir" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "Kaydırma çubuğu gizlemeyi etkinleştir", "title": "Sayfa kaydırma çubuğunu gizler" diff --git a/public/locales/zh-CN.json b/public/locales/zh-CN.json index a77320bd..412e2af8 100644 --- a/public/locales/zh-CN.json +++ b/public/locales/zh-CN.json @@ -209,6 +209,10 @@ "label": "自动启用剧场模式", "title": "当视频打开时,自动启用剧场模式" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "启用隐藏滚动条", "title": "隐藏页面滚动条" diff --git a/public/locales/zh-TW.json b/public/locales/zh-TW.json index 484ad8e0..2de75572 100644 --- a/public/locales/zh-TW.json +++ b/public/locales/zh-TW.json @@ -209,6 +209,10 @@ "label": "自動啟用劇院模式", "title": "載入影片時自動啟用劇院模式" }, + "hideLiveStreamChat": { + "label": "Hide live stream chat", + "title": "Hides the live stream chat" + }, "hideScrollbar": { "label": "隱藏捲軸", "title": "隱藏頁面捲軸" diff --git a/src/components/Settings/Settings.tsx b/src/components/Settings/Settings.tsx index 3b2ccef0..c4cd04e7 100644 --- a/src/components/Settings/Settings.tsx +++ b/src/components/Settings/Settings.tsx @@ -656,6 +656,14 @@ export default function Settings() { title={t("settings.sections.miscellaneous.features.hideShorts.title")} type="checkbox" /> + @@ -1087,7 +1095,7 @@ export default function Settings() {
{isPopup && ( )} {notifications.filter((n) => n.action === "reset_settings").length > 0 ? { const notificationToRemove = notifications.find((n) => n.action === "reset_settings"); @@ -1146,7 +1154,7 @@ export default function Settings() { value={t("settings.sections.bottomButtons.confirm.value")} /> : ("div#movie_player"); + if (!player) return; + const playerData = await player.getVideoData(); + if (!playerData.isLive) return; + modifyElementsClassList("add", liveStreamChatElementPairs); +} + +export async function disableHideLiveStreamChat() { + const player = document.querySelector("div#movie_player"); + if (!player) return; + const playerData = await player.getVideoData(); + if (!playerData.isLive) return; + modifyElementsClassList("remove", liveStreamChatElementPairs); +} diff --git a/src/i18n/index.ts b/src/i18n/index.ts index 2faa7811..0fa8fdee 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -30,18 +30,18 @@ export const localePercentages: Record = { "en-GB": 2, "es-ES": 63, "fa-IR": 0, - "fr-FR": 67, + "fr-FR": 66, "he-IL": 0, "hi-IN": 0, - "it-IT": 100, - "ja-JP": 100, + "it-IT": 99, + "ja-JP": 99, "pl-PL": 0, - "pt-BR": 74, - "ru-RU": 100, - "sv-SE": 98, - "tr-TR": 75, - "zh-CN": 100, - "zh-TW": 95 + "pt-BR": 73, + "ru-RU": 99, + "sv-SE": 97, + "tr-TR": 74, + "zh-CN": 99, + "zh-TW": 94 }; export const localeDirection: Record = { "ca-ES": "ltr", diff --git a/src/pages/content/index.ts b/src/pages/content/index.ts index 54b256bb..91d7a9fa 100644 --- a/src/pages/content/index.ts +++ b/src/pages/content/index.ts @@ -275,6 +275,11 @@ const storageChangeHandler = async (changes: StorageChanges, areaName: string) = playerSpeed: options.player_speed }); }, + enable_hide_live_stream_chat: (__oldValue, newValue) => { + sendExtensionOnlyMessage("hideLiveStreamChatChange", { + hideLiveStreamChatEnabled: newValue + }); + }, enable_hide_scrollbar: (__oldValue, newValue) => { sendExtensionOnlyMessage("hideScrollBarChange", { hideScrollBarEnabled: newValue diff --git a/src/pages/embedded/index.ts b/src/pages/embedded/index.ts index d318819a..3ced09f6 100644 --- a/src/pages/embedded/index.ts +++ b/src/pages/embedded/index.ts @@ -10,6 +10,7 @@ import { disableDeepDarkCSS, enableDeepDarkCSS } from "@/src/features/deepDarkCS import { deepDarkCSSExists, getDeepDarkCustomThemeStyle, updateDeepDarkCSS } from "@/src/features/deepDarkCSS/utils"; import { enableFeatureMenu, setupFeatureMenuEventListeners } from "@/src/features/featureMenu"; import { featuresInMenu, getFeatureMenuItem, updateFeatureMenuItemLabel, updateFeatureMenuTitle } from "@/src/features/featureMenu/utils"; +import { disableHideLiveStreamChat, enableHideLiveStreamChat } from "@/src/features/hideLiveStreamChat"; import { enableHideScrollBar } from "@/src/features/hideScrollBar"; import { hideScrollBar, showScrollBar } from "@/src/features/hideScrollBar/utils"; import { disableHideShorts, enableHideShorts } from "@/src/features/hideShorts"; @@ -119,6 +120,7 @@ const alwaysShowProgressBar = async function () { }; const enableFeatures = () => { + browserColorLog(`Enabling features...`, "FgMagenta"); void (async () => { // Wait for the specified container selectors to be available on the page await waitForAllElements(["div#player", "div#player-wide-container", "div#video-container", "div#player-container"]); @@ -143,6 +145,7 @@ const enableFeatures = () => { setupPlaybackSpeedChangeListener(), enableShortsAutoScroll(), enableOpenYouTubeSettingsOnHover(), + enableHideLiveStreamChat(), enableRememberVolume(), automaticTheaterMode(), setupRemainingTime(), @@ -173,11 +176,9 @@ window.addEventListener("DOMContentLoaded", function () { } = response; const i18nextInstance = await i18nService(language); window.i18nextInstance = i18nextInstance; - // Listen to YouTube's soft navigate event document.addEventListener("yt-navigate-finish", enableFeatures); document.addEventListener("yt-player-updated", enableFeatures); - /** * Listens for the "yte-message-from-youtube" event and handles incoming messages from the YouTube page. * @@ -390,6 +391,17 @@ window.addEventListener("DOMContentLoaded", function () { } break; } + case "hideLiveStreamChatChange": { + const { + data: { hideLiveStreamChatEnabled } + } = message; + if (hideLiveStreamChatEnabled) { + await enableHideLiveStreamChat(); + } else { + await disableHideLiveStreamChat(); + } + break; + } case "languageChange": { const { data: { language } diff --git a/src/types/index.ts b/src/types/index.ts index d16bdff7..25496245 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -273,6 +273,7 @@ export type ExtensionSendOnlyMessageMappings = { { deepDarkCustomThemeColors: DeepDarkCustomThemeColors; deepDarkPreset: DeepDarkPreset; deepDarkThemeEnabled: boolean } >; featureMenuOpenTypeChange: DataResponseMessage<"featureMenuOpenTypeChange", { featureMenuOpenType: FeatureMenuOpenType }>; + hideLiveStreamChatChange: DataResponseMessage<"hideLiveStreamChatChange", { hideLiveStreamChatEnabled: boolean }>; hideScrollBarChange: DataResponseMessage<"hideScrollBarChange", { hideScrollBarEnabled: boolean }>; hideShortsChange: DataResponseMessage<"hideShortsChange", { hideShortsEnabled: boolean }>; languageChange: DataResponseMessage<"languageChange", { language: AvailableLocales }>; @@ -352,6 +353,7 @@ export type configuration = { enable_custom_css: boolean; enable_deep_dark_theme: boolean; enable_forced_playback_speed: boolean; + enable_hide_live_stream_chat: boolean; enable_hide_scrollbar: boolean; enable_hide_shorts: boolean; enable_loop_button: boolean; diff --git a/src/utils/constants.ts b/src/utils/constants.ts index d48d8fa7..c3f9d82e 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -46,6 +46,7 @@ export const defaultConfiguration = { enable_custom_css: false, enable_deep_dark_theme: false, enable_forced_playback_speed: false, + enable_hide_live_stream_chat: false, enable_hide_scrollbar: false, enable_hide_shorts: false, enable_loop_button: false, @@ -126,6 +127,7 @@ export const configurationImportSchema: TypeToPartialZodSchema< enable_custom_css: z.boolean().optional(), enable_deep_dark_theme: z.boolean().optional(), enable_forced_playback_speed: z.boolean().optional(), + enable_hide_live_stream_chat: z.boolean().optional(), enable_hide_scrollbar: z.boolean().optional(), enable_hide_shorts: z.boolean().optional(), enable_loop_button: z.boolean().optional(),