-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.html
138 lines (128 loc) · 4.13 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
<html>
<head>
<!-- JQuery v1.11.2 -->
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<!-- Bootstrap v3.3.2 -->
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"
/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<!-- SweetAlert v0.5.0 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/0.5.0/sweet-alert.min.js"></script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/0.5.0/sweet-alert.css"
/>
<!-- Dropzone v1.3.12 -->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/gh/dropzone/[email protected]/downloads/css/dropzone.css"
/>
<script src="https://cdn.jsdelivr.net/gh/dropzone/[email protected]/downloads/dropzone.js"></script>
</head>
<body>
<div class="container">
<div role="tabpanel">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">
<a
href="#pastebin"
aria-controls="pastebin"
role="tab"
data-toggle="tab"
>Pastebin</a
>
</li>
<li role="presentation">
<a
href="#fileupload"
aria-controls="fileupload"
role="tab"
data-toggle="tab"
>File Upload</a
>
</li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="pastebin">
<form id="pastebin-form">
<label for="content">File Content</label>
<textarea
class="form-control"
id="pastebin-content"
name="pastebin-content"
></textarea>
<input type="submit" class="btn btn-default" />
</form>
</div>
<div role="tabpanel" class="tab-pane" id="fileupload">
<form action="/upload" class="dropzone" id="dropzone"></form>
</div>
</div>
</div>
<hr />
Or, paste a file anywhere on the page!
</div>
<script>
Dropzone.options.dropzone = {
init: function () {
this.on("success", function (file, response) {
window.open(response.url, "_blank");
});
},
};
$(() => {
$("#pastebin-form").submit(function (e) {
e.preventDefault();
var file_content = $("#pastebin-content").val();
$.ajax({
type: "POST",
dataType: "json",
data: {
content: $("#pastebin-content").val(),
},
url: "/paste",
success: function (data) {
$("#pastebin-content").val("");
window.open(data.url, "_blank");
},
error: function (jqXHR, status, message) {
sweetAlert(status, message, "error");
},
});
});
$("html").on("paste", (jqEvent) => {
const e = jqEvent.originalEvent;
if (e.clipboardData) {
for (let item of e.clipboardData.items) {
if (item.kind === "file") {
const file = item.getAsFile();
const reader = new FileReader();
reader.onload = (e) => {
const dataURL = e.target.result;
$.ajax({
type: "POST",
dataType: "json",
data: {
dataurl: dataURL,
filename: file.name,
},
url: "/image",
success: function (data) {
window.open(data.url, "_blank");
},
error: function (jqXHR, status, message) {
sweetAlert(status, message, "error");
},
});
};
reader.readAsDataURL(file);
}
}
}
});
});
</script>
</body>
</html>