-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdu.html
197 lines (194 loc) · 8.68 KB
/
du.html
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
188
189
190
191
192
193
194
195
196
197
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Xav's Disk Usage Info</title>
<style>
* {
font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
box-sizing: border-box;
}
.loading {
cursor: progress !important;
}
.loading * {
cursor: progress !important;
}
.entry {
padding: 0em;
border-top: 0;
border-bottom: 0;
padding-top: 0em;
text-align: center;
border: 1px red solid;
overflow: hidden;
}
.entry.folder {
border-right: 3px blue solid;
}
.entry.folder.selected {
border-right: 3px #0F0 solid;
}
body {
overflow-x: scroll;
}
#loading-msg {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
flex-direction: column;
}
#top-bar {
background-color: #0F0;
height: 30px;
padding: 3px;
overflow: hidden;
position: fixed;
top: 0;
left: 0;
width: 100%;
vertical-align: middle;
display: table-cell;
line-height: 30px;
}
</style>
</head>
<body>
<div id="top-bar">
Scanning file system, please stand by...
</div>
<div id="loading-msg">
<div>
Scanning<span id="loading-dots"></span>
</div>
<div>
<span id="loading-status"></span>
</div>
</div>
<script type="text/javascript">
'use strict';
if(window.location.href.includes("du.html")) {
alert("Please run the python script and open the appropriate location, not just open the HTML...");
}
let API_URL = window.location.origin;
const BOX_WIDTH = 300;
const TOP_BAR_HEIGHT = 30;
let num_loading_dots = 0;
setInterval(() => {
num_loading_dots += 1;
num_loading_dots %= 4;
document.getElementById('loading-dots').innerText = '.'.repeat(num_loading_dots);
}, 500);
let main_scan_done = false;
function fetch_new_loading_status() {
fetch(API_URL + "/main_scan_status", {
method: 'POST'
}).then(
response => response.text()
).then(function(text_response) {
document.getElementById('loading-status').innerText = text_response;
if(!main_scan_done) {
setTimeout(fetch_new_loading_status, 1500);
}
}).catch(e => {
document.getElementById('loading-status').innerText = "Error loading status: " + e;
console.log(e);
});
}
fetch_new_loading_status();
function format_big_number(n) {
// 1234567 --> 1,234,567
return n.toLocaleString();
}
function make_listing(path, dom_node, x_offset, generation) {
document.body.classList.add("loading");
fetch(API_URL + "/query|" + encodeURI(path)).then(
response => response.json()
).then(function(json_response) {
document.body.classList.remove("loading");
document.getElementById('loading-msg').style.visibility = 'hidden';
main_scan_done = true;
let other_columns = document.getElementsByClassName("columns");
for (let i = other_columns.length - 1; i >= 0; --i) {
// faffing around to allow for removal of elements from list during iteration
let element = other_columns[i];
if(parseInt(element.dataset.generation) >= generation) {
element.parentNode.removeChild(element);
}
}
console.log(json_response);
document.getElementById("top-bar").innerText = json_response.header;
let colour_light = false;
let y_offset = TOP_BAR_HEIGHT;
let column_node = document.createElement("div");
column_node.classList.add("columns");
column_node.style.zIndex = generation;
column_node.dataset.generation = generation;
column_node.style.display = "position";
let box_nodes = [];
for(let child of json_response.entries) {
let percentage = child[0];
let filename = child[1];
let box_node = document.createElement("div");
let full_path = child[2];
let foldable = child[3];
let size_summary = child[4];
let num_files = child[5];
box_node.style.position = "absolute";
box_node.style.width = BOX_WIDTH;
box_node.style.left = x_offset;
box_node.style.top = y_offset;
let box_height = percentage * (document.documentElement.clientHeight - 2 - TOP_BAR_HEIGHT);
y_offset += box_height;
box_node.style.height = box_height;
box_node.style.backgroundColor = colour_light ?
(foldable ? "#CCF" : "#EEE") : (foldable ? "#AAE" : "#AAA");
colour_light = !colour_light;
box_node.innerText = filename;
box_node.innerHTML += "<br /> " + size_summary;
if(num_files != 1) {
box_node.innerHTML += "<br /> " + format_big_number(num_files) + " files";
}
box_node.title = box_node.innerText + " (" + Math.round(percentage * 100, 2) + "% of folder)";
box_node.classList.add("entry");
box_node.style.zIndex = 9999 - generation;
column_node.appendChild(box_node);
box_nodes.push(box_node);
box_node.addEventListener('click', function(e) {
if(e.altKey) {
fetch(API_URL + "/reveal|" + encodeURI(full_path), {
method: 'POST'
}).catch(function(e) {
alert("Error opening: " + e);
console.error(e);
})
} else if(foldable) {
for(let other_node of box_nodes) {
other_node.classList.remove("selected");
}
box_node.classList.add("selected");
make_listing(full_path, dom_node, x_offset + BOX_WIDTH, generation + 1);
}
});
if(foldable) {
box_node.classList.add("folder");
box_node.style.cursor = "pointer";
}
}
dom_node.appendChild(column_node);
}).catch(function(e) {
console.error(e);
document.body.classList.remove("loading");
alert("Error report to Xavier (also check console): " + e)
});
}
let FS_ROOT = "__FS_ROOT__"; // replaced by python script
if(FS_ROOT == "__FS" + "_ROOT__") {
alert("Error code 7998");
} else {
make_listing(FS_ROOT, document.body, 0, 0);
}
</script>
</body>
</html>