Spaces:
Running
Running
Create script.js
Browse files
script.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Function to fetch and display the contents of a folder
|
| 2 |
+
function listFolderContents() {
|
| 3 |
+
const folderContents = document.getElementById('folder-contents');
|
| 4 |
+
|
| 5 |
+
// Replace 'your-folder-path/' with the path to your folder
|
| 6 |
+
const folderPath = './spidey/';
|
| 7 |
+
|
| 8 |
+
// Fetch a list of files and subfolders in the folder
|
| 9 |
+
fetch(folderPath)
|
| 10 |
+
.then(response => response.text())
|
| 11 |
+
.then(data => {
|
| 12 |
+
const items = data.split('\n').filter(item => item.trim() !== '');
|
| 13 |
+
|
| 14 |
+
// Create an unordered list to display the contents
|
| 15 |
+
const ul = document.createElement('ul');
|
| 16 |
+
|
| 17 |
+
items.forEach(item => {
|
| 18 |
+
const li = document.createElement('li');
|
| 19 |
+
li.textContent = item;
|
| 20 |
+
ul.appendChild(li);
|
| 21 |
+
});
|
| 22 |
+
|
| 23 |
+
folderContents.appendChild(ul);
|
| 24 |
+
})
|
| 25 |
+
.catch(error => console.error('Error loading folder contents:', error));
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
// Call the function to list folder contents when the page loads
|
| 29 |
+
window.onload = listFolderContents;
|