Tiny Customize

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

Fra 09.02.2017. Se den seneste versjonen.

  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://passport.jd.com/*
  16. // @include https://www.chiphell.com/*
  17. // @version 1.2.1
  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 = function ()
  29. {
  30. const actions = [];
  31.  
  32. if (host === "forum.gamer.com.tw")
  33. {
  34. // 巴哈姆特。
  35.  
  36. // 反反广告检测。
  37. const action = function ()
  38. {
  39. if (window.AntiAd)
  40. {
  41. window.AntiAd.check = function () { };
  42. window.AntiAd.block = function () { };
  43. window.AntiAd.verifyLink = function () { return false; };
  44. }
  45. };
  46. actions.push(action);
  47. }
  48. else if (
  49. host === "bbs.kafan.cn" ||
  50. host === "bbs.3dmgame.com" ||
  51. host === "www.chiphell.com"
  52. )
  53. {
  54. // 卡饭、3DMGame、Chiphell 论坛(Discuz 驱动的论坛)。
  55.  
  56. // 屏蔽方向键翻页。
  57. const action = function ()
  58. {
  59. if (window.keyPageScroll)
  60. {
  61. window.keyPageScroll = function () { };
  62. }
  63. };
  64. actions.push(action);
  65. }
  66. else if (/^https?\:\/\/poedb\.tw(\/?.*)\/dps/.test(href))
  67. {
  68. // 流亡编年史。
  69.  
  70. // 屏蔽默认自动全选物品信息、自动查询物品信息。
  71. const action = function ()
  72. {
  73. const elem = document.querySelector(`#iteminfo`);
  74. elem.addEventListener("click", (e) =>
  75. {
  76. e.stopPropagation();
  77. }, true);
  78.  
  79. elem.addEventListener("keydown", (e) =>
  80. {
  81. if (e.key === "Enter")
  82. {
  83. document.querySelector(`form[action^="dps"]`).submit();
  84. e.preventDefault();
  85. }
  86. }, true);
  87.  
  88. elem.addEventListener("keyup", (e) =>
  89. {
  90. if (e.ctrlKey && (e.key === "v" || e.key === "V"))
  91. {
  92. document.querySelector(`form[action^="dps"]`).submit();
  93. }
  94. });
  95. };
  96. actions.push(action);
  97. }
  98. else if (host === "login.taobao.com")
  99. {
  100. // 淘宝。
  101.  
  102. // 默认显示密码登录(而非 QR 码登录)界面。
  103. let action = function ()
  104. {
  105. // 始终显示密码登录。
  106. let elems = document.querySelectorAll(`.static-form, .iconfont.static`);
  107. for (let elem of elems)
  108. {
  109. elem.setAttribute("style", "display: block !important");
  110. }
  111.  
  112. // 删除扫码登录。
  113. elems = document.querySelectorAll(`.login-switch, .login-tip, .iconfont.quick, .quick-form`);
  114. for (let elem of elems)
  115. {
  116. elem.remove();
  117. }
  118. };
  119. actions.push(action);
  120. }
  121. else if (host === "passport.jd.com")
  122. {
  123. // 京东。
  124.  
  125. // 默认显示密码登录(而非 QR 码登录)界面。
  126. let action = function ()
  127. {
  128. // 删除扫码登录。
  129. let elems = document.querySelectorAll(`.login-tab, .login-box > .mt.tab-h, .qrcode-login, #qrCoagent`);
  130. for (let elem of elems)
  131. {
  132. elem.remove();
  133. }
  134.  
  135. // 始终显示密码登录。
  136. elems = document.querySelectorAll(`.login-box, #entry`);
  137. for (let elem of elems)
  138. {
  139. elem.setAttribute("style", "display: block !important; visibility: visible !important;");
  140. }
  141. };
  142. actions.push(action);
  143. }
  144. else if (/^(.+\.)?github\./.test(host))
  145. {
  146. // GitHub。
  147.  
  148. // 禁用快捷键: "s","w"。
  149. _disableKeydown("s w");
  150. }
  151.  
  152. return actions;
  153. };
  154.  
  155. /**
  156. * 获取延迟执行的操作。
  157. */
  158. const getLazyActions = function ()
  159. {
  160. const actions = [];
  161.  
  162. if (host === "forum.gamer.com.tw")
  163. {
  164. // 巴哈姆特。
  165.  
  166. // 自动开启图片。
  167. let action = function ()
  168. {
  169. if (window.forumShowAllMedia)
  170. {
  171. window.forumShowAllMedia();
  172. }
  173. };
  174. actions.push(action);
  175. }
  176. else if (host === "tieba.baidu.com")
  177. {
  178. // 贴吧。
  179.  
  180. // 删除广告贴。
  181. action = function ()
  182. {
  183. let spans;
  184. const elems = document.querySelectorAll(`#j_p_postlist > div`);
  185. for (let elem of elems)
  186. {
  187. spans = elem.querySelectorAll(`.core_reply_tail span`);
  188. for (let s of spans)
  189. {
  190. if (s.innerText.trim() === "商业推广")
  191. {
  192. elem.remove();
  193. break;
  194. }
  195. }
  196. }
  197. };
  198. actions.push(action);
  199. }
  200.  
  201. return actions;
  202. };
  203.  
  204. /**
  205. * 立即执行指定的操作。
  206. */
  207. const exec = function (p_actions)
  208. {
  209. if (p_actions)
  210. {
  211. p_actions.forEach(function (p_action)
  212. {
  213. p_action();
  214. });
  215. }
  216. };
  217.  
  218. // 1. 立即执行。
  219. exec(getInstantActions());
  220.  
  221. // 2. 延迟执行。
  222. window.addEventListener("load", function ()
  223. {
  224. exec(getLazyActions());
  225. }, true);
  226.  
  227. /**
  228. * 禁止键盘快捷键(单键)。
  229. */
  230. function _disableKeydown(p_keys)
  231. {
  232. if (typeof p_keys === "string")
  233. {
  234. const keys = p_keys.split(/\W+/);
  235. document.addEventListener("keydown", (e) =>
  236. {
  237. if (keys.indexOf(e.key.toLowerCase()) !== -1)
  238. {
  239. e.stopPropagation();
  240. }
  241. }, true);
  242. }
  243. }
  244.  
  245. function _removeListeners(p_element, p_events)
  246. {
  247. if (p_element && typeof p_events === "string")
  248. {
  249. const events = p_events.split(/\W+/) || [];
  250. for (let event of events)
  251. {
  252. p_element.removeEventListener(event, _preventDefaultAction, true);
  253. p_element.addEventListener(event, _preventDefaultAction, true);
  254. }
  255. }
  256. }
  257.  
  258. function _preventDefaultAction(e)
  259. {
  260. e.stopPropagation();
  261. }