YouTube - Filter Subscriptions Page

hide videos with given title keywords

当前为 2021-06-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube - Filter Subscriptions Page
  3. // @namespace https://zachhardesty.com
  4. // @author Zach Hardesty <zachhardesty7@users.noreply.github.com> (https://github.com/zachhardesty7)
  5. // @description hide videos with given title keywords
  6. // @copyright 2019-2021, Zach Hardesty (https://zachhardesty.com/)
  7. // @license GPL-3.0-only; http://www.gnu.org/licenses/gpl-3.0.txt
  8. // @version 2.0.2
  9.  
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM_registerMenuCommand
  13.  
  14. // @homepageURL https://github.com/zachhardesty7/tamper-monkey-scripts-collection/raw/master/youtube-filter-subscriptions-page.user.js
  15. // @homepageURL https://openuserjs.org/scripts/zachhardesty7/YouTube_-_Filter_Subscriptions_Page
  16. // @supportURL https://github.com/zachhardesty7/tamper-monkey-scripts-collection/issues
  17.  
  18.  
  19. // @match https://www.youtube.com*
  20. // @require https://greasyfork.org/scripts/419640-onelementready/code/onElementReady.js?version=887637
  21. // ==/UserScript==
  22. /* global onElementReady */
  23.  
  24. const HIDDEN_CLASSNAME = "zh-hidden"
  25. const DEFAULT_KEYWORDS = [
  26. "pixelmon",
  27. "dark souls",
  28. "darkest dungeon",
  29. "hot rod garage",
  30. "dirt every day",
  31. "roadkill",
  32. "standard chess",
  33. "no man's sky",
  34. "unboxing",
  35. "week to wicked",
  36. "engine masters",
  37. "hearthstone",
  38. ].join(",")
  39.  
  40. let keywords = GM_getValue("yt-filter-page", DEFAULT_KEYWORDS)
  41.  
  42. const stylesheet = document.createElement("style")
  43. const head = document.head || document.querySelectorAll("head")[0]
  44. stylesheet.id = "hiding" // to edit later
  45. stylesheet.type = "text/css"
  46. stylesheet.append(
  47. document.createTextNode(`
  48. .zh-hidden {
  49. display: none !important;
  50. }
  51. `)
  52. )
  53. head.append(stylesheet)
  54.  
  55. // runs on youtube.com/feed/subscriptions
  56. onElementReady(
  57. "#dismissible.style-scope.ytd-grid-video-renderer",
  58. { findOnce: false },
  59. (el) => {
  60. const videoTitle = el
  61. .querySelector("#details #meta")
  62. .firstElementChild.textContent.toLowerCase()
  63. const parentContainer = el.parentElement
  64.  
  65. for (const keyword of keywords.split(",")) {
  66. if (videoTitle.includes(keyword)) {
  67. parentContainer.classList.add(HIDDEN_CLASSNAME)
  68. return
  69. }
  70. }
  71.  
  72. parentContainer.classList.remove(HIDDEN_CLASSNAME)
  73. }
  74. )
  75.  
  76. // runs on youtube.com
  77. onElementReady(
  78. "#dismissible.style-scope.ytd-rich-grid-media",
  79. { findOnce: false },
  80. (el) => {
  81. const videoTitle = el
  82. .querySelector("#details #meta")
  83. .firstElementChild.textContent.toLowerCase()
  84. const parentContainer = el.parentElement.parentElement.parentElement
  85.  
  86. for (const keyword of keywords.split(",")) {
  87. if (videoTitle.includes(keyword)) {
  88. parentContainer.classList.add(HIDDEN_CLASSNAME)
  89. return
  90. }
  91. }
  92.  
  93. parentContainer.classList.remove(HIDDEN_CLASSNAME)
  94. }
  95. )
  96.  
  97. GM_registerMenuCommand("Set YT Filter Subscriptions Page Keywords", () => {
  98. // eslint-disable-next-line no-alert
  99. const val = prompt(
  100. "input a comma separated list of keywords (you can delete the keywords already here)",
  101. keywords
  102. )
  103.  
  104. keywords = val
  105. GM_setValue("yt-filter-page", val)
  106. })