-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
269 lines (247 loc) · 9.5 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Data URL Converter</title>
<style>
body {
font-family: 'Roboto', sans-serif;
background-color: #202327;
padding: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
background-color: #2d3339;
padding: 20px;
border-radius: 15px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
text-align: center;
color: #fff;
border: 5.5px;
border-style: solid;
border-color: #4f5964;
overflow-y: hidden;
overflow-x: hidden;
}
.form-group {
margin-bottom: 20px;
display: flex;
width: 180px;
position: absolute;
top: 50px;
margin-left: 5px;
border-radius: 15px;
}
.dropdown-container {
display: flex;
gap: 10px;
width: 180px;
position: absolute;
top: 0px;
right: 292px;
border-radius: 15px;
}
select, input[type="file"], textarea, button {
width: 100%;
margin-bottom: 10px;
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
font-family: monospace;
}
select {
flex: 1;
}
textarea {
border: 3px solid #4f5963;
border-radius: 10px;
font-size: 16px;
font-family: 'Roboto', sans-serif;
color: #fff;
background-color: #394047;
resize: none;
width: 96%;
height: 160px;
}
button {
padding: 18px 10px;
margin: 5px;
margin-bottom: 20px;
border: none;
border-radius: 11px;
background-color: #3b8ea5;
color: #f0f0f0;
cursor: pointer;
font-size: 16px;
font-weight: 500;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #41a3be;
}
#imagePreview {
display: none;
margin-bottom: 20px;
max-width: 100%;
height: auto;
}
.hidden {
display: none;
}
.actions {
display: flex;
gap: 10px;
}
h1 {
margin-top: 0px;
}
::placeholder {
color: #ccc;
}
</style>
</head>
<body>
<div class="container">
<h1>dinguschan's Converter</h1>
<div class="form-group">
<select id="conversionType" onchange="toggleInputArea()">
<option value="rawHtml">Raw HTML Code</option>
<option value="githubLink">Raw GitHub Link</option>
<option value="websiteSource">Website Link</option>
<option value="uploadImage">Upload an Image</option>
<option value="uploadTextFile">Upload a .txt File</option>
</select>
</div>
<div class="dropdown-container">
<div class="form-group">
<select id="outputType">
<option value="dataUrl">Data URL</option>
<option value="blobUrl">Blob URL</option>
</select>
</div>
</div>
<textarea id="inputArea" placeholder="Enter your media format here"></textarea>
<input type="file" id="fileInput" class="hidden" accept="image/*,text/*" onchange="handleFile()">
<img id="imagePreview" src="" alt="Image Preview" class="hidden">
<div class="actions">
<button onclick="convertToUrl()">Generate URL</button>
<button onclick="copyToClipboard()">Copy to Clipboard</button>
<button onclick="clearFields()">Clear</button>
</div>
<textarea id="resultOutput" placeholder="Your converted data:/blob: URL will appear here" readonly ></textarea>
</div>
<script>
let corsProxies = [
'https://api.codetabs.com/v1/proxy?quest=',
'https://api.codetabs.com/v1/tmp/?quest='
];
let currentProxyIndex = 0;
function toggleInputArea() {
const conversionType = document.getElementById('conversionType').value;
const inputArea = document.getElementById('inputArea');
const fileInput = document.getElementById('fileInput');
const imagePreview = document.getElementById('imagePreview');
if (conversionType === 'uploadImage' || conversionType === 'uploadTextFile') {
inputArea.style.display = 'none';
fileInput.style.display = 'block';
imagePreview.classList.toggle('hidden', conversionType !== 'uploadImage');
} else {
inputArea.style.display = 'block';
fileInput.style.display = 'none';
imagePreview.classList.add('hidden');
}
}
function handleFile() {
const conversionType = document.getElementById('conversionType').value;
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
if (conversionType === 'uploadImage') {
reader.onload = function(e) {
const imagePreview = document.getElementById('imagePreview');
imagePreview.src = e.target.result;
imagePreview.classList.remove('hidden');
document.getElementById('resultOutput').value = convertToBlobUrl(e.target.result);
}
reader.readAsDataURL(file);
} else if (conversionType === 'uploadTextFile') {
reader.onload = function(e) {
const textContent = e.target.result;
const base64EncodedText = btoa(unescape(encodeURIComponent(textContent)));
document.getElementById('resultOutput').value = convertToBlobUrl('data:text/plain;base64,' + base64EncodedText);
}
reader.readAsText(file);
}
}
}
function convertToUrl() {
const conversionType = document.getElementById('conversionType').value;
const outputType = document.getElementById('outputType').value;
if (conversionType === 'rawHtml') {
convertRawHtmlToUrl(outputType);
} else if (conversionType === 'githubLink' || conversionType === 'websiteSource') {
fetchAndConvertUrl(outputType);
}
}
function convertRawHtmlToUrl(outputType) {
const htmlInput = document.getElementById('inputArea').value;
const base64EncodedHTML = btoa(unescape(encodeURIComponent(htmlInput)));
const dataUrl = 'data:text/html;base64,' + base64EncodedHTML;
document.getElementById('resultOutput').value = convertOutput(dataUrl, outputType);
}
function fetchAndConvertUrl(outputType) {
const url = document.getElementById('inputArea').value.trim();
const proxyUrl = corsProxies[currentProxyIndex];
fetch(proxyUrl + url)
.then(response => response.text())
.then(html => {
const base64EncodedHTML = btoa(unescape(encodeURIComponent(html)));
const dataUrl = 'data:text/html;base64,' + base64EncodedHTML;
document.getElementById('resultOutput').value = convertOutput(dataUrl, outputType);
})
.catch(error => {
alert('Error fetching content: ' + error);
});
currentProxyIndex = (currentProxyIndex + 1) % corsProxies.length;
}
function convertOutput(dataUrl, outputType) {
if (outputType === 'blobUrl') {
return convertToBlobUrl(dataUrl);
} else {
return dataUrl;
}
}
function convertToBlobUrl(dataUrl) {
const blob = dataUrlToBlob(dataUrl);
const blobUrl = URL.createObjectURL(blob);
return blobUrl;
}
function dataUrlToBlob(dataUrl) {
const parts = dataUrl.split(',');
const mime = parts[0].match(/:(.*?);/)[1];
const data = atob(parts[1]);
const array = [];
for (let i = 0; i < data.length; i++) {
array.push(data.charCodeAt(i));
}
return new Blob([new Uint8Array(array)], { type: mime });
}
function copyToClipboard() {
const resultOutput = document.getElementById('resultOutput');
resultOutput.select();
document.execCommand('copy');
alert('Result copied to clipboard!');
}
function clearFields() {
document.getElementById('inputArea').value = '';
document.getElementById('resultOutput').value = '';
document.getElementById('fileInput').value = '';
document.getElementById('imagePreview').src = '';
document.getElementById('imagePreview').classList.add('hidden');
}
</script>
</body>
</html>