Youtube live verified comments highlighter

Shows (also logs) youtube live comments of verified persons

Fra 15.07.2021. Se den seneste versjonen.

// ==UserScript==
// @name         Youtube live verified comments highlighter
// @name:ru      Выделение комментариев от верифицированных пользователей на Youtube трансляциях
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Shows (also logs) youtube live comments of verified persons
// @description:ru  Показывает (а также записывает в лог) комментарии от верифицированных пользователей на Youtube трансляциях.
// @author       dark1103
// @include      https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?domain=youtube.com
// @grant        none
// @require http://code.jquery.com/jquery-3.4.1.min.js
// ==/UserScript==

(function() {
    'use strict';

    function setup(){
        const style = document.createElement('style');
        style.innerHTML = `
      #notification_live_chat {
    z-index:1000000!important;
    position:fixed;
    top:0px;
    width:100%;
    text-align:center;
    font-weight:normal;
    font-size:14px;
    color:black;
    background-color:lightgray;
    padding:5px;
}
#notification_live_chat span.dismiss {
    border:2px solid #FFF;
    padding:0 5px;
    cursor:pointer;
    float:right;
    margin-right:10px;
}
#notification_live_chat a {
    color:white;
    text-decoration:none;
    font-weight:bold
}
    `;
        document.head.appendChild(style);
        const node = $('<div id="notification_live_chat" style="display: none;"><span class="text"></span><span class="dismiss"><a title="dismiss this notification">x</a></span></div>');
        node.appendTo(document.body);
    }
    var to = undefined;
    function notify(str){
        if(to !== undefined){
            clearTimeout(to);
        }

        const node = $('#notification_live_chat');
        node.fadeIn("slow").find('.text').html(str);
        node.find(".dismiss").click(function(){
            $(node).fadeOut("fast");
        });
        to = setTimeout(function(){
            $(node).fadeOut("slow");
        }, 12000);
    }

    setup();

    $('yt-live-chat-app').bind("DOMSubtreeModified", function(e) {
        var target = $(e.target);

        if(target.prop("tagName") === 'YT-LIVE-CHAT-TEXT-MESSAGE-RENDERER'){
            var count = target.find('yt-live-chat-author-badge-renderer[type="verified"]').length;
            if(count > 0){
                target.find('#message').bind("DOMSubtreeModified", function(ee) {
                    var author = target.find('#author-name').text();
                    var text = $(this).text();
                    //notify(author + ": " + text);
                    notify('<span style="color: hsl(225, 84%, 66%);font-weight:bold">' + author + '</span> ' + text);
                    console.log(author + ": " + text);
                });
            }
        }
    });
})();