blob: 5861dafed1d450a30c2aa5035fd7c0a200cadb02 [file] [log] [blame]
DTabidzeb00a1db2024-01-12 18:30:14 +04001<!DOCTYPE html>
2<html lang="en">
DTabidzeb00a1db2024-01-12 18:30:14 +04003<head>
4 <meta charset="UTF-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <title>URL Shortener</title>
DTabidze71353b52024-01-17 16:02:55 +04007 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css">
DTabidzeb00a1db2024-01-12 18:30:14 +04008</head>
DTabidzeb00a1db2024-01-12 18:30:14 +04009<body>
10 <h1>URL Shortener</h1>
DTabidzeb00a1db2024-01-12 18:30:14 +040011 <form action="/" method="post">
12 <label for="address">Address:</label>
13 <input type="text" id="address" name="address" required>
DTabidzeb00a1db2024-01-12 18:30:14 +040014 <label for="custom">Custom Name (optional):</label>
15 <input type="text" id="custom" name="custom">
DTabidzeb00a1db2024-01-12 18:30:14 +040016 <button type="submit">Shorten URL</button>
17 </form>
DTabidzeb00a1db2024-01-12 18:30:14 +040018 <h2>Named Addresses:</h2>
19 <table>
20 <tr>
21 <th>Name</th>
22 <th>Address</th>
DTabidzeb00a1db2024-01-12 18:30:14 +040023 <th>Active</th>
24 </tr>
DTabidze71353b52024-01-17 16:02:55 +040025 {{- range .NamedAddresses -}}
DTabidzeb00a1db2024-01-12 18:30:14 +040026 <tr>
27 <td><a href="{{ .Name }}" target="_blank">{{ .Name }}</a></td>
28 <td>{{ .Address }}</td>
DTabidze71353b52024-01-17 16:02:55 +040029 <td>
30 <input type="checkbox" role="switch" {{ if .Active }}checked{{ end }} onclick="toggle('{{ .Name }}', {{ not .Active }});">
31 </td>
DTabidzeb00a1db2024-01-12 18:30:14 +040032 </tr>
DTabidze71353b52024-01-17 16:02:55 +040033 {{- end -}}
DTabidzeb00a1db2024-01-12 18:30:14 +040034 </table>
35</body>
DTabidze71353b52024-01-17 16:02:55 +040036<script type="application/javascript">
37 function toggle(name, status) {
38 const data = {
39 "name": name,
40 "active": status,
41 };
42 fetch("/api/update/", {
43 method: "POST",
44 headers: {
45 'Content-Type': 'application/json',
46 },
47 body: JSON.stringify(data),
48 })
49 .then(response => {
50 if (response.ok) {
51 window.location.reload();
52 }
53 })
54 .catch((error) => {
55 console.error('Error:', error);
56 });
57 }
58</script>
DTabidzeb00a1db2024-01-12 18:30:14 +040059</html>