youtube_block_comments

Hide videos comments including specified words. (不愉快なコメントを非表示にする)

  1. // ==UserScript==
  2. // @name youtube_block_comments
  3. // @namespace https://catherine.v0cyc1pp.com/
  4. // @include https://www.youtube.com/*
  5. // @author greg10
  6. // @run-at document-start
  7. // @license GPL 3.0
  8. // @version 0.1
  9. // @grant none
  10. // @description Hide videos comments including specified words. (不愉快なコメントを非表示にする)
  11. // ==/UserScript==
  12.  
  13.  
  14. //================================
  15. // Configurations
  16. // - specify texts you don't want to see.
  17. var g_list = [
  18. "毛in濃すぎ",
  19. ];
  20. //================================
  21.  
  22.  
  23.  
  24.  
  25. function main() {
  26.  
  27. //$("div.yt-lockup-content").each(function() {
  28. document.querySelectorAll("ytd-comment-thread-renderer").forEach(function(elem) {
  29. //var str = $(this).text();
  30. var str = elem.innerText;
  31. //console.log("str="+str);
  32.  
  33. for (var i = 0; i < g_list.length; ++i) {
  34. var ngword = g_list[i];
  35. if (ngword == "") continue;
  36.  
  37. ngword = ngword.replace(/^\s+|\s+$/g, "");
  38.  
  39. var obj = new RegExp(ngword, "i");
  40. var index = str.search(obj);
  41. //var index = str.indexOf( ngword );
  42. if (index != -1) {
  43. //$(this).parent("div").parent("div").parent("li").hide();
  44. elem.style.display = "none";
  45. //console.log("str="+str);
  46. }
  47. }
  48. });
  49. }
  50.  
  51. var observer = new MutationObserver(function(mutations) {
  52. observer.disconnect();
  53. main();
  54. observer.observe(document, config);
  55. });
  56.  
  57. //var config = { attributes: true, childList: true, characterData: true, subtree:true }
  58. var config = {
  59. childList: true,
  60. characterData: true,
  61. subtree: true
  62. }
  63.  
  64. observer.observe(document, config);