TheRiverVan / Block url spammers in youtube livechat.

// ==UserScript==
// @name         Block url spammers in youtube livechat.
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Block spammers in the youtube livechat (made for the defqon1 spamm.)
// @author       https://therivervan.com
// @include     https://www.youtube.com/watch*
// @grant        none
// @run-at document-idle
// @license MIT
// ==/UserScript==

(function () {
  'use strict';
  setTimeout(function () {
    //iframe chat
    var iframe = document.getElementById('chatframe');
    var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
    //actual chat
    var chat = innerDoc.getElementById("item-offset")

    var config = {
      attributes: true,
      childList: true,
      subtree: true
    };

    var callback = function (mutationsList, observer) {
      for (var mutation of mutationsList) {
        if (mutation.type == "childList" && mutation.target.id == "message") {
          mutation.addedNodes.forEach(node => {
            if (node.nodeName == "A") {
              try {
                node.parentNode.parentNode.parentNode.parentNode.removeChild(node.parentNode.parentNode.parentNode)
              }
              catch (e) {
                console.log("Spammer blocked :D")
              }
            }

          })

        }

      }
    };

    var observer = new MutationObserver(callback);
    observer.observe(chat, config);
  }, 9000);
})();