forked from WishMelz/imgur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
323 lines (294 loc) · 12.3 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>imgur</title>
<meta name="description" content="基于imgur的web图片托管页面">
<meta name="keywords"
content="imgur,图床,免费图床,在线图床,图片托管,免费图片存储,图片上传网站,图片分享平台,图片存储服务,图片云存储,图片外链,快速图片上传,匿名图床服务,图片托管网站,图片存储工具,图片上传和存储服务,图片托管">
</head>
<style>
body,
html {
margin: 0;
padding: 0;
}
.forkicon {
position: fixed;
top: 0px;
right: 0px;
border: 0px;
width: 150px;
user-select: none;
}
.main {
padding-top: 60px;
min-height: 100vh;
box-sizing: border-box;
font-family: Avenir, Helvetica, Arial, sans-serif;
}
.upload-demo {
text-align: center;
}
.upload-demo .info {
display: inline-block;
text-align: center;
cursor: pointer;
outline: 0;
}
.upload {
background-color: #fff;
border: 1px dashed #d9d9d9;
border-radius: 6px;
box-sizing: border-box;
width: 360px;
height: 180px;
text-align: center;
position: relative;
overflow: hidden;
}
.upload.highlight {
background-color: rgba(32, 159, 255, .06);
border: 2px dashed #409eff;
}
.upload:hover {
border-color: #409eff;
}
.upinp {
display: none;
}
.upload-info .text {
color: #606266;
font-size: 14px;
text-align: center;
}
.upload-info .text em {
color: #409eff;
font-style: normal;
}
.upload-info .icon svg {
color: #c0c4cc;
margin: 40px 0 16px;
line-height: 50px;
}
.line {
display: block;
height: 1px;
width: 100%;
margin: 24px 0;
background-color: #dcdfe6;
position: relative;
}
.res-info {
text-align: center;
}
.res-link {
font-size: 20px;
padding-bottom: 20px
}
.footer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
text-align: center;
color: #c0c4cc;
font-size: 16px;
}
.footer span {
cursor: pointer;
}
.loading {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: #1413136b;
display: grid;
place-items: center;
display: none;
}
.loading svg {
width: 30px;
animation: rotateAnimation 2s infinite linear;
}
@keyframes rotateAnimation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
</style>
<body>
<a target="_blank" href="https://github.com/WishMelz/imgur">
<img class="forkicon"
src="https://cdn.jsdelivr.net/gh/WishMelz/file@master/messy/614b81962449bb3430193bdd6eaa3c7f.png" alt="">
</a>
<div class="main">
<div class="footer">
<span><a style="color:#606266;" href="https://github.com/WishMelz/imgur">基于 imgur 的web程序</a></span>
<!-- <span>|</span>
<span>历史记录</span> -->
</div>
<div class="upload-demo">
<div class="info">
<div class="upload">
<div class="upload-info">
<div class="icon">
<svg t="1692252618256" viewBox="0 0 1024 1024" version="1.1"
xmlns="http://www.w3.org/2000/svg" p-id="18739" width="60" height="60">
<path
d="M768.114773 384c0-140.8-115.2-256-256-256S256.114773 243.2 256.114773 384c-145.066667 0-260.266667 119.466667-256 264.533333 4.266667 140.8 128 247.466667 268.8 247.466667H384.114773c25.6 0 42.666667-17.066667 42.666667-42.666667v-128H375.58144c-38.4 0-55.466667-46.933333-29.866667-72.533333l136.533334-136.533333c17.066667-17.066667 42.666667-17.066667 59.733333 0l136.533333 136.533333c25.6 25.6 8.533333 72.533333-29.866666 72.533333H597.448107v128c0 25.6 17.066667 42.666667 42.666666 42.666667h115.2c140.8 0 264.533333-106.666667 264.533334-247.466667 8.533333-145.066667-106.666667-264.533333-251.733334-264.533333z"
p-id="18740" fill="#c0c4cc"></path>
</svg>
</div>
<div class="text">将文件拖到此处,或 <em>点击上传</em> </div>
<div class="text"><b>支持 ctrl + v 上传</b></div>
</div>
<input type="file" class="upinp" name="file" multiple>
</div>
</div>
</div>
<div class="line"></div>
<div class="resmain">
<div class="res-info">
<div class="res-link">
<b id="resurl">https://i.imgur.com/nGI3Js1.png</b>
</div>
<div class="res-img">
<img id="resimg" src="https://i.imgur.com/nGI3Js1.png" alt="">
</div>
</div>
</div>
</div>
<div class="loading">
<div class="info">
<svg t="1692859661070" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4043" width="128" height="128"><path d="M511.882596 287.998081h-0.361244a31.998984 31.998984 0 0 1-31.659415-31.977309v-0.361244c0-0.104761 0.115598-11.722364 0.115598-63.658399V96.000564a31.998984 31.998984 0 1 1 64.001581 0V192.001129c0 52.586273-0.111986 63.88237-0.119211 64.337537a32.002596 32.002596 0 0 1-31.977309 31.659415zM511.998194 959.99842a31.998984 31.998984 0 0 1-31.998984-31.998984v-96.379871c0-51.610915-0.111986-63.174332-0.115598-63.286318s0-0.242033 0-0.361243a31.998984 31.998984 0 0 1 63.997968-0.314283c0 0.455167 0.11921 11.711527 0.11921 64.034093v96.307622a31.998984 31.998984 0 0 1-32.002596 31.998984zM330.899406 363.021212a31.897836 31.897836 0 0 1-22.866739-9.612699c-0.075861-0.075861-8.207461-8.370021-44.931515-45.094076L195.198137 240.429485a31.998984 31.998984 0 0 1 45.256635-45.253022L308.336112 263.057803c37.182834 37.182834 45.090463 45.253022 45.41197 45.578141A31.998984 31.998984 0 0 1 330.899406 363.021212zM806.137421 838.11473a31.901448 31.901448 0 0 1-22.628318-9.374279L715.624151 760.859111c-36.724054-36.724054-45.018214-44.859267-45.097687-44.93874a31.998984 31.998984 0 0 1 44.77618-45.729864c0.32512 0.317895 8.395308 8.229136 45.578142 45.411969l67.88134 67.88134a31.998984 31.998984 0 0 1-22.624705 54.630914zM224.000113 838.11473a31.901448 31.901448 0 0 0 22.628317-9.374279l67.88134-67.88134c36.724054-36.724054 45.021826-44.859267 45.097688-44.93874a31.998984 31.998984 0 0 0-44.776181-45.729864c-0.32512 0.317895-8.395308 8.229136-45.578142 45.411969l-67.88134 67.884953a31.998984 31.998984 0 0 0 22.628318 54.627301zM255.948523 544.058589h-0.361244c-0.104761 0-11.722364-0.115598-63.658399-0.115598H95.942765a31.998984 31.998984 0 1 1 0-64.00158h95.996952c52.586273 0 63.88237 0.111986 64.337538 0.11921a31.998984 31.998984 0 0 1 31.659414 31.97731v0.361244a32.002596 32.002596 0 0 1-31.988146 31.659414zM767.939492 544.058589a32.002596 32.002596 0 0 1-31.995372-31.666639v-0.361244a31.998984 31.998984 0 0 1 31.659415-31.970085c0.455167 0 11.754876-0.11921 64.34115-0.11921h96.000564a31.998984 31.998984 0 0 1 0 64.00158H831.944685c-51.936034 0-63.553638 0.111986-63.665624 0.115598h-0.335957zM692.999446 363.0176a31.998984 31.998984 0 0 1-22.863126-54.381656c0.317895-0.32512 8.229136-8.395308 45.41197-45.578141l67.88134-67.884953A31.998984 31.998984 0 1 1 828.693489 240.429485l-67.892177 67.88134c-31.020013 31.023625-41.644196 41.759794-44.241539 44.393262l-0.697201 0.722488a31.908673 31.908673 0 0 1-22.863126 9.591025z" fill="#ffffff" p-id="4044"></path></svg>
</div>
</div>
</body>
<script>
/**
* imgur 上传图片的 clientId
* 注册应用:https://api.imgur.com/oauth2/addclient
* 查看已注册:https://imgur.com/account/settings/apps
*/
const clientId = 'b2e5734394755e0'
let uploadInp = document.querySelector('.upinp')
let dropzone = document.querySelector('.upload')
let loadingDom = document.querySelector('.loading')
// 阻止默认的拖放行为
dropzone.addEventListener('dragover', function (e) {
e.preventDefault()
dropzone.classList.add('highlight')
})
// 拖放结束时移除高亮样式
dropzone.addEventListener('dragleave', function (e) {
dropzone.classList.remove('highlight')
})
// 处理拖放事件
dropzone.addEventListener('drop', function (e) {
e.preventDefault()
dropzone.classList.remove('highlight')
var files = e.dataTransfer.files
handleImage(files)
})
uploadInp.addEventListener('change', function (e) {
var file = e.target.files
handleImage(file)
})
document.querySelector('.upload').onclick = function () {
uploadInp.click()
}
async function handleImage(file) {
let fileOne = file[0]
const formData = new FormData()
formData.append('image', fileOne)
loadingDom.style.display = 'grid'
const res = await fetch('https://api.imgur.com/3/upload', {
method: 'POST',
headers: { Authorization: `Client-ID ${clientId}` },
body: formData,
})
loadingDom.style.display = 'none'
if (res.ok) {
const resData = await res.json()
if (resData.success) {
setHistory(resData.data.link)
}
}
}
function setHistory(url) {
document.querySelector('#resurl').innerHTML = url
document.querySelector('#resimg').src = url
let urlList = localStorage.getItem('historyList')
if (urlList) {
urlList = JSON.parse(urlList)
} else {
urlList = []
}
urlList.push({
url,
timer: Date.now()
})
localStorage.setItem('historyList', JSON.stringify(urlList))
}
document.addEventListener("paste", function (event) {
var isChrome = false
if (event.clipboardData || event.originalEvent) {
//某些chrome版本使用的是event.originalEvent
var clipboardData =
event.clipboardData || event.originalEvent.clipboardData
if (clipboardData.items) {
// for chrome
var items = clipboardData.items,
len = items.length,
blob = null
isChrome = true
for (var i = 0; i < len; i++) {
if (items[i].type.indexOf("image") !== -1) {
//getAsFile() 此方法只是living standard firefox ie11 并不支持
blob = items[i].getAsFile()
}
}
if (blob !== null) {
var reader = new FileReader()
reader.readAsDataURL(blob)
//base64码显示
reader.onload = function (event) {
// event.target.result 即为图片的Base64编码字符串
var base64_str = event.target.result
let blob = dataURLtoBlob(base64_str)
let file = blobToFile(blob, Date.now() + ".png")
handleImage([file])
}
}
}
}
})
function dataURLtoBlob(dataurl) {
var arr = dataurl.split(","),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n)
while (n--) {
u8arr[n] = bstr.charCodeAt(n)
}
return new Blob([u8arr], { type: mime })
}
function blobToFile(theBlob, fileName) {
theBlob.lastModifiedDate = new Date() // 文件最后的修改日期
theBlob.name = fileName // 文件名
return new File([theBlob], fileName, {
type: theBlob.type,
lastModified: Date.now(),
})
}
</script>
</html>