-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectFile.html
More file actions
85 lines (66 loc) · 1.7 KB
/
selectFile.html
File metadata and controls
85 lines (66 loc) · 1.7 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>Read local file </title>
</head>
<script>
"use strict";
var fetchText;
function readText() {
// fetch text
var text;
fetch(urlInput.value)
.then(response => response.text())
.then(getText);
}
function getText(txt){
fetchText = txt;
}
function isText(f) {
console.assert(f instanceof File);
return f.type.startsWith("text") || f.name.endsWith(".md")
|| f.name.endsWith(".js") || f.name.endsWith(".java");
}
function fileSelect(t) { //target is the button
var readTextt = readText()
var isFind=false;
setTimeout(function(){
var findedFileName;
function readFile(index) {
if( index > t.files.length-1 ){
return;
}
var reader = new FileReader();
var file = t.files[index];
reader.onload = function(e) {
var localText = e.target.result;
if(localText.replace(/\s/g,'')==fetchText.replace(/\s/g,'')){
isFind=true;
findedFileName = file.name;
out.innerText = t.files.length + " items checked, "+ findedFileName + " has the same content";
}
readFile(index+1);
}
reader.readAsBinaryString(file);
}
readFile(0);
}, 90);
if(isFind==false){
out.innerText = t.files.length + " items checked, all files different ";
}
}
</script>
<body>
<h2 id=title></h2>
<p>URL: <input id=urlInput value="https://maeyler.github.io/BLM305/README.md" style="width: 300px" ></p>
<input type=file id=button onChange='fileSelect(this)' multiple />
<p>
<output id=out></output>
</p>
<script>
title.innerText = document.title;
</script>
</body>
</html>