Tiny-Customize

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

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