always updated plugin project list

This commit is contained in:
2022-03-06 16:06:23 +01:00
parent 5cb6d1330c
commit 134ff1d4a8
3 changed files with 72 additions and 37 deletions
+41
View File
@@ -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);
}