-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurllist.html
More file actions
167 lines (144 loc) · 5.48 KB
/
urllist.html
File metadata and controls
167 lines (144 loc) · 5.48 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL List</title>
<style>
/* Global Styles */
body {
font-family: Arial, sans-serif;
background-color: #1f1f1f; /* Dark theme background color */
color: #ffffff; /* Dark theme text color */
margin: 0;
padding: 0;
}
/* Container Styles */
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #333333; /* Dark theme container background color */
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 5px;
}
/* Heading Styles */
h1 {
font-size: 24px;
margin-bottom: 20px;
color: #ffffff; /* Text color for headings */
}
/* URL List Styles */
.url-item {
border: 1px solid #444444; /* Dark theme border color */
margin-bottom: 10px;
padding: 10px;
border-radius: 5px;
transition: background-color 0.3s ease; /* CSS animation for background color */
display: flex;
flex-direction: column;
}
.url-item:hover {
background-color: #444444; /* Dark theme background color on hover */
}
.short-url {
color: #3399ff; /* Blue color for short URL */
font-weight: bold;
margin-bottom: 5px;
}
.original-url {
color: #33cc33; /* Green color for original URL */
word-wrap: break-word; /* Wrap long URLs */
}
.timestamp {
color: #888888;
font-size: 14px;
}.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
/* Custom CSS for the "Back to Home" button */
.back-button {
display: inline-block;
padding: 10px 20px;
background-color: #007bff; /* Button background color */
color: #fff; /* Button text color */
text-decoration: none;
border-radius: 5px;
transition: background-color 0.3s ease; /* Smooth color transition on hover */
}
.back-button:hover {
background-color: #0056b3; /* New background color on hover */
}
/* Add more CSS for the URL list display here */
</style>
</head>
<body>
<a href="/" class="back-button">Back to Home</a>
<div class="container">
<h1>URL List</h1>
<div id="urlList">
<!-- URL items will be dynamically populated here -->
</div>
</div>
<!-- Inside your HTML file -->
<!-- Add your JavaScript code here to populate the URL list and handle sharing -->
<script src="/socket.io/socket.io.js"></script> <!-- Include the Socket.io client library -->
<script>
// Initialize Socket.io client
const socket = io();
// Function to fetch URL list data from the server
async function fetchUrlListData() {
try {
const response = await fetch('/api/urllist-data'); // Use the new endpoint
if (!response.ok) {
throw new Error('Network response was not ok');
}
return await response.json();
} catch (error) {
console.error('Error fetching URL list data:', error);
return [];
}
}
// Function to populate the URL list
async function populateUrlList() {
const urlList = document.getElementById('urlList');
const urlData = await fetchUrlListData(); // Use the new function
// Clear existing content
urlList.innerHTML = '';
// Loop through the URL data and create items
urlData.forEach((data) => {
const urlItem = document.createElement('div');
urlItem.classList.add('url-item'); // Apply CSS class for styling
// Short URL
const shortUrl = document.createElement('div');
shortUrl.classList.add('short-url');
shortUrl.textContent = data.shortUrl !== 'None' ? `Short URL: http://localhost:3000/${data.shortUrl}` : 'Short URL: N/A';
// Original URL
const originalUrl = document.createElement('div');
originalUrl.classList.add('original-url');
originalUrl.textContent = `Original URL: ${data.originalUrl}`;
// Timestamp
const timestamp = document.createElement('div');
timestamp.classList.add('timestamp');
const createdAtDate = new Date(data.createdAt);
timestamp.textContent = `Timestamp: ${createdAtDate.toLocaleString()}`;
// Append elements to the URL item
urlItem.appendChild(shortUrl);
urlItem.appendChild(originalUrl);
urlItem.appendChild(timestamp);
// Append the URL item to the URL list
urlList.appendChild(urlItem);
});
}
// Call the function to populate the URL list
populateUrlList();
</script>
</body>
</html>