Tiny-Customize

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

当前为 2018-03-07 提交的版本,查看 最新版本

  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://greasyfork.org/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://auth.alipay.com/*
  15. // @include https://login.taobao.com/*
  16. // @include https://login.xiami.com/*
  17. // @include https://passport.jd.com/*
  18. // @include https://www.chiphell.com/*
  19. // @version 1.2.9
  20. // @grant none
  21. // ==/UserScript==
  22.  
  23. const host = window.location.host;
  24. const href = window.location.href;
  25.  
  26. /**
  27. * 获取立即执行的操作。
  28. */
  29. const getInstantActions = () =>
  30. {
  31. const actions = [];
  32.  
  33. if (host === "forum.gamer.com.tw")
  34. {
  35. // 巴哈姆特。
  36.  
  37. // 反反广告检测。
  38. actions.push(() =>
  39. {
  40. if (window.AntiAd)
  41. {
  42. window.AntiAd.check = _noop;
  43. window.AntiAd.block = _noop;
  44. window.AntiAd.verifyLink = () => false;
  45. }
  46. });
  47. }
  48. else if (
  49. host === "bbs.kafan.cn" ||
  50. host === "bbs.3dmgame.com" ||
  51. host === "www.chiphell.com"
  52. )
  53. {
  54. // 卡饭、3DMGame、Chiphell 论坛(Discuz 驱动的论坛)。
  55.  
  56. // 屏蔽方向键翻页。
  57. actions.push(() =>
  58. {
  59. if (window.keyPageScroll)
  60. {
  61. window.keyPageScroll = _noop;
  62. }
  63. });
  64. }
  65. else if (/^https?:\/\/poedb\.tw(\/?.*)\/dps/.test(href))
  66. {
  67. // 流亡编年史。
  68.  
  69. // 屏蔽默认自动全选物品信息、自动查询物品信息。
  70. actions.push(() =>
  71. {
  72. const elem = document.querySelector(`#iteminfo`);
  73. const form = document.querySelector(`form[action^="dps"]`);
  74. elem.addEventListener("click", e => e.stopPropagation(), true);
  75. elem.addEventListener("keydown", (e) =>
  76. {
  77. if (e.key === "Enter")
  78. {
  79. form.submit();
  80. e.preventDefault();
  81. }
  82. });
  83.  
  84. elem.addEventListener("paste", (e) =>
  85. {
  86. setTimeout(() => form.submit(), 0);
  87. });
  88. });
  89. }
  90. else if (host === "login.taobao.com")
  91. {
  92. // 淘宝。
  93.  
  94. // 默认显示密码登录(而非 QR 码登录)界面。
  95. actions.push(() =>
  96. {
  97. _disableQRLogin(
  98. ".login-switch, .login-tip, .iconfont.quick, .quick-form",
  99. ".static-form, .iconfont.static",
  100. `input[name="TPL_username"]`
  101. );
  102. });
  103. }
  104. else if (host === "auth.alipay.com")
  105. {
  106. // 支付宝。
  107.  
  108. // 默认显示密码登录(而非 QR 码登录)界面。
  109. actions.push(() =>
  110. {
  111. _disableQRLogin(
  112. "#J-qrcode",
  113. "#J-login",
  114. "#J-input-user"
  115. );
  116. });
  117. }
  118. else if (host === "passport.jd.com")
  119. {
  120. // 京东。
  121.  
  122. // 默认显示密码登录(而非 QR 码登录)界面。
  123. actions.push(() =>
  124. {
  125. _disableQRLogin(
  126. ".login-tab, .login-box > .mt.tab-h, .qrcode-login, #qrCoagent",
  127. ".login-box, #entry",
  128. `input[name="loginname"]`
  129. );
  130. });
  131. }
  132. else if (host === "login.xiami.com")
  133. {
  134. // 虾米。
  135.  
  136. // 默认显示密码登录(而非 QR 码登录)界面。
  137. actions.push(() =>
  138. {
  139. _disableQRLogin(
  140. ".login-switch, .login-qrcode, .qrcode-tips",
  141. ".login-xm",
  142. `input[name="account"]`
  143. );
  144. });
  145. }
  146. else if (/^(.+\.)?github\./.test(host))
  147. {
  148. // GitHub。
  149.  
  150. // 禁用快捷键: "s","w"。
  151. _disableKeydown("s w");
  152. }
  153.  
  154. return actions;
  155. };
  156.  
  157. /**
  158. * 获取延迟执行的操作。
  159. */
  160. const getLazyActions = () =>
  161. {
  162. const actions = [];
  163.  
  164. if (host === "forum.gamer.com.tw")
  165. {
  166. // 巴哈姆特。
  167.  
  168. // 自动开启图片。
  169. actions.push(() =>
  170. {
  171. if (window.forumShowAllMedia)
  172. {
  173. window.forumShowAllMedia();
  174. }
  175. });
  176. }
  177. else if (host === "tieba.baidu.com")
  178. {
  179. // 贴吧。
  180.  
  181. // 删除广告贴。
  182. actions.push(() =>
  183. {
  184. let spans;
  185. const elems = document.querySelectorAll(`#j_p_postlist > div`);
  186. elems.forEach((e) =>
  187. {
  188. spans = e.querySelectorAll(`.core_reply_tail span`);
  189. for (const s of spans)
  190. {
  191. if (s.innerText.trim() === "商业推广")
  192. {
  193. e.remove();
  194. break;
  195. }
  196. }
  197. });
  198. });
  199. }
  200.  
  201. return actions;
  202. };
  203.  
  204. /**
  205. * 立即执行指定的操作。
  206. */
  207. const exec = (p_actions) =>
  208. {
  209. p_actions.forEach(p_action => p_action());
  210. };
  211.  
  212. // 1. 立即执行。
  213. exec(getInstantActions());
  214.  
  215. // 2. 延迟执行。
  216. window.addEventListener("load", () => exec(getLazyActions()), true);
  217.  
  218. function _noop() { }
  219.  
  220. /**
  221. * 禁止键盘快捷键(单键)。
  222. */
  223. function _disableKeydown(p_keys)
  224. {
  225. if (typeof p_keys === "string")
  226. {
  227. const keys = p_keys.split(/\W+/);
  228. document.addEventListener("keydown", (e) =>
  229. {
  230. if (keys.indexOf(e.key.toLowerCase()) !== -1)
  231. {
  232. e.stopPropagation();
  233. }
  234. }, true);
  235. }
  236. }
  237.  
  238. /**
  239. * 默认显示密码登录(而非 QR 码登录)界面
  240. */
  241. function _disableQRLogin(p_hide, p_show, p_focus)
  242. {
  243. // 删除扫码登录。
  244. let elems = document.querySelectorAll(p_hide);
  245. elems.forEach(e => e.remove());
  246.  
  247. // 始终显示密码登录。
  248. elems = document.querySelectorAll(p_show);
  249. elems.forEach(e => e.setAttribute("style", "display: block !important; visibility: visible !important;"));
  250.  
  251. // 自动聚焦用户名输入框。
  252. if (p_focus)
  253. {
  254. const elem = document.querySelector(p_focus);
  255. if (elem)
  256. {
  257. setTimeout(() => elem.select(), 300);
  258. }
  259. }
  260. }