Skip to content

Commit

Permalink
Fix autoplay control not working correctly when resizing page and nav…
Browse files Browse the repository at this point in the history
…igating

Fix issue when trying to move chat location
  • Loading branch information
ParticleCore committed Mar 6, 2024
1 parent 8a8109d commit b9ef588
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/chrome/css/content-script.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ini | autoplay */
#movie_player.unstarted-mode > *:not(.ytp-cued-thumbnail-overlay) {
#movie_player.unstarted-mode:is(.playing-mode, .paused-mode) > *:not(.ytp-cued-thumbnail-overlay) {
display: none;
}
/* end | autoplay */
Expand Down
17 changes: 13 additions & 4 deletions src/chrome/js/background-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,9 @@ function mainScript(extensionId, SettingData, defaultSettings) {

if (canPlay) {
previousVideoId = document.getElementById("movie_player")?.["getVideoData"]()?.["video_id"] || null;
timer = setTimeout(() => canPlay = false, 300);
}

timer = setTimeout(() => canPlay = false, 300);

}

const override = () => {
Expand Down Expand Up @@ -346,12 +345,22 @@ function mainScript(extensionId, SettingData, defaultSettings) {

};

const onNavigate = () => {
clearTimeout(timer);
canPlay = false;
previousVideoId = null;
};

const update = () => {
if (iridiumSettings.autoplay) {
document.documentElement.removeEventListener("click", onClick, true);
window.removeEventListener("yt-navigate-start", onNavigate, false);
window.removeEventListener("popstate", onNavigate, true);
reset();
} else {
document.documentElement.addEventListener("click", onClick, true);
window.addEventListener("yt-navigate-start", onNavigate, false);
window.addEventListener("popstate", onNavigate, true);
override();
}
};
Expand Down Expand Up @@ -678,7 +687,7 @@ function mainScript(extensionId, SettingData, defaultSettings) {
}

const url = browseEndpoint["canonicalBaseUrl"]
|| (browseEndpoint["browseId"] ? `/channel/${browseEndpoint["browseId"]}` : undefined) ;
|| (browseEndpoint["browseId"] ? `/channel/${browseEndpoint["browseId"]}` : undefined);

if (url) {
metadata.url = link.href = `${url}/${iridiumSettings.channelTab}`;
Expand Down Expand Up @@ -798,7 +807,7 @@ function mainScript(extensionId, SettingData, defaultSettings) {

const donationShelf = document.getElementById("donation-shelf");

if (donationShelf) {
if (donationShelf && sidebar === donationShelf.parentElement) {
sidebar.insertBefore(chat, donationShelf);
} else {
sidebar.prepend(chat);
Expand Down
2 changes: 1 addition & 1 deletion src/firefox/css/content-script.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ini | autoplay */
#movie_player.unstarted-mode > *:not(.ytp-cued-thumbnail-overlay) {
#movie_player.unstarted-mode:is(.playing-mode, .paused-mode) > *:not(.ytp-cued-thumbnail-overlay) {
display: none;
}
/* end | autoplay */
Expand Down
17 changes: 13 additions & 4 deletions src/firefox/js/background-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,9 @@ function mainScript(extensionId, SettingData, defaultSettings) {

if (canPlay) {
previousVideoId = document.getElementById("movie_player")?.["getVideoData"]()?.["video_id"] || null;
timer = setTimeout(() => canPlay = false, 300);
}

timer = setTimeout(() => canPlay = false, 300);

}

const override = () => {
Expand Down Expand Up @@ -346,12 +345,22 @@ function mainScript(extensionId, SettingData, defaultSettings) {

};

const onNavigate = () => {
clearTimeout(timer);
canPlay = false;
previousVideoId = null;
};

const update = () => {
if (iridiumSettings.autoplay) {
document.documentElement.removeEventListener("click", onClick, true);
window.removeEventListener("yt-navigate-start", onNavigate, false);
window.removeEventListener("popstate", onNavigate, true);
reset();
} else {
document.documentElement.addEventListener("click", onClick, true);
window.addEventListener("yt-navigate-start", onNavigate, false);
window.addEventListener("popstate", onNavigate, true);
override();
}
};
Expand Down Expand Up @@ -678,7 +687,7 @@ function mainScript(extensionId, SettingData, defaultSettings) {
}

const url = browseEndpoint["canonicalBaseUrl"]
|| (browseEndpoint["browseId"] ? `/channel/${browseEndpoint["browseId"]}` : undefined) ;
|| (browseEndpoint["browseId"] ? `/channel/${browseEndpoint["browseId"]}` : undefined);

if (url) {
metadata.url = link.href = `${url}/${iridiumSettings.channelTab}`;
Expand Down Expand Up @@ -798,7 +807,7 @@ function mainScript(extensionId, SettingData, defaultSettings) {

const donationShelf = document.getElementById("donation-shelf");

if (donationShelf) {
if (donationShelf && sidebar === donationShelf.parentElement) {
sidebar.insertBefore(chat, donationShelf);
} else {
sidebar.prepend(chat);
Expand Down

0 comments on commit b9ef588

Please sign in to comment.