GitHub 小助手

优化 GitHub 使用体验的小工具;仓库页显示 GitHub 计数统计(issues、watch、fork、star)为具体数值、放大查看 Markdown 中的图片

  1. // ==UserScript==
  2. // @name GitHub 小助手
  3. // @description 优化 GitHub 使用体验的小工具;仓库页显示 GitHub 计数统计(issues、watch、fork、star)为具体数值、放大查看 Markdown 中的图片
  4. // @namespace maomao1996.github-helper
  5. // @version 1.1.0
  6. // @icon https://github.githubassets.com/favicons/favicon.svg
  7. // @author maomao1996
  8. // @homepage https://github.com/maomao1996/tampermonkey-scripts
  9. // @supportURL https://github.com/maomao1996/tampermonkey-scripts/issues
  10. // @license MIT
  11. // @match *://github.com/*
  12. // @grant GM_addStyle
  13. // ==/UserScript==
  14. !function() {
  15. "use strict";
  16. var e = "femm-helper";
  17. function t(e, t) {
  18. (null == t || t > e.length) && (t = e.length);
  19. for (var o = 0, n = new Array(t); o < t; o++) n[o] = e[o];
  20. return n;
  21. }
  22. function o(e, o) {
  23. return function(e) {
  24. if (Array.isArray(e)) return e;
  25. }(e) || function(e, t) {
  26. var o = null == e ? null : "undefined" != typeof Symbol && e[Symbol.iterator] || e["@@iterator"];
  27. if (null != o) {
  28. var n, r, i = [], d = !0, a = !1;
  29. try {
  30. for (o = o.call(e); !(d = (n = o.next()).done) && (i.push(n.value), !t || i.length !== t); d = !0) ;
  31. } catch (e) {
  32. a = !0, r = e;
  33. } finally {
  34. try {
  35. d || null == o.return || o.return();
  36. } finally {
  37. if (a) throw r;
  38. }
  39. }
  40. return i;
  41. }
  42. }(e, o) || function(e, o) {
  43. if (!e) return;
  44. if ("string" == typeof e) return t(e, o);
  45. var n = Object.prototype.toString.call(e).slice(8, -1);
  46. "Object" === n && e.constructor && (n = e.constructor.name);
  47. if ("Map" === n || "Set" === n) return Array.from(n);
  48. if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return t(e, o);
  49. }(e, o) || function() {
  50. throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  51. }();
  52. }
  53. var n = /^(\d{1,3}(,\d{3})*|\d+|\d{1,3},\d{3}\+)$/, r = {
  54. COUNTER: 'span[class*="Counter"]:not(['.concat(e, "])"),
  55. REPO_SIDEBAR: "#repo-content-pjax-container .Layout-sidebar",
  56. WATCH: "#repo-notifications-counter",
  57. FORKS: "#repo-network-counter",
  58. STARS: '[id^="repo-stars-counter-"]'
  59. }, i = [ [ 'a[href$="/watchers"] strong', r.WATCH ], [ 'a[href$="/forks"] strong', r.FORKS ], [ 'a[href$="/stargazers"] strong', r.STARS ] ];
  60. function d(t, o) {
  61. (function(t, o) {
  62. return !t.getAttribute(e) && n.test(o) && t.innerText !== o;
  63. })(t, o) && (function(e, t) {
  64. e.innerText = t;
  65. }(t, o), function(e, t, o) {
  66. e.getAttribute(t) || e.setAttribute(t, o);
  67. }(t, e, "update-count"));
  68. }
  69. function a() {
  70. var e;
  71. document.querySelectorAll(r.COUNTER).forEach((function(e) {
  72. var t = e.getAttribute("title") || "";
  73. d(e, t);
  74. })), document.querySelector("#repository-container-header:not([hidden])") && ((e = document.querySelector(r.REPO_SIDEBAR)) && i.forEach((function(t) {
  75. var n, r = o(t, 2), i = r[0], a = r[1];
  76. d(e.querySelector(i), (null === (n = document.querySelector(a)) || void 0 === n ? void 0 : n.getAttribute("title")) || "");
  77. })));
  78. }
  79. /*! medium-zoom 1.1.0 | MIT License | https://github.com/francoischalifour/medium-zoom */ var m = Object.assign || function(e) {
  80. for (var t = 1; t < arguments.length; t++) {
  81. var o = arguments[t];
  82. for (var n in o) Object.prototype.hasOwnProperty.call(o, n) && (e[n] = o[n]);
  83. }
  84. return e;
  85. }, c = function(e) {
  86. return "IMG" === e.tagName;
  87. }, l = function(e) {
  88. return e && 1 === e.nodeType;
  89. }, u = function(e) {
  90. return ".svg" === (e.currentSrc || e.src).substr(-4).toLowerCase();
  91. }, s = function(e) {
  92. try {
  93. return Array.isArray(e) ? e.filter(c) : function(e) {
  94. return NodeList.prototype.isPrototypeOf(e);
  95. }(e) ? [].slice.call(e).filter(c) : l(e) ? [ e ].filter(c) : "string" == typeof e ? [].slice.call(document.querySelectorAll(e)).filter(c) : [];
  96. } catch (e) {
  97. throw new TypeError("The provided selector is invalid.\nExpects a CSS selector, a Node element, a NodeList or an array.\nSee: https://github.com/francoischalifour/medium-zoom");
  98. }
  99. }, f = function(e, t) {
  100. var o = m({
  101. bubbles: !1,
  102. cancelable: !1,
  103. detail: void 0
  104. }, t);
  105. if ("function" == typeof window.CustomEvent) return new CustomEvent(e, o);
  106. var n = document.createEvent("CustomEvent");
  107. return n.initCustomEvent(e, o.bubbles, o.cancelable, o.detail), n;
  108. };
  109. !function(e, t) {
  110. void 0 === t && (t = {});
  111. var o = t.insertAt;
  112. if (e && "undefined" != typeof document) {
  113. var n = document.head || document.getElementsByTagName("head")[0], r = document.createElement("style");
  114. r.type = "text/css", "top" === o && n.firstChild ? n.insertBefore(r, n.firstChild) : n.appendChild(r),
  115. r.styleSheet ? r.styleSheet.cssText = e : r.appendChild(document.createTextNode(e));
  116. }
  117. }(".medium-zoom-overlay{position:fixed;top:0;right:0;bottom:0;left:0;opacity:0;transition:opacity .3s;will-change:opacity}.medium-zoom--opened .medium-zoom-overlay{cursor:pointer;cursor:zoom-out;opacity:1}.medium-zoom-image{cursor:pointer;cursor:zoom-in;transition:transform .3s cubic-bezier(.2,0,.2,1)!important}.medium-zoom-image--hidden{visibility:hidden}.medium-zoom-image--opened{position:relative;cursor:pointer;cursor:zoom-out;will-change:transform}");
  118. var p = function e(t) {
  119. var o = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, n = window.Promise || function(e) {
  120. function t() {}
  121. e(t, t);
  122. }, r = function() {
  123. for (var e = arguments.length, t = Array(e), o = 0; o < e; o++) t[o] = arguments[o];
  124. var n = t.reduce((function(e, t) {
  125. return [].concat(e, s(t));
  126. }), []);
  127. return n.filter((function(e) {
  128. return -1 === c.indexOf(e);
  129. })).forEach((function(e) {
  130. c.push(e), e.classList.add("medium-zoom-image");
  131. })), p.forEach((function(e) {
  132. var t = e.type, o = e.listener, r = e.options;
  133. n.forEach((function(e) {
  134. e.addEventListener(t, o, r);
  135. }));
  136. })), b;
  137. }, i = function() {
  138. var e = (arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}).target, t = function() {
  139. var e = {
  140. width: document.documentElement.clientWidth,
  141. height: document.documentElement.clientHeight,
  142. left: 0,
  143. top: 0,
  144. right: 0,
  145. bottom: 0
  146. }, t = void 0, o = void 0;
  147. if (h.container) if (h.container instanceof Object) t = (e = m({}, e, h.container)).width - e.left - e.right - 2 * h.margin,
  148. o = e.height - e.top - e.bottom - 2 * h.margin; else {
  149. var n = (l(h.container) ? h.container : document.querySelector(h.container)).getBoundingClientRect(), r = n.width, i = n.height, d = n.left, a = n.top;
  150. e = m({}, e, {
  151. width: r,
  152. height: i,
  153. left: d,
  154. top: a
  155. });
  156. }
  157. t = t || e.width - 2 * h.margin, o = o || e.height - 2 * h.margin;
  158. var c = y.zoomedHd || y.original, s = u(c) ? t : c.naturalWidth || t, f = u(c) ? o : c.naturalHeight || o, p = c.getBoundingClientRect(), g = p.top, v = p.left, z = p.width, b = p.height, E = Math.min(Math.max(z, s), t) / z, w = Math.min(Math.max(b, f), o) / b, S = Math.min(E, w), A = "scale(" + S + ") translate3d(" + ((t - z) / 2 - v + h.margin + e.left) / S + "px, " + ((o - b) / 2 - g + h.margin + e.top) / S + "px, 0)";
  159. y.zoomed.style.transform = A, y.zoomedHd && (y.zoomedHd.style.transform = A);
  160. };
  161. return new n((function(o) {
  162. if (e && -1 === c.indexOf(e)) o(b); else {
  163. if (y.zoomed) o(b); else {
  164. if (e) y.original = e; else {
  165. if (!(c.length > 0)) return void o(b);
  166. var n = c;
  167. y.original = n[0];
  168. }
  169. if (y.original.dispatchEvent(f("medium-zoom:open", {
  170. detail: {
  171. zoom: b
  172. }
  173. })), v = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0,
  174. g = !0, y.zoomed = function(e) {
  175. var t = e.getBoundingClientRect(), o = t.top, n = t.left, r = t.width, i = t.height, d = e.cloneNode(), a = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0, m = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;
  176. return d.removeAttribute("id"), d.style.position = "absolute", d.style.top = o + a + "px",
  177. d.style.left = n + m + "px", d.style.width = r + "px", d.style.height = i + "px",
  178. d.style.transform = "", d;
  179. }(y.original), document.body.appendChild(z), h.template) {
  180. var r = l(h.template) ? h.template : document.querySelector(h.template);
  181. y.template = document.createElement("div"), y.template.appendChild(r.content.cloneNode(!0)),
  182. document.body.appendChild(y.template);
  183. }
  184. if (y.original.parentElement && "PICTURE" === y.original.parentElement.tagName && y.original.currentSrc && (y.zoomed.src = y.original.currentSrc),
  185. document.body.appendChild(y.zoomed), window.requestAnimationFrame((function() {
  186. document.body.classList.add("medium-zoom--opened");
  187. })), y.original.classList.add("medium-zoom-image--hidden"), y.zoomed.classList.add("medium-zoom-image--opened"),
  188. y.zoomed.addEventListener("click", d), y.zoomed.addEventListener("transitionend", (function e() {
  189. g = !1, y.zoomed.removeEventListener("transitionend", e), y.original.dispatchEvent(f("medium-zoom:opened", {
  190. detail: {
  191. zoom: b
  192. }
  193. })), o(b);
  194. })), y.original.getAttribute("data-zoom-src")) {
  195. y.zoomedHd = y.zoomed.cloneNode(), y.zoomedHd.removeAttribute("srcset"), y.zoomedHd.removeAttribute("sizes"),
  196. y.zoomedHd.removeAttribute("loading"), y.zoomedHd.src = y.zoomed.getAttribute("data-zoom-src"),
  197. y.zoomedHd.onerror = function() {
  198. clearInterval(i), console.warn("Unable to reach the zoom image target " + y.zoomedHd.src),
  199. y.zoomedHd = null, t();
  200. };
  201. var i = setInterval((function() {
  202. y.zoomedHd.complete && (clearInterval(i), y.zoomedHd.classList.add("medium-zoom-image--opened"),
  203. y.zoomedHd.addEventListener("click", d), document.body.appendChild(y.zoomedHd),
  204. t());
  205. }), 10);
  206. } else if (y.original.hasAttribute("srcset")) {
  207. y.zoomedHd = y.zoomed.cloneNode(), y.zoomedHd.removeAttribute("sizes"), y.zoomedHd.removeAttribute("loading");
  208. var a = y.zoomedHd.addEventListener("load", (function() {
  209. y.zoomedHd.removeEventListener("load", a), y.zoomedHd.classList.add("medium-zoom-image--opened"),
  210. y.zoomedHd.addEventListener("click", d), document.body.appendChild(y.zoomedHd),
  211. t();
  212. }));
  213. } else t();
  214. }
  215. }
  216. }));
  217. }, d = function() {
  218. return new n((function(e) {
  219. if (!g && y.original) {
  220. g = !0, document.body.classList.remove("medium-zoom--opened"), y.zoomed.style.transform = "",
  221. y.zoomedHd && (y.zoomedHd.style.transform = ""), y.template && (y.template.style.transition = "opacity 150ms",
  222. y.template.style.opacity = 0), y.original.dispatchEvent(f("medium-zoom:close", {
  223. detail: {
  224. zoom: b
  225. }
  226. })), y.zoomed.addEventListener("transitionend", (function t() {
  227. y.original.classList.remove("medium-zoom-image--hidden"), document.body.removeChild(y.zoomed),
  228. y.zoomedHd && document.body.removeChild(y.zoomedHd), document.body.removeChild(z),
  229. y.zoomed.classList.remove("medium-zoom-image--opened"), y.template && document.body.removeChild(y.template),
  230. g = !1, y.zoomed.removeEventListener("transitionend", t), y.original.dispatchEvent(f("medium-zoom:closed", {
  231. detail: {
  232. zoom: b
  233. }
  234. })), y.original = null, y.zoomed = null, y.zoomedHd = null, y.template = null, e(b);
  235. }));
  236. } else e(b);
  237. }));
  238. }, a = function() {
  239. var e = (arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}).target;
  240. return y.original ? d() : i({
  241. target: e
  242. });
  243. }, c = [], p = [], g = !1, v = 0, h = o, y = {
  244. original: null,
  245. zoomed: null,
  246. zoomedHd: null,
  247. template: null
  248. };
  249. "[object Object]" === Object.prototype.toString.call(t) ? h = t : (t || "string" == typeof t) && r(t);
  250. var z = function(e) {
  251. var t = document.createElement("div");
  252. return t.classList.add("medium-zoom-overlay"), t.style.background = e, t;
  253. }((h = m({
  254. margin: 0,
  255. background: "#fff",
  256. scrollOffset: 40,
  257. container: null,
  258. template: null
  259. }, h)).background);
  260. document.addEventListener("click", (function(e) {
  261. var t = e.target;
  262. t !== z ? -1 !== c.indexOf(t) && a({
  263. target: t
  264. }) : d();
  265. })), document.addEventListener("keyup", (function(e) {
  266. var t = e.key || e.keyCode;
  267. "Escape" !== t && "Esc" !== t && 27 !== t || d();
  268. })), document.addEventListener("scroll", (function() {
  269. if (!g && y.original) {
  270. var e = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
  271. Math.abs(v - e) > h.scrollOffset && setTimeout(d, 150);
  272. }
  273. })), window.addEventListener("resize", d);
  274. var b = {
  275. open: i,
  276. close: d,
  277. toggle: a,
  278. update: function() {
  279. var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, t = e;
  280. if (e.background && (z.style.background = e.background), e.container && e.container instanceof Object && (t.container = m({}, h.container, e.container)),
  281. e.template) {
  282. var o = l(e.template) ? e.template : document.querySelector(e.template);
  283. t.template = o;
  284. }
  285. return h = m({}, h, t), c.forEach((function(e) {
  286. e.dispatchEvent(f("medium-zoom:update", {
  287. detail: {
  288. zoom: b
  289. }
  290. }));
  291. })), b;
  292. },
  293. clone: function() {
  294. return e(m({}, h, arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}));
  295. },
  296. attach: r,
  297. detach: function() {
  298. for (var e = arguments.length, t = Array(e), o = 0; o < e; o++) t[o] = arguments[o];
  299. y.zoomed && d();
  300. var n = t.length > 0 ? t.reduce((function(e, t) {
  301. return [].concat(e, s(t));
  302. }), []) : c;
  303. return n.forEach((function(e) {
  304. e.classList.remove("medium-zoom-image"), e.dispatchEvent(f("medium-zoom:detach", {
  305. detail: {
  306. zoom: b
  307. }
  308. }));
  309. })), c = c.filter((function(e) {
  310. return -1 === n.indexOf(e);
  311. })), b;
  312. },
  313. on: function(e, t) {
  314. var o = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
  315. return c.forEach((function(n) {
  316. n.addEventListener("medium-zoom:" + e, t, o);
  317. })), p.push({
  318. type: "medium-zoom:" + e,
  319. listener: t,
  320. options: o
  321. }), b;
  322. },
  323. off: function(e, t) {
  324. var o = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
  325. return c.forEach((function(n) {
  326. n.removeEventListener("medium-zoom:" + e, t, o);
  327. })), p = p.filter((function(o) {
  328. return !(o.type === "medium-zoom:" + e && o.listener.toString() === t.toString());
  329. })), b;
  330. },
  331. getOptions: function() {
  332. return h;
  333. },
  334. getImages: function() {
  335. return c;
  336. },
  337. getZoomedImage: function() {
  338. return y.original;
  339. }
  340. };
  341. return b;
  342. }, g = ".markdown-body img:not(.medium-zoom-image)", v = p();
  343. function h() {
  344. !function() {
  345. var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : g;
  346. v.detach(), v.attach(e);
  347. }();
  348. }
  349. document.addEventListener("click", (function(e) {
  350. var t, o = e.target;
  351. "IMG" === (null == o ? void 0 : o.tagName) && (null === (t = document.querySelector(".markdown-body")) || void 0 === t ? void 0 : t.contains(o)) && (e.preventDefault(),
  352. e.stopPropagation());
  353. }));
  354. var y = ".medium-zoom-overlay{background-color:#fff!important;z-index:1996}.medium-zoom-image--opened{z-index:1997}@media (prefers-color-scheme:dark){.medium-zoom-overlay{background-color:#000!important}}";
  355. !function(e, t) {
  356. void 0 === t && (t = {});
  357. var o = t.insertAt;
  358. if (e && "undefined" != typeof document) {
  359. var n = document.head || document.getElementsByTagName("head")[0], r = document.createElement("style");
  360. r.type = "text/css", "top" === o && n.firstChild ? n.insertBefore(r, n.firstChild) : n.appendChild(r),
  361. r.styleSheet ? r.styleSheet.cssText = e : r.appendChild(document.createTextNode(e));
  362. }
  363. }(y), GM_addStyle(y);
  364. var z = function() {
  365. a(), h();
  366. }, b = document.querySelector("main");
  367. null != b && new MutationObserver((function() {
  368. return z();
  369. })).observe(b, {
  370. childList: !0,
  371. subtree: !0
  372. });
  373. z();
  374. }();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址