Tiny-Customize

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

当前为 2024-04-19 提交的版本,查看 最新版本

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