Skip to content

Commit

Permalink
Fixed autoplay for YouTube Music
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnyP36 committed Sep 9, 2022
1 parent 7ad726d commit 68980f0
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions manifest_v3/js/autoplay+loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let YTNonstop = function YTNonstop(options) {
* 5 – video cued
*/
const get_YT={
player: () => document.getElementById("movie_player"),
player: () => document.getElementById("movie_player") || document.getElementById("player"),
loop: {
button: () => playlistActionMenu()[1],
status: function() {
Expand Down Expand Up @@ -89,7 +89,7 @@ let YTNonstop = function YTNonstop(options) {
},
callback: (MutationList, Observer) => {
// check if mutationList has the 'attributes' type
if(MutationList.some(t => t.type === "attributes")) {
if(MutationList.some(el => el.type === "attributes")) {
// get "you there?" popup
const p = window.document.getElementById("confirm-button") || window.document.getElementsByClassName('ytmusic-you-there-renderer')[2] || undefined;
if(p){
Expand All @@ -109,13 +109,29 @@ let YTNonstop = function YTNonstop(options) {
//set play button observer
const pb_Observer = new MutationObserver(Play_Pause.callback);
pb_Observer.observe(Play_Pause.getButton, Play_Pause.config);


//set autonav button
Settings.setAutonav();

//set loop button
Settings.setLoop();

clearInterval(Settings.setInterval)
}, 1000),

setAutonav: function() {
const on = document.querySelector('.ytp-autonav-toggle-button-container > .ytp-autonav-toggle-button[aria-checked="true"]')
|| document.querySelector('#automix[role="button"][aria-pressed="true"]')
const off = document.querySelector('.ytp-autonav-toggle-button-container > .ytp-autonav-toggle-button[aria-checked="false"]')
|| document.querySelector('#automix[role="button"][aria-pressed="false"]')

if (Nonstop.getIsAutoSkip() == true) {
off.click();
} else {
on.click();
}
},

setLoop: function() {
if(get_YT.loop.button() && Nonstop.getIsAutoLoop() && !get_YT.loop.status()) {
get_YT.loop.button().click()
Expand All @@ -125,7 +141,8 @@ let YTNonstop = function YTNonstop(options) {

setInterval(() => {
yt.util && yt.util.activity && yt.util.activity.setTimestamp();
Settings.setLoop()
Settings.setLoop();
Settings.setAutonav()
}, 5000);

return Nonstop
Expand Down

0 comments on commit 68980f0

Please sign in to comment.