2021-02-04 22:58:41 -05:00
|
|
|
// ==UserScript==
|
|
|
|
// @name Turn off Youtube Autoplay
|
|
|
|
// @namespace https://bubbletea.dev/
|
2024-07-17 17:49:31 -04:00
|
|
|
// @version 2.1.0
|
2021-02-04 22:58:41 -05:00
|
|
|
// @description Disables Youtube recommended videos from automatically playing
|
|
|
|
// @author shibao
|
|
|
|
// @include https://www.youtube.com/watch*
|
2022-01-06 22:22:13 -05:00
|
|
|
// @downloadURL https://gitea.bubbletea.dev/shibao/disable-youtube-autoplay/raw/branch/stable/disable-youtube-autoplay.user.js
|
|
|
|
// @updateURL https://gitea.bubbletea.dev/shibao/disable-youtube-autoplay/raw/branch/stable/disable-youtube-autoplay.user.js
|
2021-02-04 22:58:41 -05:00
|
|
|
// @grant none
|
|
|
|
// ==/UserScript==
|
|
|
|
|
2022-01-06 22:22:13 -05:00
|
|
|
// from https://developer.mozilla.org/en-US/docs/Web/API/Node#recurse_through_child_nodes
|
|
|
|
function eachNode(rootNode, callback) {
|
|
|
|
if (!callback) {
|
|
|
|
const nodes = []
|
|
|
|
eachNode(rootNode, function (node) {
|
|
|
|
nodes.push(node)
|
|
|
|
})
|
|
|
|
return nodes
|
|
|
|
}
|
|
|
|
|
|
|
|
if (false === callback(rootNode)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rootNode.hasChildNodes()) {
|
|
|
|
const nodes = rootNode.childNodes
|
|
|
|
for (let i = 0, l = nodes.length; i < l; ++i) {
|
|
|
|
if (false === eachNode(nodes[i], callback)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-02-04 22:58:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
2022-01-06 22:22:13 -05:00
|
|
|
|
|
|
|
const observer = new MutationObserver(function (mutationList) {
|
|
|
|
for (const mutation of mutationList) {
|
|
|
|
for (const addedNode of mutation.addedNodes) {
|
|
|
|
// recurses through all child nodes as well
|
|
|
|
eachNode(addedNode, function (node) {
|
2024-07-17 17:49:31 -04:00
|
|
|
node.nodeName == 'DIV' &&
|
2022-01-06 22:22:13 -05:00
|
|
|
node.classList.contains('ytp-autonav-toggle-button') &&
|
2024-07-17 17:49:31 -04:00
|
|
|
node.getAttribute('aria-checked') == "true" &&
|
|
|
|
node.click();
|
2022-01-06 22:22:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
observer.observe(document, {
|
|
|
|
childList: true,
|
|
|
|
subtree: true,
|
|
|
|
attributes: true
|
|
|
|
});
|
|
|
|
})();
|