-
Notifications
You must be signed in to change notification settings - Fork 36
/
index.html
73 lines (68 loc) · 2.48 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Imgur-Upload</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.1/normalize.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="./css/style.css" rel="stylesheet" media="screen">
<link href="./css/mobile-style.css" rel="stylesheet" media="screen">
<link rel="shortcut icon" href="./favicon.png">
</head>
<body>
<div class="title">
<a href="https://github.com/carry0987/Imgur-Upload">
<h1>Imgur Upload API</h1>
</a>
<p>Use JavaScript To Upload Image</p>
</div>
<div class="dropzone">
<div class="info"></div>
</div>
<div class="container">
<div class="row">
<div class="col-12 col-md-12">
<div class="row justify-content-center" id="item-list"></div>
</div>
</div>
</div>
<script type="text/javascript" src="./dist/imgur.min.js"></script>
<script type="text/javascript">
const addImg = (selector, content) => {
const myDIV = document.querySelector(selector);
if (myDIV) {
const newContent = document.createElement('div');
newContent.innerHTML = content;
while (newContent.firstChild) {
myDIV.appendChild(newContent.firstChild);
}
} else {
console.error(`Element with selector "${selector}" not found.`);
}
}
const feedback = (res) => {
console.log(res);
if (res.success) {
const get_link = res.data.link.replace(/^http:\/\//i, 'https://');
const statusElement = document.querySelector('#item-list');
if (statusElement) {
statusElement.classList.add('success');
const content = `
<div class="col-6 col-md-3 item p-3">
<h5>Image:</h5>
<input type="text" class="form-control mb-3 image-url" value="${get_link}">
<img class="img-fluid" alt="Imgur-Upload" src="${get_link}">
</div>
`;
addImg('#item-list', content);
}
}
};
new Imgur({
clientid: 'b234bda60e00570', //You can change this ClientID
onSuccess: feedback
});
</script>
</body>
</html>