-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
29 lines (26 loc) · 1.39 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
document.addEventListener('DOMContentLoaded', function() {
const repoOwner = 'max9753'; // Replace with your GitHub username
const repoName = 'max9753.github.io'; // Replace with your repository name
const pathToFolder = 'downloadData'; // The folder in your repository
fetch(`https://api.github.com/repos/${repoOwner}/${repoName}/contents/${pathToFolder}`)
.then(response => response.json())
.then(data => {
const fileListContainer = document.getElementById('file-list');
fileListContainer.innerHTML = ''; // Clear the loading text
data.forEach(file => {
if (file.name.endsWith('.csv')) { // Check if it's a CSV file
const fileLink = document.createElement('a');
fileLink.href = file.download_url; // URL to download the file
fileLink.textContent = 'Download ' + file.name;
fileLink.download = file.name; // Suggest this filename when saving
const listItem = document.createElement('div');
listItem.appendChild(fileLink);
fileListContainer.appendChild(listItem);
}
});
})
.catch(error => {
console.error('Error fetching file list:', error);
document.getElementById('file-list').textContent = 'Error loading files.';
});
});