Created
May 20, 2019 13:19
-
-
Save saenai255/9ffb5edb874626f711e42b2f6a630876 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setToggles() { | |
document.querySelectorAll('.ytd-watch-next-secondary-results-renderer').forEach(video => { | |
if(video.querySelector('paper-toggle-button')) { | |
return; | |
} | |
const link = video.querySelector('a'); | |
if(!link) { | |
return; | |
} | |
const href = link.href; | |
const toggle = document.querySelector('paper-toggle-button').cloneNode(); | |
toggle.checked = false; | |
toggle.addEventListener('change', () => { | |
if(!toggle.checked) { | |
window.playNext = undefined; | |
return; | |
} | |
document.querySelectorAll('paper-toggle-button').forEach(x => x.checked = false); | |
toggle.checked = true; | |
console.log('playing next: ' + href); | |
window.playNext = href; | |
}); | |
video.appendChild(toggle); | |
}); | |
} | |
const toggleInterval = setInterval(() => { | |
if(document.querySelectorAll('.ytd-watch-next-secondary-results-renderer') < 2) { | |
return; | |
} | |
setToggles(); | |
}, 500); | |
setInterval(() => { | |
const currentTime = document.querySelector('.ytp-time-current').innerText; | |
const durationTime = document.querySelector('.ytp-time-duration').innerText; | |
if(currentTime === durationTime) { | |
window.location.href = window.playNext; | |
} | |
}, 500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment