Advertisement
Guest User

Untitled

a guest
Jun 30th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. // ==UserScript==
  2. // @name EOP Destroyer
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.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 = window.top.document.getElementById("chatframe")
  22. .contentDocument.querySelector("#items.style-scope.yt-live-chat-item-list-renderer");
  23. let observer = new MutationObserver((mutationsList, observer) => {
  24. let chat_items = chat_list.children;
  25. for(let i = 0; i < chat_items.length; i++) {
  26. if(chat_items[i].dataset.eopFiltered)
  27. continue;
  28.  
  29. let msgNode = chat_items[i].querySelector("#content span#message");
  30. if(!msgNode)
  31. continue;
  32.  
  33. let msg;
  34. for(let i = 0; i < msgNode.childNodes.length; i++) {
  35. let node = msgNode.childNodes[i];
  36. if(node.nodeType === Node.TEXT_NODE) {
  37. msg = node.nodeValue.trim();
  38. break;
  39. }
  40. }
  41. if(!msg || ALLOWED_MESSAGES.includes(msg.toLowerCase()))
  42. continue;
  43.  
  44. let original = msg;
  45. msg = msg.replace(/[\d\^\(\)\[\]w\s.!?,\ufe0e]/g, "");
  46. if(msg.length === 0)
  47. continue;
  48.  
  49. let full_len = msg.length;
  50. let en_only_array = msg.match(/[a-z]+/gi);
  51. let en_len = en_only_array ? en_only_array.reduce((a, b) => a + b.length, 0) : 0;
  52. let percentage = en_len / full_len * 100;
  53. if(percentage > FILTER_THRESHOLD) {
  54. let author = chat_items[i].querySelector("#content span#author-name").innerText;
  55. console.log(`Filtered\t${author}: ${original}`);
  56. chat_items[i].style.display = "none";
  57. chat_items[i].dataset.eopFiltered = "y";
  58. }
  59. }
  60. });
  61.  
  62. observer.observe(chat_list, { attributes: false, childList: true, subtree: false });
  63. };
  64.  
  65. if(window.top.document.readyState === "complete") {
  66. let chat_frame = window.top.document.getElementById("chatframe");
  67. let chat_doc = chat_frame.contentDocument;
  68. let chat_list = chat_doc.querySelector("#items.style-scope.yt-live-chat-item-list-renderer");
  69. if(chat_doc && chat_doc.readyState === "complete" && chat_list) {
  70. console.log("All loaded already");
  71. func();
  72. } else {
  73. console.log("Waiting for chat to load");
  74. chat_frame.contentWindow.addEventListener("load", func);
  75. }
  76. } else {
  77. console.log("Waiting for top to load");
  78. window.top.addEventListener("load", func);
  79. }
  80. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement