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