Compare commits
2 Commits
6b61284849
...
d73968c5ed
Author | SHA1 | Date | |
---|---|---|---|
d73968c5ed | |||
0a8b4c059e |
@ -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*
|
||||
@ -13,49 +13,47 @@
|
||||
// from https://developer.mozilla.org/en-US/docs/Web/API/Node#recurse_through_child_nodes
|
||||
function eachNode(rootNode, callback) {
|
||||
if (!callback) {
|
||||
const nodes = []
|
||||
const nodes = [];
|
||||
eachNode(rootNode, function (node) {
|
||||
nodes.push(node)
|
||||
})
|
||||
return nodes
|
||||
nodes.push(node);
|
||||
});
|
||||
return nodes;
|
||||
}
|
||||
|
||||
if (false === callback(rootNode)) {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rootNode.hasChildNodes()) {
|
||||
const nodes = rootNode.childNodes
|
||||
const nodes = rootNode.childNodes;
|
||||
for (let i = 0, l = nodes.length; i < l; ++i) {
|
||||
if (false === eachNode(nodes[i], callback)) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
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) {
|
||||
if (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.nodeName == "DIV" &&
|
||||
node.classList.contains("ytp-autonav-toggle-button") &&
|
||||
node.getAttribute("aria-checked") == "true" &&
|
||||
node.click();
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(document, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
attributes: true
|
||||
attributes: true,
|
||||
});
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user