window.tarptaeya = {};
window.tarptaeya.reloadRepoCards = async function() {
const CACHE_TIMEOUT = 60000;
async function get(url) {
const now = new Date().getTime();
const prevResp = JSON.parse(localStorage.getItem(url));
if (prevResp && Math.abs(now - prevResp.time) < CACHE_TIMEOUT) {
return prevResp.data;
}
const resp = await fetch(url);
const json = await resp.json();
localStorage.setItem(url, JSON.stringify({time: now, data: json}));
return json;
}
const emojis = await get('https://api.github.com/emojis');
const colors = await get('https://raw.githubusercontent.com/ozh/github-colors/master/colors.json');
const themes = {
'light-default': {
background: 'white',
borderColor: '#e1e4e8',
color: '#586069',
linkColor: '#0366d6',
},
'dark-theme': {
background: 'rgb(13, 17, 23)',
borderColor: 'rgb(48, 54, 61)',
color: 'rgb(139, 148, 158)',
linkColor: 'rgb(88, 166, 255)',
}
};
for (const el of document.querySelectorAll('.repo-card')) {
const name = el.getAttribute('data-repo');
const theme = themes[el.getAttribute('data-theme') || 'light-default'];
const data = await get(`https://api.github.com/repos/${name}`);
data.description = (data.description || '').replace(/:\w+:/g, function(match) {
const name = match.substring(1, match.length - 1);
const emoji = emojis[name];
if (emoji) {
return ``;
}
return match;
});
el.innerHTML = `