Files
plugins/GithubCard/js/widget.js
chorblack e75f275ef4
Some checks failed
定时更新GitHub源插件 / 自动更新GitHub插件 (push) Has been cancelled
Initial commit
2026-03-07 11:19:25 +08:00

2 lines
1.6 KiB
JavaScript

(function(t){var e,r=0;var i=t.getElementsByTagName("meta");var n="https://lab.lepture.com/github-cards/card.html";var a,c;for(e=0;e<i.length;e++){if(i[e].getAttribute("name")==="gc:url"){n=i[e].getAttribute("content")}else if(i[e].getAttribute("name")==="gc:client-id"){a=i[e].getAttribute("content")}else if(i[e].getAttribute("name")==="gc:client-secret"){c=i[e].getAttribute("content")}}function l(r){if(t.querySelectorAll){return t.querySelectorAll("."+r)}var i=t.getElementsByTagName("div");var n=[];for(e=0;e<i.length;e++){if(~i[e].className.split(" ").indexOf(r)){n.push(i[e])}}return n}function u(t,e){return t.getAttribute("data-"+e)}function d(t){if(window.addEventListener){window.addEventListener("message",function(e){if(t.id===e.data.sender){t.height=e.data.height}},false)}}function g(e,i){var n=u(e,"user");var l=u(e,"repo");var g=u(e,"github");if(g){g=g.split("/");if(g.length&&!n){n=g[0];l=l||g[1]}}if(!n){return}r+=1;var f=u(e,"width");var s=u(e,"height");var o=u(e,"target");var h=u(e,"client-id")||a;var v=u(e,"client-secret")||c;var b="ghcard-"+n+"-"+r;var m=t.createElement("iframe");m.setAttribute("id",b);m.setAttribute("frameborder",0);m.setAttribute("scrolling",0);m.setAttribute("allowtransparency",true);var A=i+"?user="+n+"&identity="+b;if(l){A+="&repo="+l}if(o){A+="&target="+o}if(h&&v){A+="&client_id="+h+"&client_secret="+v}m.src=A;m.width=f||Math.min(e.parentNode.clientWidth||400,400);if(s){m.height=s}d(m);e.parentNode.replaceChild(m,e);return m}var f=l("github-card");for(e=0;e<f.length;e++){g(f[e],n)}if(window.githubCard){window.githubCard.render=g}})(document);