From 3a63ac4642dd3d47f939362b949536f56a6250c1 Mon Sep 17 00:00:00 2001 From: Zachary Zulanas Date: Thu, 5 Nov 2020 10:55:48 -0800 Subject: [PATCH] autoplay disabled when in party --- src/content-script/actions/party.ts | 3 +++ src/lib/utils/index.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/content-script/actions/party.ts b/src/content-script/actions/party.ts index 61fe482..759845d 100644 --- a/src/content-script/actions/party.ts +++ b/src/content-script/actions/party.ts @@ -4,6 +4,8 @@ import { debug } from '@root/lib/utils/debug'; import { PartyState } from '@contentScript/reducers/party'; import socket from '@contentScript/socket'; +import { disableAutoplay } from '@root/lib/utils'; + import { Dispatch } from 'redux'; import { setUser } from './user'; @@ -22,6 +24,7 @@ export const joinParty = ({ hash, isHost }: any) => { dispatch(setParty({ isHost, ...party })); dispatch(setUser({ ...user })); }); + disableAutoplay(); } catch (error) { debug(error.message); } diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 1f91623..bd562ba 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -15,3 +15,15 @@ export const inject = (fn: () => void) => { export const isValidExtensionUrl = (url: string) => { return url.match(/^.*:\/\/.*.youtube.com\/watch.*$/); }; + +export const disableAutoplay = () => { + const autoPlayBtn = document.getElementsByClassName( + 'style-scope ytd-compact-autoplay-renderer' + )[3] as HTMLInputElement; + if (autoPlayBtn.getAttribute('aria-pressed') === 'true') { + autoPlayBtn.click(); + } + autoPlayBtn.setAttribute('disabled', 'disabled'); + const autoPlayTxt = document.getElementsByClassName('style-scope ytd-compact-autoplay-renderer')[2] as HTMLElement; + autoPlayTxt.innerText = 'Autoplay Disabled when in Party'; +};