mirror of
https://github.com/YouHaveTrouble/youhavetrouble.github.io.git
synced 2026-05-12 06:16:55 +00:00
always updated plugin project list
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
const projectEntry = document.getElementById('project-entry');
|
||||
const mcPluginsSection = document.getElementById('minecraft-plugins');
|
||||
mcPluginsSection.innerHTML = '<legend><h2>Minecraft plugins</h2></legend>'
|
||||
getRepos();
|
||||
|
||||
function getRepos() {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'https://api.github.com/users/youhavetrouble/repos?per_page=200');
|
||||
xhr.send();
|
||||
xhr.onload = function() {
|
||||
if (xhr.status !== 200) {
|
||||
mcPluginsSection.innerHTML = '<legend><h2>Minecraft plugins</h2></legend><p>An error occured while getting data from github. Please refresh the page.</p>'
|
||||
return;
|
||||
}
|
||||
let json = JSON.parse(xhr.response);
|
||||
|
||||
for (const repoId in json) {
|
||||
const repo = json[repoId];
|
||||
if (repo['topics'].includes('minecraft-plugin')) {
|
||||
addMinecraftPlugin(repo);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onprogress = function (event) {
|
||||
if (event.lengthComputable) {
|
||||
console.log(`Received ${event.loaded} of ${event.total} bytes`);
|
||||
} else {
|
||||
console.log(`Received ${event.loaded} bytes`); // no Content-Length
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMinecraftPlugin(pluginData) {
|
||||
let newEntry = projectEntry.content.querySelector('.project-entry').cloneNode(true);
|
||||
newEntry.querySelector('.project-title').innerText = pluginData['name'];
|
||||
newEntry.querySelector('.project-source').href = pluginData['html_url'];
|
||||
newEntry.querySelector('.project-description').innerText = pluginData['description']
|
||||
newEntry.querySelector('.project-downloads').href = `https://github.com/YouHaveTrouble/${pluginData['name']}/releases/latest`
|
||||
mcPluginsSection.append(newEntry);
|
||||
}
|
||||
Reference in New Issue
Block a user