Skip to content

Instantly share code, notes, and snippets.

@saenai255
Created May 20, 2019 13:19
Show Gist options
  • Save saenai255/9ffb5edb874626f711e42b2f6a630876 to your computer and use it in GitHub Desktop.
Save saenai255/9ffb5edb874626f711e42b2f6a630876 to your computer and use it in GitHub Desktop.
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