1
Fork 0

youtube: better mechanism to wait for page to load

This commit is contained in:
Conduitry 2020-04-27 18:36:12 -04:00
parent c4f062c081
commit e3cf1ed586
1 changed files with 10 additions and 5 deletions

View File

@ -7,9 +7,14 @@
// @version 0
// ==/UserScript==
setTimeout(() => {
const el = document.querySelector('.ytd-compact-autoplay-renderer[role=button][aria-pressed=true]');
if (el) {
el.dispatchEvent(new MouseEvent('click'));
(async () => {
let el;
if (location.pathname === '/watch') {
while (!(el = document.querySelector('.ytd-compact-autoplay-renderer[role=button]'))) {
await new Promise(res => setTimeout(res, 100));
}
if (el.getAttribute('aria-pressed') === 'true') {
el.dispatchEvent(new MouseEvent('click'));
}
}
}, 5000);
})();