File size: 1,564 Bytes
6882b9f
 
 
1dc763f
6882b9f
 
 
1dc763f
6882b9f
 
1dc763f
6882b9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1dc763f
6882b9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1dc763f
6882b9f
 
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
<!DOCTYPE html>
<html>
<head>
    <title>URL.cut</title>
    <p></p>
</head>
<body>
    <h1>URLcut</h1>
    <label for="long-url">Enter a long link:</label>
    <p></p>
    <input type="text" id="long-url" placeholder="https://example.com">
    <p></p>
    <button id="shorten-button">Shorten</button>
    <br>
    <p></p>
    <label for="short-url">Short link:</label>
    <p></p>
    <input type="text" id="short-url" readonly>
    <p></p>
    <script>
        document.getElementById("shorten-button").addEventListener("click", function() {
            var longUrl = document.getElementById("long-url").value;

            // Выполнение запроса к API Bit.ly для сокращения ссылки
            fetch("https://api-ssl.bitly.com/v4/shorten", {
                method: "POST",
                headers: {
                    "Content-Type": "application/json",
                    "Authorization": "YOUR_API_TOKEN_BITLY"
                },
                body: JSON.stringify({
                    long_url: longUrl
                })
            })
            .then(response => response.json())
            .then(data => {
                var shortUrl = data.link;
                document.getElementById("short-url").value = shortUrl;
            })
            .catch(error => {
                console.error(error);
                document.getElementById("short-url").value = "Ошибка при сокращении ссылки.";
            });
        });
    </script>
    <p></p>
    Link shortener
</body>
</html>