This commit is contained in:
xaoxuu 2022-10-05 17:34:16 +08:00
parent dc30d90fb5
commit 4239b3fe0e
8 changed files with 112 additions and 12 deletions

View File

@ -272,6 +272,7 @@ plugins:
# issues api # issues api
sitesjs: /js/plugins/sites.js sitesjs: /js/plugins/sites.js
friendsjs: /js/plugins/friends.js friendsjs: /js/plugins/friends.js
ghinfo: /js/plugins/ghinfo.js
## optional plugins ## ## optional plugins ##
# preload # preload

View File

@ -106,6 +106,7 @@
jQuery: '<%- url_for(theme.plugins.jquery || "https://fastly.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js") %>', jQuery: '<%- url_for(theme.plugins.jquery || "https://fastly.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js") %>',
sitesjs: '<%- url_for(theme.plugins.sitesjs) %>', sitesjs: '<%- url_for(theme.plugins.sitesjs) %>',
friendsjs: '<%- url_for(theme.plugins.friendsjs) %>', friendsjs: '<%- url_for(theme.plugins.friendsjs) %>',
ghinfo: '<%- url_for(theme.plugins.ghinfo) %>',
}; };
// optional plugins // optional plugins

View File

@ -26,7 +26,7 @@ function layoutDiv() {
el += '</div>'; el += '</div>';
// body // body
el += '<div class="widget-body fs14">'; el += '<div class="widget-body fs14">';
el += '<div class="items">'; el += '<div class="items github-info-wrap" id="ghinfo-api" api="https://api.github.xaoxuu.com/repos/' + repo + '">';
var items = []; var items = [];
// GitHub // GitHub
items.push({ items.push({
@ -34,6 +34,20 @@ function layoutDiv() {
text: 'GitHub', text: 'GitHub',
href: 'https://github.com/' + repo href: 'https://github.com/' + repo
}); });
// Stars
items.push({
icon: '<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor" style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible"><path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"></path></svg>',
text: 'Stars',
apiKey: 'stargazers_count',
href: 'https://github.com/' + repo + '/stargazers'
});
// Forks
items.push({
icon: '<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor" style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible"><path fill-rule="evenodd" d="M5 3.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm0 2.122a2.25 2.25 0 10-1.5 0v.878A2.25 2.25 0 005.75 8.5h1.5v2.128a2.251 2.251 0 101.5 0V8.5h1.5a2.25 2.25 0 002.25-2.25v-.878a2.25 2.25 0 10-1.5 0v.878a.75.75 0 01-.75.75h-4.5A.75.75 0 015 6.25v-.878zm3.75 7.378a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm3-8.75a.75.75 0 100-1.5.75.75 0 000 1.5z"></path></svg>',
text: 'Forks',
apiKey: 'forks_count',
href: 'https://github.com/' + repo + '/network/members'
});
// Releases // Releases
items.push({ items.push({
icon: '<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor" style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible"><path fill-rule="evenodd" d="M2.5 7.775V2.75a.25.25 0 01.25-.25h5.025a.25.25 0 01.177.073l6.25 6.25a.25.25 0 010 .354l-5.025 5.025a.25.25 0 01-.354 0l-6.25-6.25a.25.25 0 01-.073-.177zm-1.5 0V2.75C1 1.784 1.784 1 2.75 1h5.025c.464 0 .91.184 1.238.513l6.25 6.25a1.75 1.75 0 010 2.474l-5.026 5.026a1.75 1.75 0 01-2.474 0l-6.25-6.25A1.75 1.75 0 011 7.775zM6 5a1 1 0 100 2 1 1 0 000-2z"></path></svg>', icon: '<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor" style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible"><path fill-rule="evenodd" d="M2.5 7.775V2.75a.25.25 0 01.25-.25h5.025a.25.25 0 01.177.073l6.25 6.25a.25.25 0 010 .354l-5.025 5.025a.25.25 0 01-.354 0l-6.25-6.25a.25.25 0 01-.073-.177zm-1.5 0V2.75C1 1.784 1.784 1 2.75 1h5.025c.464 0 .91.184 1.238.513l6.25 6.25a1.75 1.75 0 010 2.474l-5.026 5.026a1.75 1.75 0 01-2.474 0l-6.25-6.25A1.75 1.75 0 011 7.775zM6 5a1 1 0 100 2 1 1 0 000-2z"></path></svg>',
@ -43,15 +57,9 @@ function layoutDiv() {
// Download // Download
items.push({ items.push({
icon: '<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor" style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible"><path fill-rule="evenodd" d="M7.47 10.78a.75.75 0 001.06 0l3.75-3.75a.75.75 0 00-1.06-1.06L8.75 8.44V1.75a.75.75 0 00-1.5 0v6.69L4.78 5.97a.75.75 0 00-1.06 1.06l3.75 3.75zM3.75 13a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5z"></path></svg>', icon: '<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor" style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible"><path fill-rule="evenodd" d="M7.47 10.78a.75.75 0 001.06 0l3.75-3.75a.75.75 0 00-1.06-1.06L8.75 8.44V1.75a.75.75 0 00-1.5 0v6.69L4.78 5.97a.75.75 0 00-1.06 1.06l3.75 3.75zM3.75 13a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5z"></path></svg>',
text: 'Download', text: 'Download Zip',
href: 'https://github.com/' + repo + '/archive/refs/heads/' + branch + '.zip' href: 'https://github.com/' + repo + '/archive/refs/heads/' + branch + '.zip'
}); });
// Issues
items.push({
icon: '<svg aria-hidden="true" role="img" class="color-icon-primary" viewBox="0 0 16 16" width="1rem" height="1rem" fill="currentColor" style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible"><path d="M8 9.5a1.5 1.5 0 100-3 1.5 1.5 0 000 3z"></path><path fill-rule="evenodd" d="M8 0a8 8 0 100 16A8 8 0 008 0zM1.5 8a6.5 6.5 0 1113 0 6.5 6.5 0 01-13 0z"></path></svg>',
text: 'Issues',
href: 'https://github.com/' + repo + '/issues'
});
items.forEach((item, i) => { items.forEach((item, i) => {
el += '<div class="line"></div>'; el += '<div class="line"></div>';
el += '<a class="item-link"'; el += '<a class="item-link"';
@ -59,8 +67,19 @@ function layoutDiv() {
el += ' href="' + url_for(item.href) + '"'; el += ' href="' + url_for(item.href) + '"';
el += ' target="_blank" rel="external nofollow noopener noreferrer"'; el += ' target="_blank" rel="external nofollow noopener noreferrer"';
el += '>'; el += '>';
el += item.icon; // left
el += '<div class="left">';
el += '<span>' + item.text + '</span>'; el += '<span>' + item.text + '</span>';
el += '</div>';
// right
el += '<div class="right">';
if (item.apiKey) {
el += '<span type="text" id="' + item.apiKey + '"></span>';
}
if (item.icon) {
el += item.icon;
}
el += '</div>';
el += '</a>'; el += '</a>';
}); });
el += '</div>'; el += '</div>';

View File

@ -14,7 +14,7 @@ a
// md > a // md > a
p:not([class]), li:not([class]) p:not([class]), li:not([class])
>a:not([class]) a:not([class])
position: relative position: relative
margin: 0 1px margin: 0 1px
padding: 2px padding: 2px

View File

@ -20,9 +20,9 @@
padding: 0.5rem .5rem padding: 0.5rem .5rem
font-size: $fs-13 font-size: $fs-13
justify-content: space-between justify-content: space-between
flex-direction: row-reverse
svg svg
width: 1em width: 1em
height: 1em height: 1em
margin-left: 4px
a:hover a:hover
background: var(--block-hover) background: var(--block-hover)

View File

@ -230,6 +230,14 @@ if (stellar.plugins.friendsjs) {
}) })
} }
} }
if (stellar.plugins.ghinfo) {
const issues_api = document.getElementById('ghinfo-api');
if (issues_api != undefined) {
stellar.jQuery(() => {
stellar.loadScript(stellar.plugins.ghinfo, { defer: true })
})
}
}
// swiper // swiper
if (stellar.plugins.swiper) { if (stellar.plugins.swiper) {

View File

@ -48,7 +48,6 @@ const friendsjs = {
friendsjs.requestAPI(cfg.api, function(data) { friendsjs.requestAPI(cfg.api, function(data) {
$(el).find('.loading-wrap').remove(); $(el).find('.loading-wrap').remove();
const arr = data.content || data; const arr = data.content || data;
console.log(data);
arr.forEach((item, i) => { arr.forEach((item, i) => {
var user = '<div class="user-card">'; var user = '<div class="user-card">';
user += '<a class="card-link" target="_blank" rel="external nofollow noopener noreferrer"'; user += '<a class="card-link" target="_blank" rel="external nofollow noopener noreferrer"';

View File

@ -0,0 +1,72 @@
const GitHubInfo = {
requestAPI: (url, callback, timeout) => {
let retryTimes = 5;
function request() {
return new Promise((resolve, reject) => {
let status = 0; // 0 等待 1 完成 2 超时
let timer = setTimeout(() => {
if (status === 0) {
status = 2;
timer = null;
reject('请求超时');
if (retryTimes == 0) {
timeout();
}
}
}, 5000);
fetch(url).then(function(response) {
if (status !== 2) {
clearTimeout(timer);
resolve(response);
timer = null;
status = 1;
}
if (response.ok) {
return response.json();
}
throw new Error('Network response was not ok.');
}).then(function(data) {
retryTimes = 0;
callback(data);
}).catch(function(error) {
if (retryTimes > 0) {
retryTimes -= 1;
setTimeout(() => {
request();
}, 5000);
} else {
timeout();
}
});
});
}
request();
},
layout: (cfg) => {
const el = $(cfg.el)[0];
GitHubInfo.requestAPI(cfg.api, function(data) {
const arr = data.content || data;
for (let key of Object.keys(data)) {
$(el).find("[type=text]#" + key).text(data[key]);
$(el).find("[type=link]#" + key).attr("href", data[key]);
}
}, function() {
});
},
}
$(function () {
const els = document.getElementsByClassName('github-info-wrap');
for (var i = 0; i < els.length; i++) {
const el = els[i];
const api = el.getAttribute('api');
if (api == null) {
continue;
}
var cfg = new Object();
cfg.el = el;
cfg.api = api;
cfg.class = el.getAttribute('class');
GitHubInfo.layout(cfg);
}
});