Tiny Customize

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

Pada tanggal 29 Desember 2016. Lihat %(latest_version_link).

  1. // ==UserScript==
  2. // @name Tiny Customize
  3. // @description 为常用网站添加功能定制。例如:3DMGame、贴吧、淘宝、GitHub...
  4. // @namespace https://greatest.deepsurf.us/zh-CN/scripts/19823-tiny-customize
  5. // @homepageURL 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://forum.gamer.com.tw/*
  11. // @include http://poedb.tw/dps*
  12. // @include http://tieba.baidu.com/*
  13. // @include https://forum.gamer.com.tw/*
  14. // @include https://login.taobao.com/*
  15. // @include https://www.chiphell.com/*
  16. // @version 1.1.12
  17. // @grant none
  18. // ==/UserScript==
  19.  
  20. const host = window.location.host;
  21. const href = window.location.href;
  22. const pathname = window.location.pathname;
  23.  
  24. /**
  25. * 获取立即执行的操作。
  26. */
  27. const getInstantActions = function ()
  28. {
  29. const actions = [];
  30.  
  31. if (host === "forum.gamer.com.tw")
  32. {
  33. // 巴哈姆特。
  34.  
  35. // 反反广告检测。
  36. const action = function ()
  37. {
  38. if (window.AntiAd)
  39. {
  40. window.AntiAd.check = function () { };
  41. window.AntiAd.block = function () { };
  42. window.AntiAd.verifyLink = function () { return false; };
  43. }
  44. };
  45. actions.push(action);
  46. }
  47. else if (
  48. host === "bbs.kafan.cn" ||
  49. host === "bbs.3dmgame.com" ||
  50. host === "www.chiphell.com"
  51. )
  52. {
  53. // 卡饭、3DMGame、Chiphell 论坛(Discuz 驱动的论坛)。
  54.  
  55. // 屏蔽方向键翻页。
  56. const action = function ()
  57. {
  58. if (window.keyPageScroll)
  59. {
  60. window.keyPageScroll = function () { };
  61. }
  62. };
  63. actions.push(action);
  64. }
  65. else if (/^https?\:\/\/poedb\.tw(\/?.*)\/dps/.test(href))
  66. {
  67. // 流亡编年史。
  68.  
  69. // 屏蔽默认自动全选物品信息、自动查询物品信息。
  70. const action = function ()
  71. {
  72. const elem = document.querySelector(`#iteminfo`);
  73. elem.addEventListener("click", (e) =>
  74. {
  75. e.stopPropagation();
  76. }, true);
  77.  
  78. elem.addEventListener("keydown", (e) =>
  79. {
  80. if (e.key === "Enter")
  81. {
  82. document.querySelector(`form[action^="dps"]`).submit();
  83. e.preventDefault();
  84. }
  85. }, true);
  86.  
  87. elem.addEventListener("keyup", (e) =>
  88. {
  89. if (e.ctrlKey && (e.key === "v" || e.key === "V"))
  90. {
  91. document.querySelector(`form[action^="dps"]`).submit();
  92. }
  93. });
  94. };
  95. actions.push(action);
  96. }
  97. else if (host === "login.taobao.com")
  98. {
  99. // 淘宝。
  100.  
  101. // 默认显示密码登录(而非 QR 码登录)界面。
  102. let action = function ()
  103. {
  104. // 始终显示密码登录。
  105. let elems = document.querySelectorAll(`.static-form, .iconfont.static`);
  106. for (let elem of elems)
  107. {
  108. elem.setAttribute("style", "display: block !important");
  109. }
  110.  
  111. // 删除扫码登录。
  112. elems = document.querySelectorAll(`.login-switch, .login-tip, .iconfont.quick, .quick-form`);
  113. for (let elem of elems)
  114. {
  115. elem.remove();
  116. }
  117. };
  118. actions.push(action);
  119. }
  120. else if (/^(.+\.)?github\./.test(host))
  121. {
  122. // GitHub。
  123.  
  124. // 禁用快捷键: "s","w"。
  125. _disableKeydown("s w");
  126. }
  127.  
  128. return actions;
  129. };
  130.  
  131. /**
  132. * 获取延迟执行的操作。
  133. */
  134. const getLazyActions = function ()
  135. {
  136. const actions = [];
  137.  
  138. if (host === "forum.gamer.com.tw")
  139. {
  140. // 巴哈姆特。
  141.  
  142. // 自动开启图片。
  143. let action = function ()
  144. {
  145. if (window.forumShowAllMedia)
  146. {
  147. window.forumShowAllMedia();
  148. }
  149. };
  150. actions.push(action);
  151. }
  152. else if (host === "tieba.baidu.com")
  153. {
  154. // 贴吧。
  155.  
  156. // 删除广告贴。
  157. action = function ()
  158. {
  159. let spans;
  160. const elems = document.querySelectorAll(`#j_p_postlist > div`);
  161. for (let elem of elems)
  162. {
  163. spans = elem.querySelectorAll(`.core_reply_tail span`);
  164. for (let s of spans)
  165. {
  166. if (s.innerText.trim() === "商业推广")
  167. {
  168. elem.remove();
  169. break;
  170. }
  171. }
  172. }
  173. };
  174. actions.push(action);
  175. }
  176.  
  177. return actions;
  178. };
  179.  
  180. /**
  181. * 立即执行指定的操作。
  182. */
  183. const exec = function (p_actions)
  184. {
  185. if (p_actions)
  186. {
  187. p_actions.forEach(function (p_action)
  188. {
  189. p_action();
  190. });
  191. }
  192. };
  193.  
  194. // 1. 立即执行。
  195. exec(getInstantActions());
  196.  
  197. // 2. 延迟执行。
  198. window.addEventListener("load", function ()
  199. {
  200. exec(getLazyActions());
  201. }, true);
  202.  
  203. /**
  204. * 禁止键盘快捷键(单键)。
  205. */
  206. function _disableKeydown(p_keys)
  207. {
  208. if (typeof p_keys === "string")
  209. {
  210. const keys = p_keys.split(/\W+/);
  211. document.addEventListener("keydown", (e) =>
  212. {
  213. if (keys.indexOf(e.key.toLowerCase()) !== -1)
  214. {
  215. e.stopPropagation();
  216. }
  217. }, true);
  218. }
  219. }