im trying to make a Userscript that removes the comments from the Youtube video page but cant get it to work i tried a lot of methods but keep getting different errors that lead into other errors and stuff
window.addEventListener('load', (event) => {
setTimeout(function(){
document.document.querySelector("#comments")[0].remove()
}, 2000);
});
i also tried this version
(function () {
window.addEventListener('load', function () {
setTimeout(() => {(function () {
var CommentSection = document.querySelector("#comments");
if (CommentSection) {
CommentSection.parentNode.removeChild(CommentSection);
}
})})
}, false);
console.log("should be removed //")
})()
but both give errors the hard thing is that the comments dont load immediately but load slowly and separately
thanks in advance
Inserting a CSS rule that hides the section would be easier.
document.body.appendChild(document.createElement('style')).textContent = '.ytd-comments { display: none; }';
The .ytd-comments
is the container for all the comments on a video, so setting it to display: none
will hide it.