forked from Bloggify/github-calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-calendar.min.js
7 lines (7 loc) · 8.96 KB
/
github-calendar.min.js
1
2
3
4
5
6
7
!function(t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).GitHubCalendar=t()}(function(){return function r(a,o,s){function u(e,t){if(!o[e]){if(!a[e]){var n="function"==typeof require&&require;if(!t&&n)return n(e,!0);if(i)return i(e,!0);throw(n=new Error("Cannot find module '"+e+"'")).code="MODULE_NOT_FOUND",n}n=o[e]={exports:{}},a[e][0].call(n.exports,function(t){return u(a[e][1][t]||t)},n,n.exports,r,a,o,s)}return o[e].exports}for(var i="function"==typeof require&&require,t=0;t<s.length;t++)u(s[t]);return u}({1:[function(t,e,n){"use strict";const c=t("formatoid"),r="MMM D, YYYY",l="MMMM D",d=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function p(t){return t+" "+(1===t?"day":"days")}const a=(new Date).getFullYear();function f(t){const e="string"==typeof t?new Date(t):t;t=e.getFullYear()==a?l:r;return c(e,t)}e.exports=function(o,s,u){o=document.querySelector(o),(u=u||{}).summary_text=u.summary_text||`Summary of pull requests, issues opened, and commits made by <a href="https://github.com/${s}" target="blank">@${s}</a>`,u.cache=1e3*(u.cache||86400),!1===u.global_stats&&(o.style.minHeight="175px");const n={content:"gh_calendar_content."+s,expire_at:"gh_calendar_expire."+s};u.proxy=t=>fetch("https://api.rigle.co/github-streak/graph/"+t).then(t=>t.text()),u.getCalendar=u.getCalendar||(t=>{if(u.cache&&Date.now()<+localStorage.getItem(n.expire_at)){var e=localStorage.getItem(n.content);if(e)return Promise.resolve(e)}return u.proxy(t).then(t=>(u.cache&&(localStorage.setItem(n.content,t),localStorage.setItem(n.expire_at,Date.now()+u.cache)),t))});let i=(t,e)=>{let n=document.createElement(t);for(const r of e.class?.split?.(" "))n.classList.add(r);return n.innerHTML=e.html,n};return u.getCalendar(s).then(async t=>{let e=document.createElement("div");var n,r,a;e.classList.add("calendar-graph"),e.innerHTML=t,o.innerHTML="",o.appendChild(e),!1!==u.global_stats&&(a=(n=await(async(t,e=null)=>{try{const r=await fetch("https://api.rigle.co/github-streak/stats/"+t);var n=r?await r.json():void 0;if(0<n.totalContributions)return n}catch(t){}return e?{totalContributions:e.last_year,firstContribution:null,longestStreak:{start:e.longest_streak?e.longest_streak_range[0]:null,end:e.longest_streak?e.longest_streak_range[1]:null,days:e.longest_streak},currentStreak:{start:e.current_streak?e.current_streak[0]:null,end:e.current_streak?e.current_streak[1]:null,days:e.current_streak}}:null})(s)).currentStreak.days?f(n.currentStreak.start)+" – "+f(n.currentStreak.end):parsed.last_contributed?`Last contributed on ${c(parsed.last_contributed,l)}.`:"Rock - Hard Place",r=n.longestStreak.days?f(n.longestStreak.start)+" – "+f(n.longestStreak.end):parsed.last_contributed?`Last contributed on ${c(parsed.last_contributed,l)}.`:"Rock - Hard Place",t=i("div",{class:"contrib-column contrib-column-first table-column",html:`<span class="text-muted">Total contributions</span>
<span class="contrib-number">${n.totalContributions} total</span>
<span class="text-muted">${f(n.firstContribution)} – Present</span>`}),r=i("div",{class:"contrib-column table-column",html:`<span class="text-muted">Longest streak</span>
<span class="contrib-number">${p(n.longestStreak.days)}</span>
<span class="text-muted">${r}</span>`}),a=i("div",{class:"contrib-column table-column",html:`<span class="text-muted">Current streak</span>
<span class="contrib-number">${p(n.currentStreak.days)}</span>
<span class="text-muted">${a}</span>`}),o.appendChild(t),o.appendChild(r),o.appendChild(a)),!0===u.tooltips&&function(t){const a=document.createElement("div");a.classList.add("day-tooltip"),t.appendChild(a);const e=t.querySelectorAll(".js-calendar-graph-svg rect.ContributionCalendar-day");e.forEach(t=>{t.addEventListener("mouseenter",t=>{let e=t.target.getAttribute("data-count");"0"===e?e="No contributions":"1"===e?e="1 contribution":e+=" contributions";const n=new Date(t.target.getAttribute("data-date"));var r=`${d[n.getUTCMonth()]} ${n.getUTCDate()}, `+n.getUTCFullYear();a.innerHTML=`<strong>${e}</strong> on `+r,a.classList.add("is-visible");r=t.target.getBoundingClientRect(),t=r.left+window.pageXOffset-a.offsetWidth/2+r.width/2,r=r.bottom+window.pageYOffset-a.offsetHeight-2*r.height;a.style.top=r+"px",a.style.left=t+"px"}),t.addEventListener("mouseleave",()=>{a.classList.remove("is-visible")})})}(o)}).catch(t=>console.error(t))}},{formatoid:4}],2:[function(t,e,n){e.exports.en=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],e.exports.en.abbr=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],e.exports.en.short=["Su","Mo","Tu","We","Th","Fr","Sa"],e.exports.fr=["dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi"],e.exports.fr.abbr=["dim","lun","mar","mer","jeu","ven","sam"],e.exports.fr.short=["di","lu","ma","me","je","ve","sa"],e.exports.es=["domingo","lunes","martes","miercoles","jueves","viernes","sabado"],e.exports.es.abbr=["dom","lun","mar","mir","jue","vie","sab"],e.exports.es.short=["do","lu","ma","mi","ju","vi","sa"],e.exports.it=["Domenica","Lunedi","Martedi","Mercoledi","Giovedi","Venerdi","Sabato"],e.exports.it.abbr=["Dom","Lun","Mar","Mer","Gio","Ven","Sab"],e.exports.it.short=["D","L","Ma","Me","G","V","S"],e.exports=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],e.exports.abbr=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],e.exports.short=["Su","Mo","Tu","We","Th","Fr","Sa"]},{}],3:[function(t,e,n){"use strict";e.exports=function(t,e,n){n=n||"0";e=(e=e||2)-(t=t.toString()).length;return(e<=0?"":n.repeat(e))+t}},{}],4:[function(t,e,n){"use strict";var r=t("months"),a=t("days"),o=t("fillo"),t=t("parse-it").Parser,s={YYYY:function(t,e){return e?t.getUTCFullYear():t.getFullYear()},YY:function(t,e){return s.YYYY(t,e)%100},MMMM:function(t,e){return e?r[t.getUTCMonth()]:r[t.getMonth()]},MMM:function(t,e){return e?r.abbr[t.getUTCMonth()]:r.abbr[t.getMonth()]},MM:function(t,e){return o(e?t.getUTCMonth()+1:t.getMonth()+1)},M:function(t,e){return e?t.getUTCMonth()+1:t.getMonth()+1},dddd:function(t,e){return a[s.d(t,e)]},ddd:function(t,e){return a.abbr[s.d(t,e)]},dd:function(t,e){return a.short[s.d(t,e)]},d:function(t,e){return e?t.getUTCDay():t.getDay()},DD:function(t,e){return o(s.D(t,e))},D:function(t,e){return e?t.getUTCDate():t.getDate()},A:function(t,e){return s.a(t,e).toUpperCase()},a:function(t,e){return 12<=s.H(t,e)?"pm":"am"},hh:function(t,e){return o(s.h(t,e))},h:function(t,e){return s.H(t,e)%12||12},HH:function(t,e){return o(s.H(t,e))},H:function(t,e){return e?t.getUTCHours():t.getHours()},mm:function(t,e){return o(s.m(t,e))},m:function(t,e){return e?t.getUTCMinutes():t.getMinutes()},ss:function(t,e){return o(s.s(t,e))},s:function(t,e){return e?t.getUTCSeconds():t.getSeconds()},S:function(t,e){return Math.round(s.s(t,e)/60*10)},SS:function(t,e){return o(s.s(t,e)/60*100)},SSS:function(t,e){return o(s.s(t,e)/60*1e3,3)},Z:function(t){t=-t.getTimezoneOffset();return(0<=t?"+":"-")+o(parseInt(t/60))+":"+o(t%60)},ZZ:function(t){t=-t.getTimezoneOffset();return(0<=t?"+":"-")+o(parseInt(t/60))+o(t%60)}},u=new t(s);e.exports=function(t,e){return u.run(e,[t,t._useUTC])}},{days:2,fillo:3,months:5,"parse-it":6}],5:[function(t,e,n){e.exports=["January","February","March","April","May","June","July","August","September","October","November","December"],e.exports.abbr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],e.exports.it=["Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre"],e.exports.abbr.it=["Gen","Feb","Mar","Apr","Mag","Giu","Lug","Ago","Set","Ott","Nov","Dic"],e.exports.de=["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],e.exports.abbr.de=["Jan","Feb","Mär","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"]},{}],6:[function(t,e,n){"use strict";var r=function(t,e,n){return e&&a(t.prototype,e),n&&a(t,n),t};function a(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}var o=t("regex-escape"),s=(r(u,[{key:"run",value:function(t,e){var n="";e=e||[];do{var r=t.match(this.re),a=r&&r[1],r=a||t.charAt(0)}while(n+=a?a="function"==typeof(a=this.obj[a])?a.apply(this,e):a:r,t=t.substring(r.length));return n}}]),u);function u(t){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,u),this.obj=t||{},this.re=new RegExp("^("+Object.keys(t).map(o).join("|")+")")}function i(t,e,n){return new s(e).run(t,n)}i.Parser=s,e.exports=i},{"regex-escape":7}],7:[function(t,e,n){"use strict";function r(t){return t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}r.proto=function(){return RegExp.escape=r},e.exports=r},{}]},{},[1])(1)});