Tiny-Customize

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

As of 2017-06-09. See the latest version.

  1. // ==UserScript==
  2. // @name Tiny-Customize
  3. // @description 为常用网站添加功能定制。例如:3DMGame、贴吧、淘宝、京东、GitHub...
  4. // @homepageURL https://github.com/nonoroazoro/firefox/tree/master/greasemonkey/tiny-customize
  5. // @namespace 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://passport.jd.com/*
  16. // @include https://www.chiphell.com/*
  17. // @version 1.2.5
  18. // @grant none
  19. // ==/UserScript==
  20.  
  21. const host = window.location.host;
  22. const href = window.location.href;
  23.  
  24. /**
  25. * 获取立即执行的操作。
  26. */
  27. const getInstantActions = () =>
  28. {
  29. const actions = [];
  30.  
  31. if (host === "forum.gamer.com.tw")
  32. {
  33. // 巴哈姆特。
  34.  
  35. // 反反广告检测。
  36. actions.push(() =>
  37. {
  38. if (window.AntiAd)
  39. {
  40. window.AntiAd.check = _noop;
  41. window.AntiAd.block = _noop;
  42. window.AntiAd.verifyLink = () => false;
  43. }
  44. });
  45. }
  46. else if (
  47. host === "bbs.kafan.cn" ||
  48. host === "bbs.3dmgame.com" ||
  49. host === "www.chiphell.com"
  50. )
  51. {
  52. // 卡饭、3DMGame、Chiphell 论坛(Discuz 驱动的论坛)。
  53.  
  54. // 屏蔽方向键翻页。
  55. actions.push(() =>
  56. {
  57. if (window.keyPageScroll)
  58. {
  59. window.keyPageScroll = _noop;
  60. }
  61. });
  62. }
  63. else if (/^https?:\/\/poedb\.tw(\/?.*)\/dps/.test(href))
  64. {
  65. // 流亡编年史。
  66.  
  67. // 屏蔽默认自动全选物品信息、自动查询物品信息。
  68. actions.push(() =>
  69. {
  70. const elem = document.querySelector(`#iteminfo`);
  71. const form = document.querySelector(`form[action^="dps"]`);
  72. elem.addEventListener("click", e => e.stopPropagation(), true);
  73. elem.addEventListener("keydown", (e) =>
  74. {
  75. if (e.key === "Enter")
  76. {
  77. form.submit();
  78. e.preventDefault();
  79. }
  80. });
  81.  
  82. elem.addEventListener("paste", (e) =>
  83. {
  84. setTimeout(() => form.submit(), 0);
  85. });
  86. });
  87. }
  88. else if (host === "login.taobao.com")
  89. {
  90. // 淘宝。
  91.  
  92. // 默认显示密码登录(而非 QR 码登录)界面。
  93. actions.push(() =>
  94. {
  95. // 始终显示密码登录。
  96. let elems = document.querySelectorAll(`.static-form, .iconfont.static`);
  97. elems.forEach(e => e.setAttribute("style", "display: block !important"));
  98.  
  99. // 删除扫码登录。
  100. elems = document.querySelectorAll(`.login-switch, .login-tip, .iconfont.quick, .quick-form`);
  101. elems.forEach(e => e.remove());
  102. });
  103. }
  104. else if (host === "passport.jd.com")
  105. {
  106. // 京东。
  107.  
  108. // 默认显示密码登录(而非 QR 码登录)界面。
  109. actions.push(() =>
  110. {
  111. // 删除扫码登录。
  112. let elems = document.querySelectorAll(`.login-tab, .login-box > .mt.tab-h, .qrcode-login, #qrCoagent`);
  113. elems.forEach(e => e.remove());
  114.  
  115. // 始终显示密码登录。
  116. elems = document.querySelectorAll(`.login-box, #entry`);
  117. elems.forEach(e => e.setAttribute("style", "display: block !important; visibility: visible !important;"));
  118. });
  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 = () =>
  135. {
  136. const actions = [];
  137.  
  138. if (host === "forum.gamer.com.tw")
  139. {
  140. // 巴哈姆特。
  141.  
  142. // 自动开启图片。
  143. actions.push(() =>
  144. {
  145. if (window.forumShowAllMedia)
  146. {
  147. window.forumShowAllMedia();
  148. }
  149. });
  150. }
  151. else if (host === "tieba.baidu.com")
  152. {
  153. // 贴吧。
  154.  
  155. // 删除广告贴。
  156. actions.push(() =>
  157. {
  158. let spans;
  159. const elems = document.querySelectorAll(`#j_p_postlist > div`);
  160. elems.forEach((e) =>
  161. {
  162. spans = e.querySelectorAll(`.core_reply_tail span`);
  163. for (const s of spans)
  164. {
  165. if (s.innerText.trim() === "商业推广")
  166. {
  167. e.remove();
  168. break;
  169. }
  170. }
  171. });
  172. });
  173. }
  174.  
  175. return actions;
  176. };
  177.  
  178. /**
  179. * 立即执行指定的操作。
  180. */
  181. const exec = (p_actions) =>
  182. {
  183. p_actions.forEach(p_action => p_action());
  184. };
  185.  
  186. // 1. 立即执行。
  187. exec(getInstantActions());
  188.  
  189. // 2. 延迟执行。
  190. window.addEventListener("load", () => exec(getLazyActions()), true);
  191.  
  192. function _noop() { }
  193.  
  194. /**
  195. * 禁止键盘快捷键(单键)。
  196. */
  197. function _disableKeydown(p_keys)
  198. {
  199. if (typeof p_keys === "string")
  200. {
  201. const keys = p_keys.split(/\W+/);
  202. document.addEventListener("keydown", (e) =>
  203. {
  204. if (keys.indexOf(e.key.toLowerCase()) !== -1)
  205. {
  206. e.stopPropagation();
  207. }
  208. }, true);
  209. }
  210. }