github-button.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. function renderGithubButton() {
  2. "use strict";
  3. var e = window.document,
  4. t = e.location,
  5. o = window.Math,
  6. r = window.HTMLElement,
  7. n = window.XMLHttpRequest,
  8. a = "https://buttons.github.io/buttons.html",
  9. i = n && n.prototype && "withCredentials" in n.prototype,
  10. l = i && r && r.prototype.attachShadow && !r.prototype.attachShadow.prototype,
  11. c = function (e, t, o, r) {
  12. null == t && (t = "&"), null == o && (o = "="), null == r && (r = window.decodeURIComponent);
  13. for (var n = {}, a = e.split(t), i = 0, l = a.length; i < l; ++i) {
  14. var c = a[i];
  15. if ("" !== c) {
  16. var d = c.split(o);
  17. n[r(d[0])] = null != d[1] ? r(d.slice(1).join(o)) : void 0
  18. }
  19. }
  20. return n
  21. },
  22. d = function (e, t, o) {
  23. e.addEventListener ? e.addEventListener(t, o, !1) : e.attachEvent("on" + t, o)
  24. },
  25. s = function (e, t, o) {
  26. e.removeEventListener ? e.removeEventListener(t, o, !1) : e.detachEvent("on" + t, o)
  27. },
  28. f = function (e, t, o) {
  29. var r = function (n) {
  30. return s(e, t, r), o(n)
  31. };
  32. d(e, t, r)
  33. },
  34. u = function (e, t, o) {
  35. var r = function (n) {
  36. if (t.test(e.readyState)) return s(e, "readystatechange", r), o(n)
  37. };
  38. d(e, "readystatechange", r)
  39. },
  40. h = function (e) {
  41. return function (t, o, r) {
  42. var n = e.createElement(t);
  43. if (o)
  44. for (var a in o) {
  45. var i = o[a];
  46. null != i && (null != n[a] ? n[a] = i : n.setAttribute(a, i))
  47. }
  48. if (r)
  49. for (var l = 0, c = r.length; l < c; l++) {
  50. var d = r[l];
  51. n.appendChild("string" == typeof d ? e.createTextNode(d) : d)
  52. }
  53. return n
  54. }
  55. },
  56. g = h(e),
  57. p = function (e) {
  58. var t;
  59. return function () {
  60. t || (t = 1, e.apply(this, arguments))
  61. }
  62. },
  63. b = function (e, t) {
  64. return {}.hasOwnProperty.call(e, t)
  65. },
  66. m = {
  67. light: ".btn{color:#24292e;background-color:#eff3f6;background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg'%3e%3clinearGradient id='o' x2='0' y2='1'%3e%3cstop stop-color='%23fafbfc'/%3e%3cstop offset='90%25' stop-color='%23eff3f6'/%3e%3c/linearGradient%3e%3crect width='100%25' height='100%25' fill='url(%23o)'/%3e%3c/svg%3e\");background-image:-moz-linear-gradient(top, #fafbfc, #eff3f6 90%);background-image:linear-gradient(180deg, #fafbfc, #eff3f6 90%);filter:progid:DXImageTransform.Microsoft.Gradient(startColorstr='#FFFAFBFC', endColorstr='#FFEEF2F5');border-color:#cdcfd1;border-color:rgba(27,31,35,.2)}:root .btn{filter:none}.btn:focus,.btn:hover{background-color:#e6ebf1;background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg'%3e%3clinearGradient id='o' x2='0' y2='1'%3e%3cstop stop-color='%23f0f3f6'/%3e%3cstop offset='90%25' stop-color='%23e6ebf1'/%3e%3c/linearGradient%3e%3crect width='100%25' height='100%25' fill='url(%23o)'/%3e%3c/svg%3e\");background-image:-moz-linear-gradient(top, #f0f3f6, #e6ebf1 90%);background-image:linear-gradient(180deg, #f0f3f6, #e6ebf1 90%);filter:progid:DXImageTransform.Microsoft.Gradient(startColorstr='#FFF0F3F6', endColorstr='#FFE5EAF0');background-position:-0.5em;border-color:#acaeb0;border-color:rgba(27,31,35,.35)}:root .btn:focus,:root .btn:hover{filter:none}.btn:active{background-color:#e9ecef;background-image:none;border-color:#acaeb0;border-color:rgba(27,31,35,.35);box-shadow:inset 0 .15em .3em rgba(27,31,35,.15);filter:none}.social-count{color:#24292e;background-color:#fff;border-color:#d1d2d3;border-color:rgba(27,31,35,.2)}.social-count:focus,.social-count:hover{color:#0366d6}.octicon-heart{color:#ea4aaa}",
  68. dark: ".btn{color:#fafbfc;background-color:#202428;background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg'%3e%3clinearGradient id='o' x2='0' y2='1'%3e%3cstop stop-color='%232f363d'/%3e%3cstop offset='90%25' stop-color='%23202428'/%3e%3c/linearGradient%3e%3crect width='100%25' height='100%25' fill='url(%23o)'/%3e%3c/svg%3e\");background-image:-moz-linear-gradient(top, #2f363d, #202428 90%);background-image:linear-gradient(180deg, #2f363d, #202428 90%);filter:progid:DXImageTransform.Microsoft.Gradient(startColorstr='#FF2F363D', endColorstr='#FF1E2226');border-color:#2b3138;border-color:rgba(27,31,35,.2)}:root .btn{filter:none}.btn:focus,.btn:hover{background-color:#1b1f23;background-image:url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg'%3e%3clinearGradient id='o' x2='0' y2='1'%3e%3cstop stop-color='%232b3137'/%3e%3cstop offset='90%25' stop-color='%231b1f23'/%3e%3c/linearGradient%3e%3crect width='100%25' height='100%25' fill='url(%23o)'/%3e%3c/svg%3e\");background-image:-moz-linear-gradient(top, #2b3137, #1b1f23 90%);background-image:linear-gradient(180deg, #2b3137, #1b1f23 90%);filter:progid:DXImageTransform.Microsoft.Gradient(startColorstr='#FF2B3137', endColorstr='#FF191D21');background-position:-0.5em;border-color:#252b30;border-color:rgba(27,31,35,.5)}:root .btn:focus,:root .btn:hover{filter:none}.btn:active{background-color:#181b1f;background-image:none;border-color:#252b30;border-color:rgba(27,31,35,.5);box-shadow:inset 0 .15em .3em rgba(27,31,35,.15);filter:none}.social-count{color:#fafbfc;background-color:#1b1f23;border-color:#1b1f23;border-color:rgba(27,31,35,.2)}.social-count:focus,.social-count:hover{color:#2188ff}.octicon-heart{color:#ec6cb9}"
  69. },
  70. v = function (e, t) {
  71. return "@media(prefers-color-scheme:" + e + "){" + m[b(m, t) ? t : e] + "}"
  72. },
  73. w = {
  74. "mark-github": {
  75. width: 16,
  76. height: 16,
  77. path: '<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/>'
  78. },
  79. heart: {
  80. width: 12,
  81. height: 16,
  82. path: '<path fill-rule="evenodd" d="M9 2c-.97 0-1.69.42-2.2 1-.51.58-.78.92-.8 1-.02-.08-.28-.42-.8-1-.52-.58-1.17-1-2.2-1-1.632.086-2.954 1.333-3 3 0 .52.09 1.52.67 2.67C1.25 8.82 3.01 10.61 6 13c2.98-2.39 4.77-4.17 5.34-5.33C11.91 6.51 12 5.5 12 5c-.047-1.69-1.342-2.913-3-3z"/>'
  83. },
  84. eye: {
  85. width: 16,
  86. height: 16,
  87. path: '<path fill-rule="evenodd" d="M8.06 2C3 2 0 8 0 8s3 6 8.06 6C13 14 16 8 16 8s-3-6-7.94-6zM8 12c-2.2 0-4-1.78-4-4 0-2.2 1.8-4 4-4 2.22 0 4 1.8 4 4 0 2.22-1.78 4-4 4zm2-4c0 1.11-.89 2-2 2-1.11 0-2-.89-2-2 0-1.11.89-2 2-2 1.11 0 2 .89 2 2z"/>'
  88. },
  89. star: {
  90. width: 14,
  91. height: 16,
  92. path: '<path fill-rule="evenodd" d="M14 6l-4.9-.64L7 1 4.9 5.36 0 6l3.6 3.26L2.67 14 7 11.67 11.33 14l-.93-4.74L14 6z"/>'
  93. },
  94. "repo-forked": {
  95. width: 10,
  96. height: 16,
  97. path: '<path fill-rule="evenodd" d="M8 1a1.993 1.993 0 00-1 3.72V6L5 8 3 6V4.72A1.993 1.993 0 002 1a1.993 1.993 0 00-1 3.72V6.5l3 3v1.78A1.993 1.993 0 005 15a1.993 1.993 0 001-3.72V9.5l3-3V4.72A1.993 1.993 0 008 1zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3 10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3-10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"/>'
  98. },
  99. "issue-opened": {
  100. width: 14,
  101. height: 16,
  102. path: '<path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 011.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"/>'
  103. },
  104. "cloud-download": {
  105. width: 16,
  106. height: 16,
  107. path: '<path fill-rule="evenodd" d="M9 12h2l-3 3-3-3h2V7h2v5zm3-8c0-.44-.91-3-4.5-3C5.08 1 3 2.92 3 5 1.02 5 0 6.52 0 8c0 1.53 1 3 3 3h3V9.7H3C1.38 9.7 1.3 8.28 1.3 8c0-.17.05-1.7 1.7-1.7h1.3V5c0-1.39 1.56-2.7 3.2-2.7 2.55 0 3.13 1.55 3.2 1.8v1.2H12c.81 0 2.7.22 2.7 2.2 0 2.09-2.25 2.2-2.7 2.2h-2V11h2c2.08 0 4-1.16 4-3.5C16 5.06 14.08 4 12 4z"/>'
  108. }
  109. },
  110. x = {},
  111. y = function (e, t) {
  112. var o = x[e] || (x[e] = []);
  113. if (!(o.push(t) > 1)) {
  114. var r = p((function () {
  115. for (delete x[e]; t = o.shift();) t.apply(null, arguments)
  116. }));
  117. if (i) {
  118. var a = new n;
  119. d(a, "abort", r), d(a, "error", r), d(a, "load", (function () {
  120. var e;
  121. try {
  122. e = JSON.parse(a.responseText)
  123. } catch (e) {
  124. return void r(e)
  125. }
  126. r(200 !== a.status, e)
  127. })), a.open("GET", e), a.send()
  128. } else {
  129. var l = this || window;
  130. l._ = function (e) {
  131. l._ = null, r(200 !== e.meta.status, e.data)
  132. };
  133. var c = h(l.document)("script", {
  134. async: !0,
  135. src: e + (/\?/.test(e) ? "&" : "?") + "callback=_"
  136. }),
  137. s = function () {
  138. l._ && l._({
  139. meta: {}
  140. })
  141. };
  142. d(c, "load", s), d(c, "error", s), c.readyState && u(c, /de|m/, s), l.document.getElementsByTagName("head")[0].appendChild(c)
  143. }
  144. }
  145. },
  146. k = function (e, t, o) {
  147. var r = h(e.ownerDocument),
  148. n = e.appendChild(r("style", {
  149. type: "text/css"
  150. })),
  151. a = "body{margin:0}a{text-decoration:none;outline:0}.widget{display:inline-block;overflow:hidden;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif;font-size:0;white-space:nowrap}.btn,.social-count{position:relative;display:inline-block;height:14px;padding:2px 5px;font-size:11px;font-weight:600;line-height:14px;vertical-align:bottom;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-repeat:repeat-x;background-position:-1px -1px;background-size:110% 110%;border:1px solid}.btn{border-radius:.25em}.btn:not(:last-child){border-radius:.25em 0 0 .25em}.social-count{border-left:0;border-radius:0 .25em .25em 0}.widget-lg .btn,.widget-lg .social-count{height:20px;padding:3px 10px;font-size:12px;line-height:20px}.octicon{display:inline-block;vertical-align:text-top;fill:currentColor}" + function (e) {
  152. if (null == e) return m.light;
  153. var t = c(e, ";", ":", (function (e) {
  154. return e.replace(/^[ \t\n\f\r]+|[ \t\n\f\r]+$/g, "")
  155. }));
  156. return m[b(m, t["no-preference"]) ? t["no-preference"] : "light"] + v("light", t.light) + v("dark", t.dark)
  157. }(t["data-color-scheme"]);
  158. n.styleSheet ? n.styleSheet.cssText = a : n.appendChild(e.ownerDocument.createTextNode(a));
  159. var i, l, d = r("a", {
  160. className: "btn",
  161. href: t.href,
  162. target: "_blank",
  163. rel: "noopener",
  164. innerHTML: (i = t["data-icon"], l = /^large$/i.test(t["data-size"]) ? 16 : 14, i = ("" + i).toLowerCase().replace(/^octicon-/, ""), b(w, i) || (i = "mark-github"), '<svg viewBox="0 0 ' + w[i].width + " " + w[i].height + '" class="octicon octicon-' + i + '" style="width: ' + l * w[i].width / w[i].height + "px; height: " + l + 'px;" aria-hidden="true">' + w[i].path + "</svg>"),
  165. "aria-label": t["aria-label"] || void 0
  166. }, [" ", r("span", {}, [t["data-text"] || ""])]),
  167. s = e.appendChild(r("div", {
  168. className: "widget" + (/^large$/i.test(t["data-size"]) ? " widget-lg" : "")
  169. }, [d])),
  170. f = d.hostname.split(".").reverse();
  171. if ("" === f[0] && f.shift(), "com" !== f[0] || "github" !== f[1]) return d.href = "#", d.target = "_self", void o(s);
  172. var u = f.length,
  173. g = (" /" + d.pathname).split(/\/+/);
  174. if (((2 === u || 3 === u && "gist" === f[2]) && "archive" === g[3] || 2 === u && "releases" === g[3] && "download" === g[4] || 3 === u && "codeload" === f[2]) && (d.target = "_top"), /^true$/i.test(t["data-show-count"]) && 2 === u) {
  175. var p, x;
  176. if (!g[2] && g[1]) p = x = "followers";
  177. else if (!g[3] && g[2]) x = "stargazers_count", p = "stargazers";
  178. else if (g[4] || "subscription" !== g[3])
  179. if (g[4] || "fork" !== g[3]) {
  180. if ("issues" !== g[3]) return void o(s);
  181. x = "open_issues_count", p = "issues"
  182. } else x = "forks_count", p = "network/members";
  183. else x = "subscribers_count", p = "watchers";
  184. var k = g[2] ? "/repos/" + g[1] + "/" + g[2] : "/users/" + g[1];
  185. y.call(this, "https://api.github.com" + k, (function (e, t) {
  186. if (!e) {
  187. var n = t[x];
  188. s.appendChild(r("a", {
  189. className: "social-count",
  190. href: t.html_url + "/" + p,
  191. target: "_blank",
  192. rel: "noopener",
  193. "aria-label": n + " " + x.replace(/_count$/, "").replace("_", " ").slice(0, n < 2 ? -1 : void 0) + " on GitHub"
  194. }, [("" + n).replace(/\B(?=(\d{3})+(?!\d))/g, ",")]))
  195. }
  196. o(s)
  197. }))
  198. } else o(s)
  199. },
  200. C = window.devicePixelRatio || 1,
  201. z = function (e) {
  202. return (C > 1 ? o.ceil(o.round(e * C) / C * 2) / 2 : o.ceil(e)) || 0
  203. },
  204. F = function (e, t) {
  205. e.style.width = t[0] + "px", e.style.height = t[1] + "px"
  206. },
  207. M = function (t, r) {
  208. if (null != t && null != r)
  209. if (t.getAttribute && (t = function (e) {
  210. for (var t = {
  211. href: e.href,
  212. title: e.title,
  213. "aria-label": e.getAttribute("aria-label")
  214. }, o = ["icon", "color-scheme", "text", "size", "show-count"], r = 0, n = o.length; r < n; r++) {
  215. var a = "data-" + o[r];
  216. t[a] = e.getAttribute(a)
  217. }
  218. return null == t["data-text"] && (t["data-text"] = e.textContent || e.innerText), t
  219. }(t)), l) {
  220. var n = g("span", {
  221. title: t.title || void 0
  222. });
  223. k(n.attachShadow({
  224. mode: "closed"
  225. }), t, (function () {
  226. r(n)
  227. }))
  228. } else {
  229. var i = g("iframe", {
  230. src: "javascript:0",
  231. title: t.title || void 0,
  232. allowtransparency: !0,
  233. scrolling: "no",
  234. frameBorder: 0
  235. });
  236. F(i, [0, 0]), i.style.border = "none";
  237. var c = function () {
  238. var n, l = i.contentWindow;
  239. try {
  240. n = l.document.body
  241. } catch (t) {
  242. return void e.body.appendChild(i.parentNode.removeChild(i))
  243. }
  244. s(i, "load", c), k.call(l, n, t, (function (e) {
  245. var n = function (e) {
  246. var t = e.offsetWidth,
  247. r = e.offsetHeight;
  248. if (e.getBoundingClientRect) {
  249. var n = e.getBoundingClientRect();
  250. t = o.max(t, z(n.width)), r = o.max(r, z(n.height))
  251. }
  252. return [t, r]
  253. }(e);
  254. i.parentNode.removeChild(i), f(i, "load", (function () {
  255. F(i, n)
  256. })), i.src = a + "#" + (i.name = function (e, t, o, r) {
  257. null == t && (t = "&"), null == o && (o = "="), null == r && (r = window.encodeURIComponent);
  258. var n = [];
  259. for (var a in e) {
  260. var i = e[a];
  261. null != i && n.push(r(a) + o + r(i))
  262. }
  263. return n.join(t)
  264. }(t)), r(i)
  265. }))
  266. };
  267. d(i, "load", c), e.body.appendChild(i)
  268. }
  269. };
  270. t.protocol + "//" + t.host + t.pathname === a ? k(e.body, c(window.name || t.hash.replace(/^#/, "")), (function () { })) : function (t) {
  271. if (/m/.test(e.readyState) || !/g/.test(e.readyState) && !e.documentElement.doScroll) setTimeout(t);
  272. else if (e.addEventListener) {
  273. var o = p(t);
  274. f(e, "DOMContentLoaded", o), f(window, "load", o)
  275. } else u(e, /m/, t)
  276. }((function () {
  277. for (var t = e.querySelectorAll ? e.querySelectorAll("a.github-button") : function () {
  278. for (var t = [], o = e.getElementsByTagName("a"), r = 0, n = o.length; r < n; r++) ~(" " + o[r].className + " ").replace(/[ \t\n\f\r]+/g, " ").indexOf(" github-button ") && t.push(o[r]);
  279. return t
  280. }(), o = 0, r = t.length; o < r; o++) ! function (e) {
  281. M(e, (function (t) {
  282. e.parentNode.replaceChild(t, e)
  283. }))
  284. }(t[o])
  285. }))
  286. }