Tiny-Customize

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

当前为 2018-05-31 提交的版本,查看 最新版本

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