diff --git a/resources/js/ajax.js b/resources/js/ajax.js index 80fb24b..9d024ef 100644 --- a/resources/js/ajax.js +++ b/resources/js/ajax.js @@ -4,7 +4,9 @@ function getDirSSE() { var path = ""; // Create path from array of items - for (pathNode of pathNodes) { path += pathNode; } + for (pathNode of pathNodes) { + path += pathNode; + } // For some reason, PHPSESSID= gets inserted when in sub dir. // temp work arround is to trim it. @@ -19,12 +21,13 @@ function getDirSSE() { function getDir(query) { var formULPTH = document.getElementById("DIRPATHUL"); var path = ""; + var temp = ""; // push or pop to path list if (query === "/") { // Process path from cookie and set to array/list if (document.cookie) { - var temp = document.cookie.replace("dirQuery=", ""); + temp = document.cookie.replace("dirQuery=", ""); temp = temp.split("/"); // Subtract one b/c paths end with / and create empty slot var size = temp.length - 1; @@ -32,19 +35,24 @@ function getDir(query) { for (var i = 0; i < size; i++) { pathNodes.push(temp[i] + "/"); } - // If no cookie, etup path from root + // If no cookie, setup path from root } else { - pathNodes.push("." + query); // If in root of server + pathNodes.push("." + query); } } else if (query === "../") { - if (pathNodes.length > 1) { pathNodes.pop(); } // Only remove while not in root - } else if (query === "./") { // Do nothing since re-scanning dir - } else { pathNodes.push(query); } // Add path + // Only remove while not in root + if (pathNodes.length > 1) { + pathNodes.pop(); + } + } else if (query === "./") { + // Do nothing since re-scanning dir + } else { + pathNodes.push(query); // Add path + } // Create path from array of items - // for (pathNode of pathNodes) { path += pathNode; console.log(pathNode); } - for (var i = 0; i < pathNodes.length; i++) { - path += pathNodes[i]; + for (pathNode of pathNodes) { + path += pathNode; console.log(pathNode); } // For some reason, PHPSESSID= gets inserted when in sub dir. @@ -53,7 +61,7 @@ function getDir(query) { path = path.split("; ").pop(); } - formULPTH.value = path; // Used when uploading a file + formULPTH.value = path; // Setup upload path for form path = "dirQuery=" + path; console.log("Path : " + path); process(path); diff --git a/resources/js/xmlParser.js b/resources/js/xmlParser.js index fe55229..c23ad29 100644 --- a/resources/js/xmlParser.js +++ b/resources/js/xmlParser.js @@ -8,14 +8,18 @@ function updateHTMLDirList(returnData) { var insertArea = document.getElementById('dynDiv'); var workingDir = dirPath.innerHTML; var i = 0; + var size = 0; // Insert dirs - document.getElementById("path").innerHTML = dirPath.innerHTML; + document.getElementById("path").innerHTML = workingDir; insertArea.innerHTML = ""; - if (workingDir === "./") { var i = 2 } // Remove ,. and ../ if in "root" + // Remove . and ../ if in "root" + if (workingDir === "./") { + var i = 2 + } - var size = dirs.length; + size = dirs.length; for (; i < size; i++) { var dir = dirs[i].innerHTML; @@ -30,10 +34,13 @@ function updateHTMLDirList(returnData) { } // Insert videos - size = videos .length; + var thumbnail = ""; + var vidNme = ""; + size = videos .length; + for (i = 0; i < size; i++) { - var thumbnail = videos[i].children[0].innerHTML; - var vidNme = videos[i].children[1].innerHTML; + thumbnail = videos[i].children[0].innerHTML; + vidNme = videos[i].children[1].innerHTML; insertArea.innerHTML += "" + "\"""; @@ -60,9 +68,9 @@ function updateHTMLDirList(returnData) { } if (images[0] != undefined) { - if (images[0].children[0].innerHTML.includes("000.jpg") || - images[0].children[0].innerHTML.includes("000.png") || - images[0].children[0].innerHTML.includes("000.gif")) { + var imgText = images[0].children[0].innerHTML; + + if (imgText.match(/000\.(jpg|png|gif)\b/) != null) { updateBG(path + images[0].children[0].innerHTML); } else { updateBG("resources/images/backgrounds/000.jpg"); @@ -75,40 +83,34 @@ function updateHTMLDirList(returnData) { size = files.length; for (i = 0; i < size; i++) { var fileName = files[i].children[0].innerHTML; - var iconImg = ""; - } else if (fileName.includes(".7z") || fileName.includes(".7zip") || - fileName.includes(".zip") || fileName.includes(".tar.gz") || - fileName.includes(".tar.xz") || fileName.includes(".gz") || - fileName.includes(".rar") || fileName.includes(".jar")) { - iconImg += " src=\"resources/images/icons/arc.png\" />"; - } else if (fileName.includes(".pdf")) { - iconImg += " src=\"resources/images/icons/pdf.png\" />"; - } else if (fileName.includes(".html")) { - iconImg += " src=\"resources/images/icons/html.png\" />"; - } else if (fileName.includes(".txt") || fileName.includes(".conf")) { - iconImg += " src=\"resources/images/icons/text.png\" />"; - } else if (fileName.includes(".iso") || fileName.includes(".img")) { - iconImg += " src=\"resources/images/icons/img.png\" />"; - } else if (fileName.includes(".sh") || fileName.includes(".batch") || - fileName.includes(".exe")) { - iconImg += " src=\"resources/images/icons/scrip.png\" />"; - } else { - iconImg += " src=\"resources/images/icons/bin.png\" />"; - } - - if (fileName != "sse.php" && fileName != "upload.php" && - fileName != "open.php" && fileName != "process.php") { - insertArea.innerHTML += "
" - + iconImg - + "" - + ""; - } + insertArea.innerHTML += "
" + + iconImg + + "" + + ""; + } +} + +function setFileIconType(fileName) { + if (fileName.match(/\.(doc|docx|xls|xlsx|rtf)\b/) != null) { + return " src=\"resources/images/icons/doc.png\" />"; + } else if (fileName.match(/\.(7z|7zip|zip|tar.gz|tar.xz|gz|rar|jar)\b/) != null) { + return " src=\"resources/images/icons/arc.png\" />"; + } else if (fileName.match(/\.(pdf)\b/) != null) { + return " src=\"resources/images/icons/pdf.png\" />"; + } else if (fileName.match(/\.(html)\b/) != null) { + return " src=\"resources/images/icons/html.png\" />"; + } else if (fileName.match(/\.(txt|conf)\b/) != null) { + return " src=\"resources/images/icons/text.png\" />"; + } else if (fileName.match(/\.(iso|img)\b/) != null) { + return " src=\"resources/images/icons/img.png\" />"; + } else if (fileName.match(/\.(sh|batch|exe)\b/) != null) { + return " src=\"resources/images/icons/scrip.png\" />"; + } else { + return " src=\"resources/images/icons/bin.png\" />"; } }