youtube: better mechanism to wait for page to load
This commit is contained in:
parent
c4f062c081
commit
e3cf1ed586
1 changed files with 10 additions and 5 deletions
|
@ -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);
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue