-
Notifications
You must be signed in to change notification settings - Fork 53
/
index.html
169 lines (157 loc) · 4.24 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
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8"/>
<title>paste</title>
<style>
* {
box-sizing: border-box;
font-family: monospace;
font-size: 1.1em;
}
#plaintext {
width: 100%;
height: 100%;
padding: .5em;
border: 0;
margin: 0;
resize: none;
color: #eeeeee;
background: #000000;
}
body.invert #plaintext {
color: #000000;
background: #eeeeee;
}
#plaintext-wrapper {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 2em;
}
#nav {
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: 2em;
line-height: 2em;
text-align: right;
vertical-align: middle;
background: #333333;
color: #ffffff;
white-space: nowrap;
}
body.invert #nav {
background: #aaaaaa;
color: #000000;
}
#nav .nav-left {
float: left;
}
#nav a {
display: inline-block;
padding: 0 .5em;
text-decoration: none;
color: inherit;
cursor: pointer;
}
#nav a:hover {
background: #666666;
}
body.invert #nav a:hover {
background: #999999;
}
#nav #text-offer-value {
border: 1px solid #999999;
background: transparent;
width: calc(100vw - 11em);
text-overflow: ellipsis;
color: inherit;
margin-right: 5px;
}
#nav .nav-text-offer { display:none; }
#nav.text-offer .nav-default { display:none; }
#nav.text-offer .nav-text-offer { display:inline; }
</style>
<script src="lzma.js"></script>
<script>
var matches;
var lzma = new LZMA("lzma_worker.js");
document.addEventListener('DOMContentLoaded', function(){
document.getElementById("plaintext").focus();
if (matches = /(?:^|\;)invert\=([01])(?:\;|$)/.exec(document.cookie)) {
if (matches[1] === '1') {
document.body.classList.add("invert");
}
}
var base64 = location.hash.substr(1);
if (base64.length == 0) return;
if (!fetch) {
alert("Your browser does not support this page. Sorry! :(");
return;
}
fetch("data:application/octet-stream;base64,"+base64).then(r => r.blob()).then(function(blob){
var reader = new FileReader();
reader.onload = function(){
var compressed_data = Array.from(new Uint8Array(reader.result));
lzma.decompress(compressed_data, function(plaintext, error){
if (error) {
alert("Failed to decompress data: "+error);
return;
}
document.getElementById("plaintext").value = plaintext;
});
};
reader.readAsArrayBuffer(blob);
});
});
function url_generate(format) {
var plaintext = document.getElementById("plaintext").value;
lzma.compress(plaintext, 1, function(compressed, error){
if (error) {
alert("Failed to compress data: "+error);
return;
}
var reader = new FileReader();
reader.onload = function(){
var base64 = reader.result.substr(reader.result.indexOf(",")+1);
var url = "https://"+location.host+location.pathname+"#"+base64;
var result;
if (format === 'markdown') {
result = "[paste]("+url+")";
} else {
result = url;
}
text_offer(result);
};
reader.readAsDataURL(new Blob([new Uint8Array(compressed)]));
});
}
function text_offer(text) {
document.getElementById("text-offer-value").value = text;
document.getElementById("nav").classList.add("text-offer");
}
function text_offer_copy() {
var input = document.getElementById("text-offer-value");
input.select();
document.execCommand('copy');
text_offer_cancel();
}
function text_offer_cancel() {
document.getElementById("text-offer-value").value = "";
document.getElementById("nav").classList.remove("text-offer");
}
function invert() {
var pref = document.body.classList.contains("invert") ? 0 : 1;
document.cookie = "invert="+pref+";max-age=63072000";
document.body.classList[pref?"add":"remove"]("invert");
}
</script>
</head>
<body>
<div id="plaintext-wrapper"><textarea id="plaintext" spellcheck="false"></textarea></div>
<div id="nav"><span class="nav-default"><a class="nav-left" href="https://github.com/topaz/paste">[github]</a><a class="nav-left" onclick="invert()">[invert colors]</a><a onclick="url_generate('raw')">[generate url]</a><a onclick="url_generate('markdown')">[generate markdown link]</a></span><span class="nav-text-offer"><input id="text-offer-value"/><a onclick="text_offer_copy()">[copy]</a><a onclick="text_offer_cancel()">[cancel]</a></span></div>
</body>
</html>