-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecondcode.html
More file actions
78 lines (67 loc) · 2.02 KB
/
secondcode.html
File metadata and controls
78 lines (67 loc) · 2.02 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
<!DOCTYPE html>
<html>
<head>
<title>File Loader</title>
<style>
#file-input {
display: none;
}
#file-content {
width: auto;
height: auto;
border: 1px solid #ccc;
padding: 10px;
overflow-y: scroll;
}
.copy-button {
display: none;
}
</style>
</head>
<body>
<button onclick="selectFile()">Select File</button>
<div id="file-content"></div>
<script>
function selectFile() {
var fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = '.txt'; // Specify the file types allowed, e.g., .txt, .csv
fileInput.addEventListener('change', function(event) {
var file = event.target.files[0];
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
displayFileContents(contents);
};
reader.readAsText(file);
});
fileInput.click();
}
function displayFileContents(contents) {
var fileContentDiv = document.getElementById('file-content');
fileContentDiv.innerHTML = '';
var lines = contents.split('\n');
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
var lineElement = document.createElement('div');
lineElement.textContent = line;
var copyButton = document.createElement('button');
copyButton.textContent = 'Copy';
copyButton.addEventListener('click', function() {
copyToClipboard(this.parentNode.firstChild.textContent);
});
lineElement.appendChild(copyButton);
fileContentDiv.appendChild(lineElement);
}
}
function copyToClipboard(text) {
var textarea = document.createElement('textarea');
textarea.value = text;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
}
</script>
</body>
</html>