YouTube去广告

简单高效的YouTube去广告脚本,拒绝花里胡哨.这个脚本可以移除所有广告,甚至是视频广告.如果你有一丢丢编程知识,可以尝试为常量cssSeletorArr定义元素.如果你有好的建议可以联系我(zgh0118c@gmail.com).

当前为 2023-02-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube去广告
  3. // @name:zh-CN YouTube去广告
  4. // @name:zh-TW YouTube去廣告
  5. // @name:ar YouTube AD Blocker
  6. // @name:bg YouTube AD Blocker
  7. // @name:cs YouTube AD Blocker
  8. // @name:da YouTube AD Blocker
  9. // @name:de YouTube AD Blocker
  10. // @name:el YouTube AD Blocker
  11. // @name:eo YouTube AD Blocker
  12. // @name:es YouTube AD Blocker
  13. // @name:fi YouTube AD Blocker
  14. // @name:fr YouTube AD Blocker
  15. // @name:fr-CA YouTube AD Blocker
  16. // @name:he YouTube AD Blocker
  17. // @name:hu YouTube AD Blocker
  18. // @name:id YouTube AD Blocker
  19. // @name:ko YouTube AD Blocker
  20. // @name:nb YouTube AD Blocker
  21. // @name:nl YouTube AD Blocker
  22. // @name:pl YouTube AD Blocker
  23. // @name:pt-BR YouTube AD Blocker
  24. // @name:ro YouTube AD Blocker
  25. // @name:ru YouTube AD Blocker
  26. // @name:sk YouTube AD Blocker
  27. // @name:sr YouTube AD Blocker
  28. // @name:sv YouTube AD Blocker
  29. // @name:th YouTube AD Blocker
  30. // @name:tr YouTube AD Blocker
  31. // @name:uk YouTube AD Blocker
  32. // @name:ug YouTube AD Blocker
  33. // @name:vi YouTube AD Blocker
  34. // @name:it YouTube AD Blocker
  35. // @name:ja YouTubeの広告を削除します
  36. // @name:kr 포함한 YouTube 광고 차단
  37.  
  38. // @namespace http://tampermonkey.net/
  39. // @version 1.33
  40.  
  41. // @description 简单高效的YouTube去广告脚本,拒绝花里胡哨.这个脚本可以移除所有广告,甚至是视频广告.如果你有一丢丢编程知识,可以尝试为常量cssSeletorArr定义元素.如果你有好的建议可以联系我(zgh0118c@gmail.com).
  42. // @description:zh-CN 简单高效的YouTube去广告脚本,拒绝花里胡哨.这个脚本可以移除所有广告,甚至是视频广告.如果你有一丢丢编程知识,可以尝试为常量cssSeletorArr定义元素.如果你有好的建议可以联系我(zgh0118c@gmail.com).
  43. // @description:zh-TW 簡單高效的YouTube去廣告腳本,拒絕花裏胡哨.這個腳本可以移除所有廣告,甚至是視頻廣告.如果你有一丟丟編程知識,可以嘗試為常量cssSeletorArr定義元素.如果你有好的建議可以聯系我(zgh0118c@gmail.com).
  44. // @description:ar Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  45. // @description:bg Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  46. // @description:cs Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  47. // @description:da Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  48. // @description:de Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  49. // @description:el Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  50. // @description:eo Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  51. // @description:es Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  52. // @description:fi Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  53. // @description:fr Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  54. // @description:fr-CA Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  55. // @description:he Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  56. // @description:hu Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  57. // @description:id Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  58. // @description:ko Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  59. // @description:nb Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  60. // @description:nl Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  61. // @description:pl Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  62. // @description:pt-BR Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  63. // @description:ro Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  64. // @description:ru Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  65. // @description:sk Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  66. // @description:sr Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  67. // @description:sv Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  68. // @description:th Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  69. // @description:tr Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  70. // @description:uk Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  71. // @description:ug Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  72. // @description:vi Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  73. // @description:it Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  74. // @description:ja Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  75. // @description:kr Simple and efficient YouTube AD Blocker, no bells and whistles. The script removes all ads, even video ads. If you have a little programming knowledge, you can try editing the constant cssSeletorArr. If you have any good suggestions, you can contact me (zgh0118c@gmail.com).
  76.  
  77. // @author iamfugui
  78. // @match *://*.youtube.com/*
  79. // @icon https://www.google.com/s2/favicons?sz=64&domain=YouTube.com
  80. // @grant none
  81. // @license MIT
  82. // ==/UserScript==
  83. (function() {
  84. 'use strict';
  85.  
  86. //界面广告选择器
  87. const cssSeletorArr = [
  88. `#mastheAD-AD`,//首页顶部横幅广告. Homepage banner AD1.
  89. `ytd-rich-item-renderer.style-scope.ytd-rich-grid-row:has(.ytd-display-AD-renderer)`,//首页视频排版广告. Homepage video layout AD.
  90. `ytd-rich-section-renderer #dismissible`,//首页中部横幅广告. Homepage banner AD2.
  91. `.video-ADs.ytp-AD-module`,//播放器底部广告. Player bottom AD.
  92. `tp-yt-paper-dialog:has(yt-mealbar-promo-renderer)`,//播放页会员促销广告. Play page member promotion AD.
  93. `#related #player-ADs`,//播放页评论区右侧推广广告. Play page, right side, promotion AD.
  94. `#related ytd-AD-slot-renderer`,//播放页评论区右侧视频排版广告. Play page, right side, video layout AD.
  95. `ytd-search-pyv-renderer:has(ytd-AD-slot-renderer)`,//搜索页广告. Search page AD.
  96. ];
  97.  
  98. /**
  99. * 生成去除广告的css元素style并附加到HTML节点上
  100. * @param {String} styles 样式文本
  101. * @param {String} styleId 元素id
  102. * @return {undefined}
  103. */
  104. function generateRemoveADHTMLElement(styles,styleId) {
  105. //如果已经设置过,退出. If alreADy set.
  106. if (document.getElementById(styleId)) {
  107. return false
  108. }
  109.  
  110. //设置移除广告样式. Remove AD CSS.
  111. let style = document.createElement(`style`);//创建style元素. Create element style.
  112. style.id = styleId;
  113. (document.querySelector(`heAD`) || document.querySelector(`body`)).appendChild(style);//将节点附加到HTML. Append html node.
  114. style.appendChild(document.createTextNode(styles));//附加样式节点到元素节点. Append element node.
  115. }
  116.  
  117. /**
  118. * 生成去除广告的css文本
  119. * @param {Array} cssSeletorArr 待设置css选择器数组
  120. * @return {String}
  121. */
  122. function generateRemoveADCssText(cssSeletorArr){
  123. cssSeletorArr.forEach((seletor,index)=>{
  124. cssSeletorArr[index]=`${seletor}{display:none!important}`;//遍历并设置样式. Setting css.
  125. });
  126. return cssSeletorArr.join(" ");//拼接成字符串. Return string.
  127. }
  128.  
  129. /**
  130. * 去除播放中的广告
  131. * @return {undefined}
  132. */
  133. function removePlayerAD(){
  134. let timerId =setInterval(function(){
  135. //拥有跳过按钮的广告. Use the Skip button.
  136. let skipButton = document.querySelector(`.ytp-AD-skip-button`);
  137. if(skipButton)
  138. {
  139. skipButton.click();// 跳过广告. Skip AD.
  140. return false;//防止后面错判. Return.
  141. }
  142.  
  143. //片头短广告. Short AD.
  144. let ADShortMsg = document.querySelector(`.video-ADs.ytp-AD-module .ytp-AD-player-overlay`);
  145. if(ADShortMsg){
  146. location.href = location.href;//重新加载. ReloAD.
  147. clearInterval(timerId);
  148. }
  149.  
  150. }, 16);//主流屏幕刷新率为60hz,此设置与16.666666毫秒每帧对应. The mainstream screen refresh rate is 60hz, which corresponds to 16.666666 milliseconds per frame.
  151. }
  152.  
  153. /**
  154. * main函数
  155. */
  156. function main(){
  157. generateRemoveADHTMLElement(generateRemoveADCssText(cssSeletorArr),`removeAD`);//移除界面中的广告. Remove AD from page.
  158. removePlayerAD();//移除播放中的广告. Remove AD from player.
  159. }
  160. main();
  161.  
  162. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址