-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreurl2.html
More file actions
228 lines (215 loc) · 7.22 KB
/
Copy pathreurl2.html
File metadata and controls
228 lines (215 loc) · 7.22 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>縮短網址與Qrcode生成服務</title>
<style>
body {
font-family: 'Comic Sans MS', 'Raleway', Arial, sans-serif;
background: #FFF0F5;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
height: 100vh;
}
#shorten-form {
background: #fff;
padding: 30px;
border-radius: 20px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
max-width: 500px;
width: 100%;
text-align: center;
margin-top: 50px;
}
h1 {
font-size: 28px;
color: #FF69B4;
margin-bottom: 20px;
}
h1::before {
content: '🌸 ';
}
h1::after {
content: ' 🌸';
}
input, select {
width: calc(100% - 22px);
padding: 12px;
margin: 10px 0;
border: 2px solid #FFB6C1;
border-radius: 15px;
font-size: 16px;
transition: all 0.3s ease;
}
input:focus, select:focus {
outline: none;
border-color: #FF69B4;
box-shadow: 0 0 10px rgba(255, 105, 180, 0.3);
}
button {
width: auto;
padding: 12px 25px;
margin: 15px 0;
border: none;
border-radius: 25px;
background: linear-gradient(45deg, #FF69B4, #FFB6C1);
color: #fff;
font-size: 18px;
cursor: pointer;
transition: all 0.3s ease;
}
button:hover {
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(255, 105, 180, 0.4);
}
p#result {
font-size: 18px;
color: #FF69B4;
margin-top: 20px;
word-break: break-word;
}
p#result a {
color: #FF1493;
text-decoration: none;
}
p#result a:hover {
text-decoration: underline;
}
#qrcode {
margin-top: 20px;
display: flex;
justify-content: center;
}
footer {
margin-top: 30px;
padding: 15px 0;
text-align: center;
font-size: 16px;
color: #FF69B4;
}
footer a {
color: #FF1493;
text-decoration: none;
}
footer a:hover {
text-decoration: underline;
}
footer::before, footer::after {
content: '💖';
margin: 0 10px;
}
#success-message {
background-color: #DFF2BF;
color: #4F8A10;
padding: 10px;
border-radius: 15px;
margin-top: 15px;
font-size: 16px;
opacity: 0;
transition: opacity 0.5s ease-in-out;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
</head>
<body>
<div id="shorten-form">
<h1>縮短網址與Qrcode生成服務</h1>
<input type="text" id="url" placeholder="貼上你想縮短的網址">
<select id="service">
<option value="tinyurl" selected>TinyURL</option>
<option value="reurl">reurl</option>
<option value="bitly">Bitly</option>
</select>
<button onclick="shortenUrl()">縮短網址</button>
<div id="success-message" style="display: none;">短網址已複製到剪貼簿 🎉</div>
<div id="qrcode"></div>
<p id="result"></p>
</div>
<footer>
Made by <a href="https://lin.ee/Z2KRZior" target="_blank">ㄚ亮笑長練功坊</a>
</footer>
<script>
async function shortenUrl() {
const url = document.getElementById('url').value;
const service = document.getElementById('service').value;
let shortUrl;
if (service === 'tinyurl') {
shortUrl = await shortenWithTinyURL(url);
} else if (service === 'reurl') {
shortUrl = await shortenWithReurl(url);
} else if (service === 'bitly') {
shortUrl = await shortenWithBitly(url);
}
document.getElementById('result').innerHTML = `縮短後的網址:<a href="${shortUrl}" target="_blank">${shortUrl}</a>`;
copyToClipboard(shortUrl);
generateQRCode(shortUrl);
showSuccessMessage();
}
async function shortenWithTinyURL(longUrl) {
const response = await fetch(`https://tinyurl.com/api-create.php?url=${encodeURIComponent(longUrl)}`);
const shortUrl = await response.text();
return shortUrl;
}
async function shortenWithReurl(longUrl) {
const apiKey = '4070ff49d794e63d175f3b663c974755ecd3b136919204df8a38b58d65165567c4f5d6';
const response = await fetch('https://api.reurl.cc/shorten', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'reurl-api-key': apiKey
},
body: JSON.stringify({ url: longUrl })
});
const data = await response.json();
return data.short_url;
}
async function shortenWithBitly(longUrl) {
const apiKey = '0e666f3e0090523ace171ff4148f8aacb89dc157';
const response = await fetch('https://api-ssl.bitly.com/v4/shorten', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ long_url: longUrl })
});
const data = await response.json();
return data.link;
}
function copyToClipboard(text) {
const tempInput = document.createElement('input');
tempInput.style.position = 'absolute';
tempInput.style.left = '-9999px';
tempInput.value = text;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand('copy');
document.body.removeChild(tempInput);
}
function generateQRCode(url) {
document.getElementById('qrcode').innerHTML = '';
new QRCode(document.getElementById('qrcode'), {
text: url,
width: 128,
height: 128
});
}
function showSuccessMessage() {
const successMessage = document.getElementById('success-message');
successMessage.style.display = 'block';
successMessage.style.opacity = '1';
setTimeout(() => {
successMessage.style.opacity = '0';
setTimeout(() => {
successMessage.style.display = 'none';
}, 500);
}, 3000);
}
</script>
</body>
</html>