Tiny Customize

针对一些常用网站的反反广告、自动化等。

As of 2016-06-01. See the latest version.

  1. // ==UserScript==
  2. // @name Tiny Customize
  3. // @description 针对一些常用网站的反反广告、自动化等。
  4. // @namespace xiaochao.k@gmail.com
  5. // @author xiaochao.k@gmail.com
  6. // @include http://forum.gamer.com.tw/*
  7. // @include http://bbs.kafan.cn/*
  8. // @version 1.0.2
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. if (typeof unsafeWindow == "undefined")
  13. {
  14. unsafeWindow = window;
  15. }
  16.  
  17. /**
  18. * 获取立即执行的操作。
  19. */
  20. const getInstantActions = function()
  21. {
  22. const host = unsafeWindow.location.host;
  23. const actions = [];
  24.  
  25. if (host === "forum.gamer.com.tw")
  26. {
  27. // 巴哈姆特。
  28. // 反反广告检测。
  29. const action = function()
  30. {
  31. if (unsafeWindow.AntiAd)
  32. {
  33. unsafeWindow.AntiAd.check = function() {};
  34. }
  35. };
  36. actions.push(action);
  37. }
  38. else if (host === "bbs.kafan.cn")
  39. {
  40. // 卡饭论坛。
  41. // 屏蔽方向键翻页。
  42. const action = function()
  43. {
  44. if (unsafeWindow.keyPageScroll)
  45. {
  46. unsafeWindow.keyPageScroll = function() {};
  47. }
  48. };
  49. actions.push(action);
  50. }
  51.  
  52. return actions;
  53. };
  54.  
  55. /**
  56. * 获取延迟执行的操作。
  57. */
  58. const getLazyActions = function()
  59. {
  60. const host = unsafeWindow.location.host;
  61. const actions = [];
  62.  
  63. // 巴哈姆特。
  64. if (host === "forum.gamer.com.tw")
  65. {
  66. // 自动开启图片。
  67. let action = function()
  68. {
  69. if (unsafeWindow.forumShowAllMedia)
  70. {
  71. unsafeWindow.forumShowAllMedia();
  72. }
  73. };
  74. actions.push(action);
  75. }
  76.  
  77. return actions;
  78. };
  79.  
  80. /**
  81. * 执行指定的操作。
  82. */
  83. const exec = function(p_actions)
  84. {
  85. if (p_actions)
  86. {
  87. p_actions.forEach(function(p_action)
  88. {
  89. p_action();
  90. });
  91. }
  92. };
  93.  
  94. // 1. 立即执行。
  95. exec(getInstantActions());
  96.  
  97.  
  98. // 2. 延迟执行。
  99. unsafeWindow.addEventListener("load", function()
  100. {
  101. exec(getLazyActions());
  102. }, true);