-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathencode.html
More file actions
149 lines (149 loc) · 6.03 KB
/
Copy pathencode.html
File metadata and controls
149 lines (149 loc) · 6.03 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>RDPCopy Encode</title>
<style>
body {
background: #F0F0F0;
font-family: sans-serif;
}
h2 {
margin-top: 35px;
margin-left: 55px;
}
#drop-area {
margin-top: 35px;
margin-left: 50px;
font-family: monospace;
width: 500px;
height: 250px;
background-color: rgba(0, 0, 0, 0.07);
border-radius: 6px;
border-style: dashed;
color: #555555;
font-size: 1em;
line-height: 1.4em;
padding: 5px 8px;
transition: background-color 0.2s ease 0s;
cursor: pointer;
}
.highlight {
background-color: #FFFFFF !important;
}
#drop-area:hover {
background-color: #FFFFFF;
}
@keyframes glow {
0% {
box-shadow: 0 0 0 0 #0075e0ff;
}
100% {
box-shadow: 0 0 30px 15px #0075e000;
}
}
</style>
</head>
<body>
<h2>RDPCopy Encode</h2>
<div id="drop-area">Drop yo file...</div>
<input type="file" id="file-input" style="display:none">
<button id="copy-button" style="display:none">Copy file</button>
<script>
var dropArea = document.getElementById('drop-area');
var fileInput = document.getElementById('file-input');
var copyButton = document.getElementById('copy-button');
var fileData = '';
var isSafari = navigator.userAgent.includes("Safari") && !navigator.userAgent.includes("Chrome");
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, preventDefaults, false);
document.body.addEventListener(eventName, preventDefaults, false);
});
['dragenter', 'dragover'].forEach(eventName => {
dropArea.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, unhighlight, false);
});
dropArea.addEventListener('drop', handleDrop, false);
dropArea.addEventListener('click', handleFileInputClick);
fileInput.addEventListener('change', () => handleFiles(fileInput.files));
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
function highlight(e) {
dropArea.classList.add('highlight');
}
function unhighlight(e) {
dropArea.classList.remove('highlight');
}
function handleDrop(e) {
var dt = e.dataTransfer;
var files = dt.files;
handleFiles(files);
}
function handleFiles(files) {
files = [... files];
encodeFile(files[0]);
}
function handleFileInputClick() {
fileInput.click();
}
function encodeFile(file) {
var reader = new FileReader();
reader.readAsDataURL(file);
var filename = file.name;
reader.onloadend = function () {
fileData = reader.result.substring(reader.result.indexOf('base64,') + 7) + '\n' + filename;
if (isSafari) {
dropArea.innerText = 'Click to copy file data.';
dropArea.removeEventListener('click', handleFileInputClick);
dropArea.onclick = function () {
copyToClipboard(fileData, true);
};
} else {
setTimeout(() => {
copyToClipboard(fileData, false);
}, 100);
}
}
}
function copyToClipboard(data, isSafari) {
try {
navigator
.clipboard
.writeText(data)
.then(() => {
dropArea.innerText = 'File encoded and copied!';
dropArea.style.animation = 'glow 0.75s ease forwards';
if (isSafari) {
setTimeout(() => {
dropArea.style.animation = '';
dropArea.innerText = 'Drop yo file...';
dropArea.onclick = null;
dropArea.addEventListener('click', handleFileInputClick);
}, 2000);
} else {
setTimeout(() => {
dropArea.style.animation = '';
dropArea.innerText = 'Drop yo file...';
}, 2000);
}
})
.catch(err => {
alert('Failed to write to clipboard: ' + err);
if (isSafari) {
restoreClickHandler();
}
});
} catch (err) {
alert('Failed to write to clipboard: ' + err);
if (isSafari) {
restoreClickHandler();
}
}
}
</script>
</body>
</html>