Skip to content

Commit

Permalink
hotfix youtube shorts
Browse files Browse the repository at this point in the history
the observer needs to observe only the childList (and will throw if there are no added nodes)
  • Loading branch information
Araxeus committed Aug 19, 2024
1 parent a2a34ab commit 9bbf494
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions unpacked/pageAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,28 +825,28 @@ ytvs.init();
if (ytvs.$('#movie_player:not(.unstarted-mode) video')) {
YoutubeVolumeScroll.run();
} else {
const documentObserver = new MutationObserver(() => {
const videoObserver = new MutationObserver(() => {
if (ytvs.$('#movie_player:not(.unstarted-mode) video')) {
documentObserver.disconnect();
videoObserver.disconnect();
YoutubeVolumeScroll.run();
}
});

const moviePlayer = ytvs.$('#movie_player');
if (moviePlayer) {
documentObserver.observe(moviePlayer, { attributes: true });
videoObserver.observe(moviePlayer, { attributes: true });
} else {
const pageManager = ytvs.$('ytd-page-manager');
if (pageManager) {
documentObserver.observe(pageManager, {
videoObserver.observe(pageManager, {
childList: true,
subtree: true,
});
} else {
new MutationObserver((_, observer) => {
if (ytvs.$('ytd-page-manager')) {
observer.disconnect();
documentObserver.observe(ytvs.$('ytd-page-manager'), {
videoObserver.observe(ytvs.$('ytd-page-manager'), {
childList: true,
subtree: true,
});
Expand All @@ -863,34 +863,34 @@ if (!ytvs.isMusic) {
if (ytvs.$('ytd-player.ytd-shorts video')) {
YoutubeVolumeScroll.newYoutubeShorts();
} else {
const shortsListener = new MutationObserver((m) => {
const shortsObserver = new MutationObserver((m) => {
if (m[0].addedNodes[0].tagName === 'YTD-SHORTS') {
shortsListener.disconnect();
const shortsVideoListener = new MutationObserver(() => {
if (ytvs.$('ytd-player.ytd-shorts video')) {
shortsObserver.disconnect();
const shortsContainer = m[0].addedNodes[0];
new MutationObserver((_, observer) => {
if (
shortsContainer.querySelector(
'ytd-player.ytd-shorts video',
)
) {
observer.disconnect();
YoutubeVolumeScroll.newYoutubeShorts();
shortsVideoListener.disconnect();
}
}).observe(shortsContainer, {
childList: true,
subtree: true,
});
shortsVideoListener.observe(
ytvs.$('ytd-page-manager ytd-shorts'),
{
childList: true,
subtree: true,
},
);
}
});
const pageManager = ytvs.$('ytd-page-manager');
if (pageManager) {
shortsListener.observe(pageManager, { childList: true });
shortsObserver.observe(pageManager, { childList: true });
} else {
new MutationObserver((_, observer) => {
if (ytvs.$('ytd-page-manager')) {
observer.disconnect();
shortsListener.observe(ytvs.$('ytd-page-manager'), {
shortsObserver.observe(ytvs.$('ytd-page-manager'), {
childList: true,
subtree: true,
});
}
}).observe(document.documentElement, {
Expand Down

0 comments on commit 9bbf494

Please sign in to comment.