-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
62 lines (56 loc) · 1.94 KB
/
index.html
File metadata and controls
62 lines (56 loc) · 1.94 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>URL Shortener</title>
<link rel="stylesheet" href="./style.css" />
<link rel="icon" type="image/x-icon" href="./Favicon.png" />
</head>
<body>
<div class="container">
<h2>Figma URL Shortener</h2>
<input type="text" id="longUrl" placeholder="Enter your Figma URL here" />
<button onclick="shortenURL()">Shorten URL</button>
<div class="result" id="shortenedUrl" bis_skin_checked="1"></div>
</div>
<a href="https://uxrishu.com/" target="_blank">
<img src="./logo.svg" alt="" class="uxrishu">
</a>
<script>
async function shortenURL() {
const longUrl = document.getElementById("longUrl").value;
const accessToken = "be70b50a28811d5482523a6c0ea1dcd10eab03ec"; // Replace with your Bitly API token
const url = "https://api-ssl.bitly.com/v4/shorten";
const headers = {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
};
const data = {
long_url: longUrl,
};
try {
const response = await fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(data),
});
if (response.ok) {
const jsonResponse = await response.json();
document.getElementById(
"shortenedUrl"
).innerHTML = `Shortened URL: <a href="${jsonResponse.link}" target="_blank">${jsonResponse.link}</a>`;
} else {
document.getElementById(
"shortenedUrl"
).innerText = `Error: ${response.statusText}`;
}
} catch (error) {
document.getElementById(
"shortenedUrl"
).innerText = `Fetch error: ${error}`;
}
}
</script>
</body>
</html>