forked from antimatter15/js-typed-array-sha1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html~
199 lines (187 loc) · 7.01 KB
/
index.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
<!doctype html>
<html manifest="cache.manifest">
<head>
<title>SHA1 Checksum Calculator</title>
<style>
body {
background-color: #ADADAD;
font-family: sans-serif;
color:white;
}
a {
text-decoration: none;
font-weight: bold;
color:#EDFAFF;
}
#floater {
top: 40%;
left: 50%;
position:absolute;
}
#center {
display: inline-block;
color: black;
margin: -150px 0 0 -300px;
width: 600px;
z-index: 99;
padding-right: 15px;
padding-left: 15px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
opacity: 1;
background-image: -webkit-linear-gradient(273deg, rgb(252, 252, 252), rgb(247, 247, 247) 3%, rgb(242, 242, 242) 12%, rgb(217, 217, 217) 90%, rgb(191, 191, 191));
background-image: -moz-linear-gradient(273deg, rgb(252, 252, 252), rgb(247, 247, 247) 3%, rgb(242, 242, 242) 12%, rgb(217, 217, 217) 90%, rgb(191, 191, 191));
background-attachment: initial;
background-origin: initial;
background-clip: initial;
background-color: initial;
-webkit-box-shadow: #A5A5A5 0px 0px 6px 6px;
-moz-box-shadow: #A5A5A5 0px 0px 6px 6px;
border-top-left-radius: 30px 30px;
border-top-right-radius: 0 0;
border-bottom-right-radius: 30px 30px;
border-bottom-left-radius: 0 0;
background-position: initial initial;
background-repeat: initial initial;
}
#value {
color: black;
margin: 0 0 0 -260px;
top: 230px;
left: 42px;
width: 510px;
padding-bottom: 10px;
z-index: 99;
padding-right: 15px;
padding-left: 15px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
opacity: 1;
background-image: -webkit-linear-gradient(273deg, rgb(252, 252, 252), rgb(247, 247, 247) 3%, rgb(242, 242, 242) 12%, rgb(217, 217, 217) 90%, rgb(191, 191, 191));
background-image: -moz-linear-gradient(273deg, rgb(252, 252, 252), rgb(247, 247, 247) 3%, rgb(242, 242, 242) 12%, rgb(217, 217, 217) 90%, rgb(191, 191, 191));
background-attachment: initial;
background-origin: initial;
background-clip: initial;
background-color: initial;
-webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 6px 6px;
-moz-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 6px 6px;
font-family: monospace;
border-bottom-right-radius: 10px 10px;
border-bottom-left-radius: 10px 10px;
background-position: initial initial;
background-repeat: initial initial;
padding-top: 15px;
font-size: 20px;
}
</style>
</head>
<body>
<script>
var p = 0, worker;
function fileSlice(file, start, length){
var end = length + start;
if(file.mozSlice){
return file.mozSlice(start, end);
}else if(file.webkitSlice){
return file.webkitSlice(start, end);
}
}
function selected(file){
if(worker) worker.terminate();
var size = file.size;
var realsize = Math.ceil((size/4 + 3)/16) * 16 * 4;
worker = new Worker('worker.js');
lasttime = +new Date;
lastprocessed = 0;
worker.onmessage = function(e){
if(e.data.action == 'requestChunk'){
var fr = new FileReader();
fr.onload = function(){
worker.postMessage(fr.result);
}
fr.readAsArrayBuffer(fileSlice(file, e.data.position, e.data.amount));
}else{
var time = +new Date;
var pct = e.data.processed/realsize;
document.getElementById('progress').value = pct;
document.getElementById('value').style.display = '';
document.getElementById('progress').style.display = '';
document.getElementById('value').innerHTML = e.data.hash;
document.getElementById('pct').innerHTML = (pct*100).toFixed(2)+'%';
document.getElementById('speed').innerHTML = (((e.data.processed - lastprocessed)/((time - lasttime)/1000))/1024/1024).toFixed(2) + 'MB/s';
//e.data.processed+'/'+realsize+' '+
if(p++ % 14 == 0){
lasttime = time;
lastprocessed = e.data.processed;
}
}
}
worker.onerror = function(e){
console.log(e);
}
worker.postMessage({file: file, size: size});
}
//do html5 drag and drop
document.addEventListener("dragenter", function(e){e.preventDefault();e.stopPropagation()}, false);
document.addEventListener("dragexit", function(e){e.preventDefault();e.stopPropagation()}, false);
document.addEventListener("dragover", function(e){e.preventDefault();e.stopPropagation()}, false);
document.addEventListener("drop", function(e){
e.preventDefault();
e.stopPropagation();
var files = e.dataTransfer.files;
if(files.length > 0) selected(files[0]);
}, false);
</script>
<div id="floater">
<div id="center">
<h1 >SHA1 <span style="color:gray">Checksum</span> Calculator</h1>
<p>
This is a simple <b>SHA1 checksumming utility</b> written in <b>Javascript</b> and uses the File API, Typed Arrays, and Web Workers. It's <b>pretty fast</b> and can handle files up to <b>several gigabytes</b> and works <b>offline</b> (just bookmark this page).
</p>
<div id="featdetect">
<p>
To begin, select <b>a file</b> (or <b>drag it here</b>).
</p>
<div style="float:right">
<span id="speed" style='padding-right:10px;'></span>
<span id="pct" style='font-weight:bold'></span>
</div>
<p>
<input type="file" onchange="selected(this.files[0])">
</p>
</div>
<progress id="progress" style="width:570px;margin-bottom:12px;display:none" value=0></progress>
</div>
<div id="value">
3da541559918a808c2402bba5012f6c60b27661c
</div>
</div>
<footer style="position: absolute; bottom: 0; width: auto;padding: 20px;">
<b>Hello.</b> This app was made by <a href="http://twitter.com/antimatter15">@antimatter15</a> (or <a href="https://plus.google.com/116347431032639424492/about">Google+</a>). Read my <a href="http://antimatter15.com/wp/">blog</a> for some other neat stuff. See how it works on <a href="https://github.com/antimatter15/js-typed-array-sha1">Github</a>.
</footer>
<script>
(function(){
try {
var fr = new FileReader();
if(Worker && new Uint8Array && ArrayBuffer && fr.readAsArrayBuffer){
//yay
}else{
throw "boo";
}
}catch(err){
document.getElementById('featdetect').innerHTML = "It appears <b>your browser does not support all</b> the necessary features, it is known to work in recent versions of Chrome and Firefox.";
}
})();
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1367972-4']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>