Guest User

JAP Destroyer v9002

a guest
Sep 3rd, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. // JAP Destroyer v9002
  2. //
  3. // Removes non-English chat messages and superchat in YouTube live chat
  4. //
  5. // v9002: this
  6. // - Fixed messages not appearing after some time
  7. // - Fixed chat scrolling
  8. // - Removed printing of filtered messages as otherwise they would be duplicated over and over
  9. // v9001: https://pastebin.com/uj4rVWa6
  10. // - Modified and improved version of EOP Destroyer https://pastebin.com/XpiKsr8T
  11. // (it didn't support superchats and removed number-only messages)
  12.  
  13. javascript:(() => {
  14. let ALLOWED_MESSAGES = [""]; /*In lower case*/
  15. let FILTER_THRESHOLD = 85; /*How much % of the message should have english letters to not be filtered*/
  16. let func = () => {
  17. let chat_list = window.top.document.getElementById("chatframe")
  18. .contentDocument.querySelector("#items.style-scope.yt-live-chat-item-list-renderer");
  19. let observer = new MutationObserver((mutationsList, observer) => {
  20. let chat_items = chat_list.children;
  21. for(let i = 0; i < chat_items.length; i++) {
  22. let msgNode = chat_items[i].querySelector("#content #message");
  23. if(!msgNode)
  24. continue;
  25.  
  26. let msg = "";
  27. for(let i = 0; i < msgNode.childNodes.length; i++) {
  28. let node = msgNode.childNodes[i];
  29. if(node.nodeType === Node.TEXT_NODE) {
  30. msg += node.nodeValue.trim();
  31. }
  32. }
  33. if(!msg || ALLOWED_MESSAGES.includes(msg.toLowerCase()))
  34. continue;
  35.  
  36. let original = msg;
  37. msg = msg.replace(/[\^\(\)\[\]w\s.!?,\ufe0e]/g, "");
  38. if(msg.length === 0)
  39. continue;
  40.  
  41. let full_len = msg.length;
  42. let en_only_array = msg.match(/[a-z\d]+/gi);
  43. let en_len = en_only_array ? en_only_array.reduce((a, b) => a + b.length, 0) : 0;
  44. let percentage = en_len / full_len * 100;
  45. if(percentage < FILTER_THRESHOLD) {
  46. chat_items[i].style.display = "none";
  47. } else {
  48. chat_items[i].style.display = "";
  49. let scroller = window.top.document.getElementById("chatframe").contentDocument.querySelector("#item-scroller");
  50. scroller.scrollTop = scroller.scrollHeight;
  51. }
  52. }
  53. });
  54.  
  55. observer.observe(chat_list, { attributes: false, childList: true, subtree: false });
  56. };
  57.  
  58. if(window.top.document.readyState === "complete") {
  59. let chat_frame = window.top.document.getElementById("chatframe");
  60. let chat_doc = chat_frame.contentDocument;
  61. let chat_list = chat_doc.querySelector("#items.style-scope.yt-live-chat-item-list-renderer");
  62. if(chat_doc && chat_doc.readyState === "complete" && chat_list) {
  63. console.log("All loaded already");
  64. func();
  65. } else {
  66. console.log("Waiting for chat to load");
  67. chat_frame.contentWindow.addEventListener("load", func);
  68. }
  69. } else {
  70. console.log("Waiting for top to load");
  71. window.top.addEventListener("load", func);
  72. }
  73. })();
Add Comment
Please, Sign In to add comment