Tiny-Customize

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

2021-09-03 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

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