Youtube hide specific comment button

Adds a hide button on the right of every comments

ของเมื่อวันที่ 28-01-2023 ดู เวอร์ชันล่าสุด

// ==UserScript==
// @name        Youtube hide specific comment button
// @namespace   https://greasyfork.org/en/users/938672-alban-thouvignon
// @description Adds a hide button on the right of every comments
// @match       *://youtube.com/*
// @match       *://www.youtube.com/*
// @version     1.0
// @license     MIT
// @grant       GM_addStyle
// ==/UserScript==

const intervalID = setInterval(myCallback, 500);

function myCallback() {
    if(!document.getElementById('contents').children[0].children["comment"]) {
        return;
    }

    const comments = Array.from(document.getElementById('contents').children);
    comments.pop();

    comments.forEach((e, i) => {
        const comment = e.children["comment"].children["body"].children["main"].children["header"].children["header-author"];
        if (!!comment.children["hideButton"]) {
            return;
        }
        const hideButton = document.createElement("span");
        hideButton.id = 'hideButton';
        hideButton.className = 'published-time-text ytd-comment-renderer yt-simple-endpoint style-scope yt-formatted-string';
        hideButton.textContent = '  Hide  ';
        hideButton.style.cssText = 'white-space:pre-wrap';
        hideButton.style.marginLeft = 'auto';
        hideButton.style.marginRight = '0';
        hideButton.onclick = function() {
            comments[i].style.display = 'none';
        };
        comment.appendChild(hideButton);
    });
}