Greasy Fork 还支持 简体中文。

Tiny Customize

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

目前為 2016-12-04 提交的版本,檢視 最新版本

  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 http://www.poelab.com/*
  14. // @include https://forum.gamer.com.tw/*
  15. // @include https://login.taobao.com/*
  16. // @include https://www.chiphell.com/*
  17. // @version 1.1.9
  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 (/^(.+\.)?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 = function ()
  136. {
  137. const actions = [];
  138.  
  139. if (host === "forum.gamer.com.tw")
  140. {
  141. // 巴哈姆特。
  142.  
  143. // 自动开启图片。
  144. let action = function ()
  145. {
  146. if (window.forumShowAllMedia)
  147. {
  148. window.forumShowAllMedia();
  149. }
  150. };
  151. actions.push(action);
  152. }
  153. else if (host === "www.poelab.com")
  154. {
  155. // POE Lab
  156.  
  157. let action = function ()
  158. {
  159. const selectors = {
  160. "/": [
  161. "#comp-iqi4593u",
  162. "#comp-iqi4593h",
  163. "#comp-iqi45938",
  164. "#comp-iqi4593d"
  165. ],
  166. "/normal": ["#comp-inp50zrf"],
  167. "/cruel": ["#comp-inp5lj3v"],
  168. "/merciless": ["#comp-inpbrgjs"],
  169. "/uber": ["#comp-ip1tde81"],
  170. }[pathname];
  171.  
  172. if (selectors)
  173. {
  174. let elem;
  175. selectors.forEach(function (selector)
  176. {
  177. elem = document.querySelector(selector);
  178. if (elem)
  179. {
  180. document.body.appendChild(elem);
  181. elem.style.position = "unset";
  182. elem.style.margin = "10px auto";
  183. }
  184. });
  185. document.getElementById("SITE_CONTAINER").remove();
  186. document.body.style.backgroundColor = "#232323";
  187. }
  188. };
  189. actions.push(action);
  190. }
  191. else if (host === "tieba.baidu.com")
  192. {
  193. // 贴吧。
  194.  
  195. // 个人中心新标签打开。
  196. let action = function ()
  197. {
  198. const timer = window.setInterval(() =>
  199. {
  200. const elem = document.querySelector(`a.u_menu_wrap[title^="点击到个人中心"`);
  201. if (elem)
  202. {
  203. elem.target = "_blank";
  204. window.clearInterval(timer);
  205. }
  206. }, 100);
  207. };
  208. actions.push(action);
  209.  
  210. // 删除广告贴。
  211. action = function ()
  212. {
  213. let spans;
  214. const elems = document.querySelectorAll(`#j_p_postlist > div`);
  215. for (let elem of elems)
  216. {
  217. spans = elem.querySelectorAll(`.core_reply_tail span`);
  218. for (let s of spans)
  219. {
  220. if (s.innerText.trim() === "商业推广")
  221. {
  222. elem.remove();
  223. break;
  224. }
  225. }
  226. }
  227. };
  228. actions.push(action);
  229. }
  230.  
  231. return actions;
  232. };
  233.  
  234. /**
  235. * 立即执行指定的操作。
  236. */
  237. const exec = function (p_actions)
  238. {
  239. if (p_actions)
  240. {
  241. p_actions.forEach(function (p_action)
  242. {
  243. p_action();
  244. });
  245. }
  246. };
  247.  
  248. // 1. 立即执行。
  249. exec(getInstantActions());
  250.  
  251. // 2. 延迟执行。
  252. window.addEventListener("load", function ()
  253. {
  254. exec(getLazyActions());
  255. }, true);
  256.  
  257. /**
  258. * 禁止键盘快捷键(单键)。
  259. */
  260. function _disableKeydown(p_keys)
  261. {
  262. if (typeof p_keys === "string")
  263. {
  264. const keys = p_keys.split(/\W+/);
  265. document.addEventListener("keydown", (e) =>
  266. {
  267. if (keys.indexOf(e.key.toLowerCase()) !== -1)
  268. {
  269. e.stopPropagation();
  270. }
  271. }, true);
  272. }
  273. }