diff --git a/assets/js/butter-dir-listing.js b/assets/js/butter-dir-listing.js
index 44f9b12..03daf11 100644
--- a/assets/js/butter-dir-listing.js
+++ b/assets/js/butter-dir-listing.js
@@ -6,12 +6,10 @@
* INJECTION ATTACKS***. We just pop filenames and the like right into innerHTML.
*/
-console.log("butter-dir-listing.js loaded!");
const supported_extensions = ["apk", "deb", "dmg", "pdf", "exe", "jpg", "png", "pptx", "ppt", "mp3"];
const usbRoot = "usb-butter/";
const inferredBaseURL = window.location.pathname.split("/" + usbRoot)[0] + "/";
-console.log("Inferred Base URL:", inferredBaseURL);
const getFolderDivHTML = (directory_name, number_of_items, href) => {
return `
@@ -21,7 +19,7 @@ const getFolderDivHTML = (directory_name, number_of_items, href) => {
${directory_name}
-
${number_of_items} items
+
${number_of_items} items
`;
@@ -30,7 +28,6 @@ const getFolderDivHTML = (directory_name, number_of_items, href) => {
const getFileDivHTML = (file_name, size, date, href) => {
icon = "ext-unknown.svg";
extension = file_name.split('.').pop();
- console.log("Extension:", extension);
if (supported_extensions.includes(extension)) {
icon = "ext-" + extension + ".svg";
}
@@ -49,11 +46,26 @@ const getFileDivHTML = (file_name, size, date, href) => {
`;
};
+const getFolderItemCount = async (folder_href) => {
+ async function populateSpan(response) {
+ if (!response.ok) {
+ console.error("Failed to fetch " + folder_href);
+ return;
+ }
+ const text = await response.text();
+ const doc = new DOMParser().parseFromString(text, 'text/html');
+ const { files, folders } = extractDirectoryListing(doc);
+ const items = files.length + folders.length;
+ const span = document.getElementById(folder_href);
+ span.textContent = items;
+ }
+ const response = fetch(folder_href).then(populateSpan);
+}
+
// Function to extract directory listing information
-function extractDirectoryListing() {
+function extractDirectoryListing(doc) {
// Get all rows in the table body
- const rows = document.querySelectorAll('tbody tr');
- console.log('Rows:', rows)
+ const rows = doc.querySelectorAll('tbody tr');
// Initialize arrays to hold file and folder information
const files = [];
@@ -99,16 +111,12 @@ function extractDirectoryListing() {
window.onload = function () {
// Example usage
- const { files, folders } = extractDirectoryListing();
- console.log('Files:', files);
- console.log('Folders:', folders);
+ const { files, folders } = extractDirectoryListing(window.document);
const listDiv = document.querySelector('div.list');
// Header with breadcrumbs
const h2Path = document.querySelector('h2').textContent;
- console.log("H2 Path:", h2Path);
const path = h2Path.replace('Index of ', '').replace(usbRoot, '');
- console.log("Path:", path);
const breadcrumbs = document.createElement("div");
breadcrumbs.classList.add('breadcrumbs');
@@ -153,8 +161,9 @@ window.onload = function () {
folders.forEach(folder => {
const folderDiv = document.createElement('div');
folderDiv.classList.add('folder-row');
- folderDiv.innerHTML = getFolderDivHTML(folder.name, 0, folder.href);
+ folderDiv.innerHTML = getFolderDivHTML(folder.name, "?", folder.href);
folderListing.appendChild(folderDiv);
+ getFolderItemCount(folder.href);
});
// do the insertion
diff --git a/simulated-usb-butter/Learn/index.html b/simulated-usb-butter/Learn/index.html
index 57ac702..b3927b9 100644
--- a/simulated-usb-butter/Learn/index.html
+++ b/simulated-usb-butter/Learn/index.html
@@ -10,14 +10,14 @@ layout: empty
- Index of /usb-butter/Download/Learn/
+ Index of /usb-butter/Learn/
- Index of /usb-butter/Download/Learn/
+ Index of /usb-butter/Learn/