Tiny-Customize

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

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