Tiny Customize

为常用网站添加功能定制。例如:3DMGame、贴吧、淘宝、GitHub...

As of 2016-12-10. See the latest version.

  1. // ==UserScript==
  2. // @name Tiny Customize
  3. // @description 为常用网站添加功能定制。例如:3DMGame、贴吧、淘宝、GitHub...
  4. // @namespace https://greatest.deepsurf.us/zh-CN/scripts/19823-tiny-customize
  5. // @homepageURL https://greatest.deepsurf.us/zh-CN/scripts/19823-tiny-customize
  6. // @author nonoroazoro
  7. // @include /^https?:\/\/(.+\.)?github\./
  8. // @include http://bbs.3dmgame.com/*
  9. // @include http://bbs.kafan.cn/*
  10. // @include http://forum.gamer.com.tw/*
  11. // @include http://poedb.tw/dps*
  12. // @include http://tieba.baidu.com/*
  13. // @include https://forum.gamer.com.tw/*
  14. // @include https://login.taobao.com/*
  15. // @include https://www.chiphell.com/*
  16. // @version 1.1.10
  17. // @grant none
  18. // ==/UserScript==
  19.  
  20. const host = window.location.host;
  21. const href = window.location.href;
  22. const pathname = window.location.pathname;
  23.  
  24. /**
  25. * 获取立即执行的操作。
  26. */
  27. const getInstantActions = function ()
  28. {
  29. const actions = [];
  30.  
  31. if (host === "forum.gamer.com.tw")
  32. {
  33. // 巴哈姆特。
  34.  
  35. // 反反广告检测。
  36. const action = function ()
  37. {
  38. if (window.AntiAd)
  39. {
  40. window.AntiAd.check = function () { };
  41. window.AntiAd.block = function () { };
  42. window.AntiAd.verifyLink = function () { return false; };
  43. }
  44. };
  45. actions.push(action);
  46. }
  47. else if (
  48. host === "bbs.kafan.cn" ||
  49. host === "bbs.3dmgame.com" ||
  50. host === "www.chiphell.com"
  51. )
  52. {
  53. // 卡饭、3DMGame、Chiphell 论坛(Discuz 驱动的论坛)。
  54.  
  55. // 屏蔽方向键翻页。
  56. const action = function ()
  57. {
  58. if (window.keyPageScroll)
  59. {
  60. window.keyPageScroll = function () { };
  61. }
  62. };
  63. actions.push(action);
  64. }
  65. else if (/^https?\:\/\/poedb\.tw(\/?.*)\/dps/.test(href))
  66. {
  67. // 流亡编年史。
  68.  
  69. // 屏蔽默认自动全选物品信息、自动查询物品信息。
  70. const action = function ()
  71. {
  72. const elem = document.querySelector(`#iteminfo`);
  73. elem.addEventListener("click", (e) =>
  74. {
  75. e.stopPropagation();
  76. }, true);
  77.  
  78. elem.addEventListener("keydown", (e) =>
  79. {
  80. if (e.key === "Enter")
  81. {
  82. document.querySelector(`form[action^="dps"]`).submit();
  83. e.preventDefault();
  84. }
  85. }, true);
  86.  
  87. elem.addEventListener("keyup", (e) =>
  88. {
  89. if (e.ctrlKey && (e.key === "v" || e.key === "V"))
  90. {
  91. document.querySelector(`form[action^="dps"]`).submit();
  92. }
  93. });
  94. };
  95. actions.push(action);
  96. }
  97. else if (host === "login.taobao.com")
  98. {
  99. // 淘宝。
  100.  
  101. // 默认显示密码登录(而非 QR 码登录)界面。
  102. let action = function ()
  103. {
  104. // 始终显示密码登录。
  105. let elems = document.querySelectorAll(`.static-form, .iconfont.static`);
  106. for (let elem of elems)
  107. {
  108. elem.setAttribute("style", "display: block !important");
  109. }
  110.  
  111. // 删除扫码登录。
  112. elems = document.querySelectorAll(`.login-switch, .login-tip, .iconfont.quick, .quick-form`);
  113. for (let elem of elems)
  114. {
  115. elem.remove();
  116. }
  117. };
  118. actions.push(action);
  119. }
  120. else if (/^(.+\.)?github\./.test(host))
  121. {
  122. // GitHub。
  123.  
  124. // 禁用快捷键: "s","w"。
  125. _disableKeydown("s w");
  126. }
  127.  
  128. return actions;
  129. };
  130.  
  131. /**
  132. * 获取延迟执行的操作。
  133. */
  134. const getLazyActions = function ()
  135. {
  136. const actions = [];
  137.  
  138. if (host === "forum.gamer.com.tw")
  139. {
  140. // 巴哈姆特。
  141.  
  142. // 自动开启图片。
  143. let action = function ()
  144. {
  145. if (window.forumShowAllMedia)
  146. {
  147. window.forumShowAllMedia();
  148. }
  149. };
  150. actions.push(action);
  151. }
  152. else if (host === "tieba.baidu.com")
  153. {
  154. // 贴吧。
  155.  
  156. // 个人中心新标签打开。
  157. let action = function ()
  158. {
  159. const timer = window.setInterval(() =>
  160. {
  161. const elem = document.querySelector(`a.u_menu_wrap[title^="点击到个人中心"`);
  162. if (elem)
  163. {
  164. elem.target = "_blank";
  165. window.clearInterval(timer);
  166. }
  167. }, 100);
  168. };
  169. actions.push(action);
  170.  
  171. // 删除广告贴。
  172. action = function ()
  173. {
  174. let spans;
  175. const elems = document.querySelectorAll(`#j_p_postlist > div`);
  176. for (let elem of elems)
  177. {
  178. spans = elem.querySelectorAll(`.core_reply_tail span`);
  179. for (let s of spans)
  180. {
  181. if (s.innerText.trim() === "商业推广")
  182. {
  183. elem.remove();
  184. break;
  185. }
  186. }
  187. }
  188. };
  189. actions.push(action);
  190. }
  191.  
  192. return actions;
  193. };
  194.  
  195. /**
  196. * 立即执行指定的操作。
  197. */
  198. const exec = function (p_actions)
  199. {
  200. if (p_actions)
  201. {
  202. p_actions.forEach(function (p_action)
  203. {
  204. p_action();
  205. });
  206. }
  207. };
  208.  
  209. // 1. 立即执行。
  210. exec(getInstantActions());
  211.  
  212. // 2. 延迟执行。
  213. window.addEventListener("load", function ()
  214. {
  215. exec(getLazyActions());
  216. }, true);
  217.  
  218. /**
  219. * 禁止键盘快捷键(单键)。
  220. */
  221. function _disableKeydown(p_keys)
  222. {
  223. if (typeof p_keys === "string")
  224. {
  225. const keys = p_keys.split(/\W+/);
  226. document.addEventListener("keydown", (e) =>
  227. {
  228. if (keys.indexOf(e.key.toLowerCase()) !== -1)
  229. {
  230. e.stopPropagation();
  231. }
  232. }, true);
  233. }
  234. }