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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<style>
::-webkit-scrollbar {
width: 0px; /* Remove scrollbar space */
background: transparent; /* Optional: just make scrollbar invisible */
}
html{
background-color: rgba(30,30,30,0.3);
color: white;
height: 100vh;
width: 100vw;
}
.main-wrap{
user-select: none;
position: absolute;
top: 5%;
right: 10px;
width: 90%;
min-height: 20px;
max-height: 70%;
overflow-y: scroll;
}
#folder_box{
position: relative;
height: 100%;
}
#folder_box > div{
padding: 2px;
}
#folder_box > div:first-child{
height: 20px;
}
.sub-folder{
padding-left: 20px;
}
.center_text{
display: flex;
grid-template-columns: 1fr 1fr;
justify-content: left;
align-items: center;
}
.center_text > img{
padding-right: 5px;
width: 30px;
height: 30px;
}
.folder-item{
padding-top: 10px;
}
#context_menu{
display: none;
user-select: none;
position: absolute;
background-color: rgba(40,40,40,1);
padding: 4px;
left: 0px;
top: 0px;
}
#context_menu > div:hover{
background-color: rgba(80,80,80);
}
#nav_bar{
user-select: none;
position: absolute;
top: 3%;
left: 5%;
width: 91%;
display: flex;
direction: rtl;
grid-template-columns: 1fr 1fr;
background-color: rgba(30,30,30,1);
display: none;
}
#nav_bar > div{
padding: 4px;
height: 100%;
}
#nav_bar > div:hover{
background-color: rgba(80,80,80,1);
}
</style>
</head>
<body>
<div class="main-wrap"><div id="folder_box"></div></div>
<div id="context_menu">
<div onClick="reload()">reload everything</div>
<div onClick="add_to_list()">add folder to list</div>
</div>
<div id="nav_bar">
<div onclick="settings()">settings</div>
</div>
<script>
//lerd teh loobrewies
const fs=require('fs'),
os=require('os'),
path=require('path'),
electron=require('electron'),
{shell,ipcRenderer}=require('electron');
//create config if not exist
if(fs.existsSync(path.resolve(__dirname,"../config.json"))!=true){
let obj={
default_folders:[
"%Downloads%",
"%Pictures%",
"%Videos%",
"%Documents%",
"%Desktop%"
]
}
fs.writeFile(
path.resolve(__dirname,"../config.json"),
JSON.stringify(obj,null,4),
()=>{
let obj=null
}
)
}
//_*folder function related*_
//load folder config
function load_default_folders(){
fs.readFile(path.resolve(__dirname + '/../config.json'), function (err, data) {
data=JSON.parse(data)["default_folders"];
let text="<div></div>"
data.forEach((folder,i)=>{
name=folder.replace(/%/g,"");
folder=folder.replace(
/%Desktop%/g,path.resolve(os.userInfo().homedir,"Desktop")
).replace(
/%Pictures%/g,path.resolve(os.userInfo().homedir,"Pictures")
).replace(
/%Documents%/g,path.resolve(os.userInfo().homedir,"Documents")
).replace(
/%Videos%/g,path.resolve(os.userInfo().homedir,"Videos")
).replace(
/%Downloads%/g,path.resolve(os.userInfo().homedir,"Downloads")
);
name=folder.replace(
path.resolve(os.userInfo().homedir,"Desktop"),'Desktop'
).replace(
path.resolve(os.userInfo().homedir,"Pictures"),'Pictures'
).replace(
path.resolve(os.userInfo().homedir,"Documents"),'Documents'
).replace(
path.resolve(os.userInfo().homedir,"Videos"),'Videos'
).replace(
path.resolve(os.userInfo().homedir,"Downloads"),'Downloads'
);
let file_parsed=folder.replace(/\\/g,"\\\\");
if (fs.existsSync(folder)) {
text+=
'<div class="folder">'+
'<div class="center_text" onclick="open_folder(\''+file_parsed+'\')">'+
'<img src="imgassets/foldericon.ico" />'+name+
'</div>'+
'<div class="sub-folder" id="'+(folder)+'"></div></div>'
} else {
text+='<div style="background-color: rgb(180,0,0);" class="not-exist" id="'+folder
+'">'+folder+' does not exist</div>'
}
})
document.getElementById('folder_box').innerHTML=text
});
}
load_default_folders();
let folder_box=document.getElementById('folder_box')
function open_folder(id){
let div=document.getElementById(id)
if(div.innerHTML==""){
fs.readdir(id,(err, files) => {
files.sort((a,b)=>{
if(a.includes(".")){
return 0
} else {
return -1
}
})
for(file in files){
let file_parsed=(id+"\\"+files[file]).replace(/\\/g,"\\\\");
if(files[file].includes('.')){
div.innerHTML+=
'<div class="folder-item" onclick="shell.openPath(\''+(file_parsed)
+'\')">'+
files[file]+'</div>'
} else {
div.innerHTML+=
'<div class="folder">'+
'<div class="center_text" onclick="open_folder(\''+file_parsed+'\')">'+
'<img src="imgassets/foldericon.ico" />'+files[file]+
'</div>'+
'<div class="sub-folder" id="'+(id+"\\"+files[file])+'"></div></div>'
}
}
})
} else {
div.innerHTML=""
}
}
//_*context menu stuffs*_
let context_data=""
context_menu=document.getElementById('context_menu')
context_menu_default=context_menu.innerHTML
window.addEventListener("contextmenu", e=>{
if(e.target.onclick){
let str=e.target.onclick.toString().match(/\'.*\'/g)[0].replace(/\'/g,"")
if(str.includes(".")){
}
else if(str){
e.preventDefault();
context_menu.innerHTML=context_menu_default
context_data=str.replace(/\\\\/g,"\\")
if(e.srcElement.parentNode.parentNode.id=="folder_box"){
context_menu.innerHTML+='<div onclick="remove_from_list()">remove from list</div>'
}
context_menu.style.display="block";
context_menu.style.left=e.pageX+'px';
context_menu.style.top=e.pageY+'px';
}
}
else if(e.target.class="not-exist"){
console.log(e.target.id.toString());
str=e.target.id.toString()
e.preventDefault();
context_menu.innerHTML='<div onclick="remove_from_list()">remove from list</div>'
context_data=str.replace(/\\\\/g,"\\")
context_menu.style.display="block";
context_menu.style.left=e.pageX+'px';
context_menu.style.top=e.pageY+'px';
}
})
window.addEventListener('mousedown',e=>{
if(context_menu.style.display!="none"){
setTimeout(()=>{
context_menu.style.display="none"
},200)
}
})
function add_to_list(id){
if(id==null){
id=context_data
}
fs.readFile(path.resolve(__dirname + '/../config.json'), function (err, data) {
data=JSON.parse(data)
data["default_folders"].push(id)
fs.writeFile(
path.resolve(__dirname,"../config.json"),
JSON.stringify(data,null,4),
()=>{
load_default_folders();
}
)
});
}
function remove_from_list(){
fs.readFile(path.resolve(__dirname + '/../config.json'), function (err, data) {
data=JSON.parse(data)
data["default_folders"].forEach((folder,i)=>{
folder=folder.replace(
/%Desktop%/g,path.resolve(os.userInfo().homedir,"Desktop")
).replace(
/%Pictures%/g,path.resolve(os.userInfo().homedir,"Pictures")
).replace(
/%Documents%/g,path.resolve(os.userInfo().homedir,"Documents")
).replace(
/%Videos%/g,path.resolve(os.userInfo().homedir,"Videos")
).replace(
/%Downloads%/g,path.resolve(os.userInfo().homedir,"Downloads")
);
if(folder==context_data){
console.log("L + RATIO + REMOVED YOUR FILE "+context_data+" + COPE");
data["default_folders"].splice(i,1)
}
});
fs.writeFile(
path.resolve(__dirname,"../config.json"),
JSON.stringify(data,null,4),
()=>{
load_default_folders();
}
)
});
}
function reload(){
location.reload();
}
//_*allow click behind*_
folder_box.addEventListener('mouseenter',()=>{
ipcRenderer.send('set-click','false')
})
folder_box.addEventListener('mouseleave',()=>{
ipcRenderer.send('set-click','true')
});
context_menu.addEventListener('mouseenter',()=>{
ipcRenderer.send('set-click','false')
})
context_menu.addEventListener('mouseleave',()=>{
ipcRenderer.send('set-click','true')
});
</script>
</body>
</html>
|