Tiny-Customize

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

Verze ze dne 06. 09. 2017. Zobrazit nejnovější verzi.

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