-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathauto.html
388 lines (319 loc) · 7.1 KB
/
auto.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
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<!DOCTYPE html>
<meta charset="UTF-8">
<title>/</title>
<style>
body,h1,h2,h3,h4,h5,h6,p,form,ol,ul{margin:0;}
ol,ul{padding:0;}
html{
font:1em Arial,sans-serif;
color:#2d3033;
}
a{color:#06F;text-decoration:none;}
a:visited{
color:#b0F;
}
nav{
padding:0 .6em;
line-height:50px;
overflow: hidden;
}
nav a{
float:left;
}
nav a:after{
content:'/';
opacity:.5;
padding:0 .2em;
}
.文件列表{
}
.文件列表 a{
display:block;
padding:.5em .6em;
line-height:1.2;
}
.文件列表 a:hover{
background:#EEE;
}
.文件列表 a[data-type="directory"]{
color:#F70;
}
.文件列表 a b{
margin-right:.5em;
}
.文件列表 a time{
font-size:.8em;
opacity:.5;
margin-right:.3em;
}
.文件列表 a cite{
font-size:.8em;
font-style:normal;
opacity:.5;
}
</style>
<div id="M">
<nav>
<a href="#/">/</a>
</nav>
<div class="body">
</div>
</div>
<script>//templet.js
(function(上帝){
var
需编码字串表={
'&':'&',
'<':'<',
'>':'>',
'"':'"',
"'":''',
'/':'/',
'`':'`',
'=':'='
},
编码成文本=function(string){
return String(string).replace(/[&<>"'`=\/]/g,function(s){
return 需编码字串表[s];
}).replace(/\n\r/g,function(s){
return '\\n';
})
},
编码成网页=function(string){
return String(string);
return String(string).replace(/"/g,function(s){
return '\\'+s;
});
},
编译模板=function(模板字串){
var
已打开的钥匙们=[],
钥匙前缀们='_',
模板字串=模板字串
.replace(/[\n\r\t]/g,'')
.replace(/"/g,'\\"')
.replace(/\{\{(#|\/|\^|&|\$)?(.+?)\}\}/g,function(整段文字,动作,管道){
if(管道=='.')
管道='_循环关键字';
管道=管道.split('|');
钥匙=管道.shift();
var
管道前,
管道后,
钥匙和管道;
管道前=管道.reverse().join('(')+'(';
管道后=[];
管道后.length=管道.length;
管道后=管道后.join(')')+')';
钥匙和管道=管道前+钥匙+管道后;
钥匙前缀们=[];
钥匙前缀们.length=已打开的钥匙们.length+3;
钥匙前缀们=钥匙前缀们.join('_');
switch(动作){
case '#':
已打开的钥匙们.push(钥匙);
return '");\
(function(){\
var '+钥匙前缀们+'value;\
var '+钥匙前缀们+'key;\
if( typeof('+钥匙+')!=="undefined" && ('+钥匙+') && ('+钥匙+'='+钥匙和管道+'))\
for('+钥匙前缀们+'key in '+钥匙+')\
with('+钥匙前缀们+'value='+钥匙+'['+钥匙前缀们+'key]){\
var _钥匙='+钥匙前缀们+'key;\
var _循环关键字='+钥匙前缀们+'value;\
$return.push("';
break;
case '$':
已打开的钥匙们.push(钥匙);
return '");\
(function(){\
if( typeof('+钥匙+')!=="undefined" && ('+钥匙+') ){\
$return.push("';
break;
case '^':
已打开的钥匙们.push(钥匙);
return '");\
(function(){\
if( typeof('+钥匙+')==="undefined" || !('+钥匙+') ){\
$return.push("';
break;
case '/':
var
长度=已打开的钥匙们.length+1;
while(已打开的钥匙们[--长度]&&已打开的钥匙们[长度]!=钥匙);
已打开的钥匙们.splice(长度,1);
return '")\
}\
})();\
$return.push("';
break;
case '&':
return '");\
if(typeof('+钥匙+')!=="undefined")\
$return.push(编码成网页('+钥匙和管道+'||\'\'));\
\
$return.push("';
break;
default:
return '");\
if(typeof('+钥匙+')!=="undefined")\
$return.push(编码成文本('+钥匙和管道+'||\'\'));\
\
$return.push("';
break;
}
});
模板字串='\
var $return=[];\
var _value=$data;\
var _key;\
with($data){\
$return.push("'+模板字串+'");\
}\
return $return.join(\'\');';
return Function('$data','编码成文本','编码成网页',模板字串);
},
运转=function(模板字串,数据,作用域){
//console.log(编译模板(模板字串));
return 编译模板(模板字串).call(作用域||上帝,数据,编码成文本,编码成网页);
};
上帝.模板={
运转:运转,
编译模板:编译模板,
编码成文本:编码成文本,
编码成网页:编码成网页,
};
})(this);
</script>
<script>
var
toArr=function(r){
return Array.prototype.slice.apply(r);
},
_=function(selector,pa){
return (pa||document).querySelector(selector);
},
__=function(selectors,pa){
return toArr((pa||document).querySelectorAll(selectors));
};
Element.prototype._=function(selector){
return _(selector,this);
};
Element.prototype.__=function(selectors){
return __(selectors,this);
};
var
en=encodeURIComponent,
de=function(text){
try{
return decodeURIComponent(text);
}catch(e){};
return text;
};
var
文件列表模板=`
<div class="文件列表">
{{#fileslist}}
{{$type=='file'}}
<a href="{{path}}{{name|en}}" data-type="{{type}}">
<b>{{name}}</b>
<time>{{mtime|时间格式化}}</time>
<cite>{{size}}</cite>
</a>
{{/type=='file'}}
{{$type=='directory'}}
<a href="#{{path}}{{name}}" data-type="{{type}}">
<b>{{name}}</b>
<time>{{mtime|时间格式化}}</time>
</a>
{{/type=='directory'}}
{{/fileslist}}
</div>
`;
var
get=function(url,func){
var
x=new XMLHttpRequest();
x.open('GET',url);
x.onload=function(){
var
r=x.response;
var
contentType=x.getResponseHeader('Content-Type');
//if(contentType.match(/json/i)){
try{
r=JSON.parse(r);
}catch(e){}
//}
func(r);
}
x.send();
},
时间格式化=function(unix){
var
e=unix,
h=new Date(),
d;
if((e+'').match(/^\d{13}$/)){
d=new Date(e);
}else if((e+'').match(/^\d{10}$/)){
d=new Date(e*1000);
}else if((e+'').match(/^\d{0,9}$/)){
return '∞';
}else if((e+'').match(/GMT$/)){
d=new Date(e);
}else{
var arr=(e+'').split(/[-\/ :]/);
d=new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4], arr[5]);
}
var
g=parseInt,
f=g((h-d)/1000);
return !e||f<0?'刚刚':
f<60?(f+'秒前'):
(f/=60)<60?g(f)+'分前':
(f/=60)<24?g(f)+'时前':
(f/=24)<7?g(f)+'天前':
(f/=7)<2?g(f)+'周前':
d>new Date(h.getFullYear()+'-01-01')?(d.getMonth()+1)+'月'+d.getDate()+'日':
d.getFullYear()+'年'+(d.getMonth()+1)+'月'+d.getDate()+'日';
},
文件列表过滤=function(data){
return !data.name.match(/^\$|^(System Volume Information|BaiduNetdiskDownload|H)$|\.(log|torrent|cfg|115chrome[_\w]+)$/i);
},
文件目录导航=function(path){
path=path.replace(/^\/|\/$/ig,'');
if(!path)
path=[];
else
path=path.split('/').map(de);
// path.unshift('/');
var
history=[];
M._('nav').innerHTML='<a href="#/"></a>'+path.map(function(name){
history.push(name);
return '<a href="#/'+history.map(en).join('/')+'">'+de(name)+'</a>';
}).join('');
}
onhashchange=function(){
var
hash=location.hash.substr(1);
if(!hash){
hash='/';
}
var
path=hash;
if(!path.match(/\/$/)){
path+='/';
}
文件目录导航(path);
path=path.split('/').map(de).map(en).join('/');
get(path,function(fileslist){
M._('.body').innerHTML=模板.运转(文件列表模板,{
path:path,
fileslist:fileslist.filter(文件列表过滤)
});
});
};
onhashchange();
</script>