ytch/ytch.user.js

47 lines
1.8 KiB
JavaScript

// ==UserScript==
// @name Youtube comment hider
// @namespace https://austenwares.com/gogs/stonewareslord/ytch
// @description Hides youtube comments that contain specified text
// @author stonewareslord
// @version 0.1.1
// @homepage https://austenwares.com/gogs/stonewareslord/ytch
// @include http://youtube.com/watch*
// @include https://youtube.com/watch*
// @include http://www.youtube.com/watch*
// @include https://www.youtube.com/watch*
// @run-at document-body
// ==/UserScript==
// Options
// Set this to 'hide' to hide comments that contain words
// Set this to 'dim' to dim comments that contain words
var hideCommentOrDimComment = 'dim';
// Set this to an array of words or phrases to check for (case sensitive)
// All entries should be wrapped in '' or ""
// All entries except the last one should end in a comma after ' or "
var wordList = [
'Example first string',
'Example second string',
"Example third string (with quotes)",
'Example last string (no comma after tick)'
];
function clearComments(){
comments = document.querySelectorAll('.comment-item>.content>.comment-text>.comment-text-content');
for (var i = 0; i < comments.length; i++) {
for (var j = 0; j < wordList.length; j++) {
if (comments[i].textContent.includes(wordList[j])) {
commentToRemove=comments[i].parentNode.parentNode.parentNode;//.parentNode;
if(hideCommentOrDimComment == 'hide'){
// They want to hide, remove the comment
commentToRemove.parentNode.removeChild(commentToRemove);
} else if(hideCommentOrDimComment == 'dim'){
// They want to dim, set the opacity to 40%
commentToRemove.style.opacity = 0.4;
} else {
// hideCommentOrDimComment is improperly set, do nothing
}
}
}
}
}
setInterval(clearComments, 1000);