Tiny Customize

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

当前为 2017-06-05 提交的版本,查看 最新版本

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