-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
144 lines (117 loc) · 3.84 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="Generate base64 encoded data URIs from files on your computer">
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAgMAAAAOFJJnAAAADFBMVEUAAAAtLS0tLS0tLS0PFSQuAAAABHRSTlMA+jaakgZ7swAAAJBJREFUGJWdz6ERwkAYROFHohCRlBCDvz5WsNxNJuIaYCYl0MTvkTQQDU2kj3QAIpMCYNU3s+rBf0sZ2s9KY1c6i6Nd6C16eyJZpDy/CYsoLXgRywSNQ7g+OOST8C3TXUPYrv1lg1IJ4ewSigFPaVxs49pvWHbEfp3GKOdnDCRbEKKzK4Ro7TuEYB6B1/pT5xcCqDaYG4+V+gAAAABJRU5ErkJggg==">
<title>Data URI generator</title>
<style>
html, body {
height: 100%;
}
body {
font: 12px/14px Monaco, Consolas, monospace;
background-color: #2d2d2d;
color: #d3d0c8;
margin: 0;
padding: 4px 5px;
box-sizing: border-box;
word-break: break-all;
overflow-wrap: break-word;
}
a {
color: #f2f0ec;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.scheme { color: #f99157; }
.mediatype { color: #99cc99; }
.base64 { color: #cc99cc; }
.data { color: #6699cc; }
.equals { color: #747369; }
::selection {
color: inherit;
background-color: rgba(81, 81, 81, 0.996);
}
::-moz-selection {
color: inherit;
background-color: rgba(81, 81, 81, 0.996);
}
@media print {
* {
background: transparent !important;
color: #000 !important;
}
}
</style>
</head>
<body><span id="content">Please enable JavaScript to use this tool</span><script>
(function() {
"use strict";
var content = document.getElementById("content");
if (!("ondrop" in document.body)
|| !window.FileReader
|| !("readAsDataURL" in new window.FileReader())) {
var win = /Win/i.test(navigator.platform),
ie = win && /*@cc_on!@*/false;
content.innerHTML =
"Your browser is outdated. To use this tool, please install the latest version of " +
"<a href=\"http://firefox.com\" target=\"_blank\">Mozilla Firefox</a>" +
(win ? ", " : " or ") +
"<a href=\"https://chrome.com\" target=\"_blank\">Google Chrome</a>" +
(win ? " or <a href=\"http://ie.microsoft.com\" target=\"_blank\">Internet Explorer</a>."
: ".") +
(ie ? "<br><br>If you don't want to change your web browser, you can also use this tool with " +
"<a href=\"https://www.google.com/chromeframe\" target=\"_blank\">Google Chrome Frame</a>."
: "");
return;
}
content.innerHTML = "Drop files here to generate a base64 data URI";
function createSpan(className, text) {
var span = document.createElement("span");
span.className = className;
span.textContent = text;
return span;
}
document.body.addEventListener("dragover", function(e) {
e.preventDefault();
e.dataTransfer.dropEffect = "copy";
}, false);
document.body.addEventListener("drop", function(e) {
var file = e.dataTransfer.files[0],
reader = new FileReader();
if (!file) return;
reader.addEventListener("loadend", function() {
var result = ""+reader.result,
uri = result.match(/^data:(.*?)(;base64)?(?:,(.*?)(=*))?$/);
if (!uri) {
content.innerHTML = "Error reading file";
return;
}
content.innerHTML = "";
content.appendChild(createSpan("scheme", "data:"));
content.appendChild(createSpan("mediatype", uri[1] || "application/octet-stream"));
if (uri[2]) {
content.appendChild(createSpan("mediatype", ";"));
content.appendChild(createSpan("base64", "base64,"));
} else
content.appendChild(createSpan("mediatype", ","));
if (uri[3]) {
content.appendChild(createSpan("data", uri[3]));
content.appendChild(createSpan("equals", uri[4]));
}
var range = document.createRange();
range.selectNodeContents(content);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}, false);
reader.readAsDataURL(file);
e.preventDefault();
}, false);
})();
</script></body>
</html>