Something went wrong. Try again.
Utensil's technical posts in Chinese (mostly 2005-2020) utensil.tngl.sh/tech
Something went wrong. Try again.
2.5 kB · 10 lines
JavaScript
at site
12345678910/*! * jQuery Github Widgets * * Copyright 2012, Utensil * https://github.com/utensil * * Released under the MIT licenses. * */!function(b){var p={createCaption:function(a){var t=a,e="https://www.github.com/"+t.login,p=e+"/repositories",s=e+"/followers",i=b("div.github-widget"),r=b('<div class="github-widget-caption"/>'),n=b('<div class="github-widget-stat"/>'),d=b('<span class="github-widget-avatar" />'),l=b("<a />").attr("href",e),o=b("<img />");o.attr("title",t.login),o.attr("alt",t.login),o.attr("src",t.avatar_url),l.append(o);var c=b('<span class="github-widget-repos-count" />'),u=b("<a />").attr("href",p),g=b("<strong />").text(t.public_repos),h=b("<span> public repos</span>"),w=b('<span class="github-widget-followers-count" />'),f=b("<a />").attr("href",s),v=b("<strong />").text(t.followers),x=b("<span> followers</span>");u.append(g).append(h),f.append(v).append(x),i.append(r.append(n.append(d.append(l)).append(c.append(u)).append(w.append(f))))},createReposList:function(a){var t=a;t=t.reverse();var e=b("div.github-widget"),p=b('<ul class="github-widget-repos-list"/>');for(var s in t){var i=t[s],r=b("<li />"),n=b("<a />").text(i.name).attr("href",i.html_url),d=b("<h3 />").append(n);i.fork&&d.addClass("fork-flag");var l=b('<ul class="repo-stats" />'),o=b('<li class="language"/>').text(i.language||""),c=b('<a class="watchers" />').text(i.watchers).attr("href",i.html_url+"/watchers"),u=b("<li />").append(c),g=b('<a class="forks" />').text(i.forks).attr("href",i.html_url+"/network"),h=b("<li />").append(g);l.append(o).append(u).append(h);var w=b('<div class="body" />'),f=b('<p class="description" />').text(i.description),v=b('<p class="updated-at" />').text("Last updated: "+i.updated_at.replace("T"," ").replace("Z"," "));w.append(f).append(v),r.append(l).append(d).append(w),p.append(r)}e.append(p)}};b.fn.github_widget=function(t){var a={width:"95%","max-width":"450px",align:"center"},e=(t=b.extend(a,t),b("<div></div>").addClass("github-widget"));return e.css({width:t.width,"max-width":t["max-width"],"margin-left":"left"==t.align?"5px":"auto","margin-right":"right"==t.align?"5px":"auto"}),this.append(e),b.ajax("https://api.github.com/users/"+t.user,{type:"get",dataType:"jsonp",crossDomain:!0,success:function(a){p.createCaption(a.data),b.ajax("https://api.github.com/users/"+t.user+"/repos",{type:"get",dataType:"jsonp",crossDomain:!0,success:function(a){p.createReposList(a.data)}})}}),this}}(jQuery);