YouTube去广告

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

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

  1. // ==UserScript==
  2. // @name YouTube去广告
  3. // @name:zh-CN YouTube去广告
  4. // @name:zh-TW YouTube去廣告
  5. // @name:ar Remove YouTube AD
  6. // @name:bg Remove YouTube AD
  7. // @name:cs Remove YouTube AD
  8. // @name:da Remove YouTube AD
  9. // @name:de Remove YouTube AD
  10. // @name:el Remove YouTube AD
  11. // @name:eo Remove YouTube AD
  12. // @name:es Remove YouTube AD
  13. // @name:fi Remove YouTube AD
  14. // @name:fr Remove YouTube AD
  15. // @name:fr-CA Remove YouTube AD
  16. // @name:he Remove YouTube AD
  17. // @name:hu Remove YouTube AD
  18. // @name:id Remove YouTube AD
  19. // @name:ko Remove YouTube AD
  20. // @name:nb Remove YouTube AD
  21. // @name:nl Remove YouTube AD
  22. // @name:pl Remove YouTube AD
  23. // @name:pt-BR Remove YouTube AD
  24. // @name:ro Remove YouTube AD
  25. // @name:ru Remove YouTube AD
  26. // @name:sk Remove YouTube AD
  27. // @name:sr Remove YouTube AD
  28. // @name:sv Remove YouTube AD
  29. // @name:th Remove YouTube AD
  30. // @name:tr Remove YouTube AD
  31. // @name:uk Remove YouTube AD
  32. // @name:ug Remove YouTube AD
  33. // @name:vi Remove YouTube AD
  34. // @name:it Remove YouTube AD
  35. // @name:ja YouTubeの広告を削除します
  36. // @name:kr 포함한 YouTube 광고 차단
  37.  
  38. // @namespace http://tampermonkey.net/
  39. // @version 1.32
  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 remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  45. // @description:bg Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  46. // @description:cs Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  47. // @description:da Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  48. // @description:de Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  49. // @description:el Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  50. // @description:eo Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  51. // @description:es Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  52. // @description:fi Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  53. // @description:fr Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  54. // @description:fr-CA Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  55. // @description:he Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  56. // @description:hu Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  57. // @description:id Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  58. // @description:ko Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  59. // @description:nb Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  60. // @description:nl Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  61. // @description:pl Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  62. // @description:pt-BR Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  63. // @description:ro Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  64. // @description:ru Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  65. // @description:sk Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  66. // @description:sr Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  67. // @description:sv Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  68. // @description:th Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  69. // @description:tr Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  70. // @description:uk Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  71. // @description:ug Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  72. // @description:vi Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  73. // @description:it Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  74. // @description:ja Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  75. // @description:kr Simple and efficient YouTube remove AD script, no bells and whistles. If you have a little programming knowledge, you can try to define cssSeletorArr. If you have suggestions, you can contact me (zgh0118c@gmail.com).
  76.  
  77. // @author FuckAD
  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. ];
  96.  
  97. /**
  98. * 生成去除广告的css元素style并附加到HTML节点上
  99. * @param {String} styles 样式文本
  100. * @param {String} styleId 元素id
  101. * @return {undefined}
  102. */
  103. function generateRemoveAdHTMLElement(styles,styleId) {
  104. //如果已经设置过,退出. If already set.
  105. if (document.getElementById(styleId)) {
  106. return false
  107. }
  108.  
  109. //设置移除广告样式. Remove AD CSS.
  110. let style = document.createElement(`style`);//创建style元素. Create element style.
  111. style.id = styleId;
  112. (document.querySelector(`head`) || document.querySelector(`body`)).appendChild(style);//将节点附加到HTML. Append html node.
  113. style.appendChild(document.createTextNode(styles));//附加样式节点到元素节点. Append element node.
  114. }
  115.  
  116. /**
  117. * 生成去除广告的css文本
  118. * @param {Array} cssSeletorArr 待设置css选择器数组
  119. * @return {String}
  120. */
  121. function generateRemoveAdCssText(cssSeletorArr){
  122. cssSeletorArr.forEach((seletor,index)=>{
  123. cssSeletorArr[index]=`${seletor}{display:none!important}`;//遍历并设置样式. Setting css.
  124. });
  125. return cssSeletorArr.join(" ");//拼接成字符串. Return string.
  126. }
  127.  
  128. /**
  129. * 去除播放中的广告
  130. * @return {undefined}
  131. */
  132. function removePlayerAd(){
  133. let timerId =setInterval(function(){
  134. //拥有跳过按钮的广告. Use the Skip button.
  135. let skipButton = document.querySelector(`.ytp-ad-skip-button`);
  136. if(skipButton)
  137. {
  138. skipButton.click();// 跳过广告. Skip AD.
  139. return false;//防止后面错判. Return.
  140. }
  141.  
  142. //片头短广告. Short AD.
  143. let adShortMsg = document.querySelector(`.video-ads.ytp-ad-module .ytp-ad-player-overlay`);
  144. if(adShortMsg){
  145. location.href = location.href;//重新加载. Reload.
  146. clearInterval(timerId);
  147. }
  148.  
  149. }, 16);//主流屏幕刷新率为60hz,此设置与16.666666毫秒每帧对应. The mainstream screen refresh rate is 60hz, which corresponds to 16.666666 milliseconds per frame.
  150.  
  151.  
  152. }
  153.  
  154. /**
  155. * main函数
  156. */
  157. function main(){
  158. generateRemoveAdHTMLElement(generateRemoveAdCssText(cssSeletorArr),`removeAd`);//移除界面中的广告. Remove AD from page.
  159. removePlayerAd();//移除播放中的广告. Remove AD from player.
  160. }
  161. main();
  162.  
  163. })();

QingJ © 2025

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