-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
187 lines (167 loc) · 4.67 KB
/
Copy pathindex.html
File metadata and controls
187 lines (167 loc) · 4.67 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Browser</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<link rel="stylesheet" href="https://rsms.me/inter/inter.css">
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap" rel="stylesheet">
<style>
body {
font-family: Inter, Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #111;
color: white;
}
#file-browser, #not-hidden {
margin: 20px auto;
max-width: 800px;
background: #222;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
padding: 20px;
}
.file-item {
display: flex;
align-items: center;
padding: 5px 10px;
background: #ff6666;
cursor: pointer;
border-bottom: 1px solid #ddd;
}
.file-item:last-child {
border-bottom: none;
}
.file-item i {
margin-right: 5px;
}
.file-item span {
flex-grow: 1;
}
.folder {
cursor: pointer;
background: #ff8888;
}
.children {
margin-left: 20px;
display: none;
}
#hidden {
display: none;
}
h2 {
margin: 1px 0;
margin-bottom: 8px;
}
textarea {
width: 100%;
height: 70vh;
font-family: "JetBrains Mono";
background: #333;
padding: 3px;
resize: none;
scrollbar-width: thin;
scrollbar-color: black #111;
border: 1px solid #ffffff2a;
border-radius: 8px;
color: white;
}
.abc {
background: #8888ff;
cursor: pointer;
}
</style>
</head>
<body>
<div id="file-browser">
<h2>1.21 SRC by gavin</h2>
<div id="file-structure">
<div class="file-item abc">
<i class="fas fa-arrow-left"></i>
<b>.. (back one)</b>
</div>
</div>
</div>
<div id="hidden">
<b>content</b> <br/>
<textarea id="ctc"></textarea>
</div>
<script>
const fileStructure = { data: [] }; // Placeholder for loaded JSON
const params = new URLSearchParams(window.location.search);
let PATH = params.get('path') || "NONE";
console.log(PATH);
document.querySelector(".abc").addEventListener('click',(e)=>{
window.location.href = window.location.href.replace(/\/[^/]*$/, "");
});
console.log(PATH.includes('.'));
if(PATH.includes('.')) {
console.log('p');
document.getElementById('hidden').id = "not-hidden";
fetch(PATH).then(x => x.text()).then(y => {
console.log(y);
document.querySelector('textarea').value = y;
});
}
// Create a file or folder item element
function createFileItem(item) {
const container = document.createElement('div');
container.classList.add('file-item');
const icon = document.createElement('i');
if (item.type === 'folder') {
icon.classList.add('fas', 'fa-folder', 'folder');
container.classList.add('folder');
} else {
icon.classList.add('fas', 'fa-file');
}
const name = document.createElement('span');
name.textContent = item.name;
container.appendChild(icon);
container.appendChild(name);
container.addEventListener('click', (e)=>{
window.location.href="?path="+(PATH!="NONE"?PATH+"/"+item.name:item.name);
});
return container;
}
function traverseAndAct(path, structure) {
if (path === "NONE" || !path) return structure;
const keys = path.split('/');
let currentLevel = structure;
for (const key of keys) {
if (!Array.isArray(currentLevel)) {
console.error(`Invalid path: "${key}" not found in current level`);
return [];
}
const next = currentLevel.find(child => child.name === key);
if (!next || !next.children) {
console.error(`Invalid path: "${key}" not found or has no children`);
return [];
}
currentLevel = next.children;
}
return currentLevel;
}
function renderFileStructure(structure) {
if(PATH.includes('.')) return;
const container = document.getElementById('file-structure');
const toRender =
PATH === "NONE" ? structure : traverseAndAct(PATH, structure);
toRender.forEach(item => {
container.appendChild(createFileItem(item));
});
}
// Fetch the structure from the JSON file
fetch('output.json')
.then(response => response.json())
.then(data => {
fileStructure.data = data;
renderFileStructure(data);
})
.catch(error => {
console.error("Error loading file structure:", error);
});
</script>
</body>
</html>