Tiny-Customize

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

目前為 2018-04-26 提交的版本,檢視 最新版本

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