Skip to content

Autoplay disabled when in party #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/content-script/actions/party.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -52,6 +54,7 @@ export const joinParty = ({ hash, isHost }: any) => {
dispatch(setParty({ isHost, ...party }));
dispatch(setUser({ ...user }));
});
disableAutoplay();
} catch (error) {
debug(error.message);
}
Expand Down
12 changes: 12 additions & 0 deletions src/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the auto play button always be the 3rd element in this list?

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';
};