Guest User

Untitled

a guest
Aug 7th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. // ==UserScript==
  2. // @name EOP Destroyer
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.1.1
  5. // @description Purges EOPs from the Youtube chat, 100% guaranteed to improve your viewing experience.
  6. // @author Anon
  7. // @match http*://*.youtube.com/*
  8. // @grant none
  9. // @require http://code.jquery.com/jquery-latest.js
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Your code here...
  16. })();
  17. javascript:(() => {
  18. let ALLOWED_MESSAGES = ["bgm", "f", "FAQ"]; /*In lower case*/
  19. let FILTER_THRESHOLD = 70; /*How much % of the message should have english letters to be filtered*/
  20. let func = () => {
  21. let chat_list;
  22. (window.location.href.indexOf("youtube.com/live_chat") !== -1) ?
  23. chat_list = window.top.document.querySelector("#items.style-scope.yt-live-chat-item-list-renderer") :
  24. chat_list = window.top.document.getElementById("chatframe")
  25. .contentDocument.querySelector("#items.style-scope.yt-live-chat-item-list-renderer");
  26. let observer = new MutationObserver((mutationsList, observer) => {
  27. let chat_items = chat_list.children;
  28. for(let i = 0; i < chat_items.length; i++) {
  29. if(chat_items[i].dataset.eopFiltered)
  30. continue;
  31.  
  32. let msgNode = chat_items[i].querySelector("#content span#message");
  33. if(!msgNode)
  34. continue;
  35.  
  36. let msg;
  37. for(let i = 0; i < msgNode.childNodes.length; i++) {
  38. let node = msgNode.childNodes[i];
  39. if(node.nodeType === Node.TEXT_NODE) {
  40. msg = node.nodeValue.trim();
  41. break;
  42. }
  43. }
  44. if(!msg || ALLOWED_MESSAGES.includes(msg.toLowerCase()))
  45. continue;
  46.  
  47. let original = msg;
  48. msg = msg.replace(/[\d\^\(\)\[\]w\s.!?,\ufe0e]/g, "");
  49. if(msg.length === 0)
  50. {
  51. continue;
  52. }
  53. let full_len = msg.length;
  54. let en_only_array = msg.match(/[a-z]+/gi);
  55. let en_len = en_only_array ? en_only_array.reduce((a, b) => a + b.length, 0) : 0;
  56. let percentage = en_len / full_len * 100;
  57. if(percentage > FILTER_THRESHOLD) {
  58. let author = chat_items[i].querySelector("#content span#author-name").innerText;
  59. console.log(`Filtered\t${author}: ${original}`);
  60. chat_items[i].style.display = "none";
  61. chat_items[i].dataset.eopFiltered = "y";
  62. }
  63. }
  64. });
  65.  
  66. observer.observe(chat_list, { attributes: false, childList: true, subtree: false });
  67. };
  68.  
  69.  
  70.  
  71. if(window.top.document.readyState === "complete") {
  72. console.log("Top loaded!");
  73. if (window.location.href.indexOf("youtube.com/live_chat") !== -1)
  74. {
  75. let chat_frame = window.top;
  76. let chat_doc = chat_frame.document;
  77. let chat_list = chat_doc.querySelector("#items.style-scope.yt-live-chat-item-list-renderer");
  78. func();
  79. }
  80. else
  81. {
  82. let chat_frame = window.top.document.getElementById("chatframe");
  83. let chat_doc = chat_frame.contentDocument;
  84. let chat_list = chat_doc.querySelector("#items.style-scope.yt-live-chat-item-list-renderer");
  85. if(chat_doc && chat_doc.readyState === "complete" && chat_list) {
  86. console.log("All loaded already");
  87. func();
  88. } else {
  89. console.log("Waiting for chat to load");
  90. chat_frame.contentWindow.addEventListener("load", func);
  91. }
  92. }
  93. }
  94. else {
  95. console.log("Waiting for top to load");
  96. window.top.addEventListener("load", func);
  97. }
  98. })();
Add Comment
Please, Sign In to add comment