Tiny Customize

针对一些常用网站,例如 3DMGame、贴吧、卡饭、巴哈姆特、流亡编年史、Chiphell、等的反反广告检测、自动化、屏蔽网站功能等。

目前为 2016-07-08 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Tiny Customize
  3. // @description 针对一些常用网站,例如 3DMGame、贴吧、卡饭、巴哈姆特、流亡编年史、Chiphell、等的反反广告检测、自动化、屏蔽网站功能等。
  4. // @namespace https://greasyfork.org/zh-CN/scripts/19823-tiny-customize
  5. // @homepageURL https://greasyfork.org/zh-CN/scripts/19823-tiny-customize
  6. // @author nonoroazoro
  7. // @include /^https?\:\/\/(bbs)\.3dmgame\.com/
  8. // @include /^https?\:\/\/(bbs)\.kafan\.cn/
  9. // @include /^https?\:\/\/(forum)\.gamer\.com\.tw/
  10. // @include /^https?\:\/\/(www)\.chiphell\.com/
  11. // @include /^https?\:\/\/poedb\.tw(\/?.*)\/dps/
  12. // @include /^https?\:\/\/tieba\.baidu\.com/
  13. // @version 1.0.9
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17. if (typeof unsafeWindow == "undefined")
  18. {
  19. unsafeWindow = window;
  20. }
  21.  
  22. /**
  23. * 获取立即执行的操作。
  24. */
  25. const getInstantActions = function()
  26. {
  27. const host = unsafeWindow.location.host;
  28. const href = unsafeWindow.location.href;
  29. const actions = [];
  30.  
  31. if (host === "forum.gamer.com.tw")
  32. {
  33. // 巴哈姆特。
  34.  
  35. // 反反广告检测。
  36. const action = function()
  37. {
  38. if (unsafeWindow.AntiAd)
  39. {
  40. unsafeWindow.AntiAd.check = function() {};
  41. }
  42. };
  43. actions.push(action);
  44. }
  45. else if (
  46. host === "bbs.kafan.cn" ||
  47. host === "bbs.3dmgame.com" ||
  48. host === "www.chiphell.com"
  49. )
  50. {
  51. // 卡饭、3DMGame、Chiphell 论坛(Discuz 驱动的论坛)。
  52.  
  53. // 屏蔽方向键翻页。
  54. const action = function()
  55. {
  56. if (unsafeWindow.keyPageScroll)
  57. {
  58. unsafeWindow.keyPageScroll = function() {};
  59. }
  60. };
  61. actions.push(action);
  62. }
  63. else if (/^https?\:\/\/poedb\.tw(\/?.*)\/dps/.test(href))
  64. {
  65. // 流亡编年史。
  66.  
  67. // 屏蔽默认自动全选物品信息、自动查询物品信息。
  68. const action = function()
  69. {
  70. const elem = document.querySelector(`#iteminfo`);
  71. elem.addEventListener("click", (e) =>
  72. {
  73. e.stopPropagation();
  74. }, true);
  75.  
  76. elem.addEventListener("keydown", (e) =>
  77. {
  78. if (e.key === "Enter")
  79. {
  80. document.querySelector(`form[action^="dps"]`).submit();
  81. e.preventDefault();
  82. }
  83. }, true);
  84.  
  85. elem.addEventListener("keyup", (e) =>
  86. {
  87. if (e.ctrlKey && (e.key === "v" || e.key === "V"))
  88. {
  89. document.querySelector(`form[action^="dps"]`).submit();
  90. }
  91. });
  92. };
  93. actions.push(action);
  94. }
  95.  
  96. return actions;
  97. };
  98.  
  99. /**
  100. * 获取延迟执行的操作。
  101. */
  102. const getLazyActions = function()
  103. {
  104. const host = unsafeWindow.location.host;
  105. const actions = [];
  106.  
  107. if (host === "forum.gamer.com.tw")
  108. {
  109. // 巴哈姆特。
  110.  
  111. // 自动开启图片。
  112. let action = function()
  113. {
  114. if (unsafeWindow.forumShowAllMedia)
  115. {
  116. unsafeWindow.forumShowAllMedia();
  117. }
  118. };
  119. actions.push(action);
  120. }
  121. else if (host === "tieba.baidu.com")
  122. {
  123. // 贴吧。
  124.  
  125. // 个人中心新标签打开。
  126. let action = function()
  127. {
  128. document.querySelector(`a.u_menu_wrap[title^="点击到个人中心"`).target = "_blank";
  129. };
  130. actions.push(action);
  131. }
  132.  
  133. return actions;
  134. };
  135.  
  136. /**
  137. * 立即执行指定的操作。
  138. */
  139. const exec = function(p_actions)
  140. {
  141. if (p_actions)
  142. {
  143. p_actions.forEach(function(p_action)
  144. {
  145. p_action();
  146. });
  147. }
  148. };
  149.  
  150. // 1. 立即执行。
  151. exec(getInstantActions());
  152.  
  153.  
  154. // 2. 延迟执行。
  155. unsafeWindow.addEventListener("load", function()
  156. {
  157. exec(getLazyActions());
  158. }, true);