Guest User

youtube_chat_shortener

a guest
Sep 17th, 2020
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         youtube_chat_shortener
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1
  5. // @description  this script fires the indians working for google
  6. // @author       Ina
  7. // @match        *.youtube.com/live_chat*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11.  
  12. (function() {
  13.     'use strict';
  14.  
  15.     const targetNode = document.querySelector("#item-offset").querySelector("#items");
  16.  
  17.     targetNode.innerHTML = "";
  18.  
  19.     const chatOptimizer = function (mutationsList, observer) {
  20.         for(let mutation of mutationsList) {
  21.             if (mutation.addedNodes[0] && (mutation.addedNodes[0].nodeName=="YT-LIVE-CHAT-PAID-MESSAGE-RENDERER" || mutation.addedNodes[0].nodeName=="YT-LIVE-CHAT-TEXT-MESSAGE-RENDERER")){
  22.                 //the '17' bellow is how many posts you'll see in the chat. this doesn't include the super chats attached at the top. you can always check those
  23.                 //the next two lines are intentionally duplicate
  24.                 if (targetNode.childElementCount>17) {
  25.                     targetNode.removeChild(targetNode.firstChild);
  26.                     targetNode.removeChild(targetNode.firstChild);
  27.                 }
  28.             }
  29.         }
  30.     };
  31.  
  32.     const chatObserver = new MutationObserver(chatOptimizer);
  33.     chatObserver.observe(targetNode, { attributes: false, childList: true, subtree: true, characterData: false, characterDataOldValue: false });
  34.  
  35. })();
  36.  
  37.  
Add Comment
Please, Sign In to add comment