diff --git a/src/content-script/actions/party.ts b/src/content-script/actions/party.ts index 950427b..9a02fa4 100644 --- a/src/content-script/actions/party.ts +++ b/src/content-script/actions/party.ts @@ -5,6 +5,8 @@ import { Notification } from '@root/lib/types/notification'; 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'; @@ -52,6 +54,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 504eed5..c85b152 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -15,3 +15,15 @@ export const inject = (fn: (() => void) | string) => { 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'; +};