隐藏youtube google广告

隐藏youtube显示的google广告,自动点击"skip ad"

当前为 2018-02-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hide youtube google ad
  3. // @name:zh-CN 隐藏youtube google广告
  4. // @namespace vince.youtube
  5. // @version 2.0.1
  6. // @description hide youtube google ad,auto click "skip ad"
  7. // @description:zh-CN 隐藏youtube显示的google广告,自动点击"skip ad"
  8. // @author vince ding
  9. // @match *://www.youtube.com/*
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. var closeAd=function (){
  15. var css = '.video-ads .ad-container .adDisplay,#player-ads{ display: none!important; }',
  16. head = document.head || document.getElementsByTagName('head')[0],
  17. style = document.createElement('style');
  18.  
  19. style.type = 'text/css';
  20. if (style.styleSheet){
  21. style.styleSheet.cssText = css;
  22. } else {
  23. style.appendChild(document.createTextNode(css));
  24. }
  25.  
  26. head.appendChild(style);
  27. };
  28. var skipInt;
  29. var log=function(msg){
  30. // unsafeWindow.console.log (msg);
  31. };
  32. var skipAd=function(){
  33. //videoAdUiPreSkipText
  34. //videoAdUiSkipButton
  35. var skiptxt=document.querySelector(".videoAdUiPreSkipText");
  36. if(skiptxt){
  37. var skipText=skiptxt.innerText;
  38. log(skipText);
  39. var _textAry=skipText.split(" ");
  40. var sec=(_textAry.length>0?_textAry[_textAry.length-1]:1);
  41. log(sec);
  42. if((sec-1)>0){
  43. log("wait btn...");
  44. if(skipInt) {clearTimeout(skipInt);}
  45. skipInt=setTimeout(skipAd,500);
  46. }else{
  47. var skipbtn=document.querySelector(".videoAdUiSkipButton");
  48. if(skipbtn){
  49. log("close ad");
  50. skipbtn.click();
  51. }
  52. log("checking...");
  53. if(skipInt) {clearTimeout(skipInt);}
  54. skipInt=setTimeout(skipAd,500);
  55. }
  56. }else{
  57. log("checking skip text...");
  58. if(skipInt) {clearTimeout(skipInt);}
  59. skipInt=setTimeout(skipAd,500);
  60. }
  61. };
  62.  
  63. closeAd();
  64. skipAd();
  65.  
  66. })();