Tiny-Customize

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

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