fix flaky behavior

This commit is contained in:
shibao 2024-07-17 17:49:31 -04:00
parent 6b61284849
commit 0a8b4c059e

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name Turn off Youtube Autoplay
// @namespace https://bubbletea.dev/
// @version 2.0
// @version 2.1.0
// @description Disables Youtube recommended videos from automatically playing
// @author shibao
// @include https://www.youtube.com/watch*
@ -42,12 +42,10 @@ function eachNode(rootNode, callback) {
for (const addedNode of mutation.addedNodes) {
// recurses through all child nodes as well
eachNode(addedNode, function (node) {
if (node.nodeName == 'DIV' &&
node.nodeName == 'DIV' &&
node.classList.contains('ytp-autonav-toggle-button') &&
node.getAttribute('aria-checked') == "true") {
const button = node.closest("button");
if (button) { setTimeout(() => button.click(), 1000); }
}
node.getAttribute('aria-checked') == "true" &&
node.click();
});
}
};