-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurlchckr.html
184 lines (164 loc) · 5.78 KB
/
urlchckr.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Check URL views</title>
<style>
@import url(https://fonts.bunny.net/css?family=athiti:200);
/* Root font-size scaling based on viewport width */
html {
font-size: calc(1vw + 1vh + 0.5vmin); /* Adjusts base font size based on the viewport */
margin: 0;
padding: 0;
}
body {
font-family: 'Athiti', sans-serif;
background-color: black;
color: rgb(2, 230, 2);
margin: 10px;
padding: 0;
box-sizing: border-box;
}
.container {
max-width: 90%;
margin: auto;
padding: 10px;
box-sizing: border-box;
}
input, button {
margin: 10px 0;
padding: 10px;
width: 100%;
box-sizing: border-box;
font-size: 1rem;
}
button {
background: #1f1f1f;
color: #fff;
border: 1px solid #454545;
cursor: pointer;
}
.result {
margin-top: 20px;
padding: 10px;
border: 1px solid #454545;
background: #1f1f1f;
font-size: 1rem;
word-wrap: break-word;
}
.error {
color: red;
font-size: 1rem;
}
h2 {
font-size: 1.5rem;
text-align: center;
}
label {
font-size: 1rem;
}
footer, .footerStatic {
position: absolute; /* Change from fixed to absolute */
bottom: 0;
padding: 10px;
background-color: #272727c2;
backdrop-filter: blur(10px);
color: #efefef;
width: 100vw;
left: 0;
font-size: 2rem;
text-align: center;
box-sizing: border-box; /* Ensures padding doesn't add extra width */
}
.footerDynamic {
position: fixed;
bottom: 0;
left: 0;
width: 100vw;
padding: 10px;
background-color: #272727c2;
backdrop-filter: blur(10px);
color: #efefef;
font-size: 2rem;
text-align: center;
box-sizing: border-box;
transition: opacity 0.5s ease-in-out;
opacity: 0; /* Initially hidden */
pointer-events: none; /* Disable interaction when hidden */
}
footer a {
color: #ffffff;
margin: 0 10px;
text-decoration: none;
}
footer a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h2>Test Total Visits, Last Access, and Original URL</h2>
<label for="short-url">Enter Shortened URL:</label>
<input type="text" id="short-url" placeholder="e.g., https://postanote.org/c984d0">
<button id="check-btn">Check Visits</button>
<div class="result" id="result-container" style="display: none;">
<p><strong>Total Visits:</strong> <span id="total-visits">0</span></p>
<p><strong>Last Accessed:</strong> <span id="last-accessed">N/A</span></p>
<p><strong>Original URL:</strong> <span id="original-url">N/A</span></p>
</div>
<p id="error-message" class="error" style="display: none;"></p>
</div>
<footer class="footerDynamic">
<a href="about.html">About</a> |
<a href="FAQ.html">FAQ</a> |
<a href="urlmkr.html">URLmkr</a> |
</footer>
<script>
document.getElementById('check-btn').addEventListener('click', async () => {
const shortUrl = document.getElementById('short-url').value.trim();
const errorContainer = document.getElementById('error-message');
const resultContainer = document.getElementById('result-container');
const originalUrlEl = document.getElementById('original-url');
const totalVisitsEl = document.getElementById('total-visits');
const lastAccessedEl = document.getElementById('last-accessed');
errorContainer.style.display = 'none';
resultContainer.style.display = 'none';
if (!shortUrl) {
errorContainer.textContent = 'Please enter a valid URL or just shortener.';
errorContainer.style.display = 'block';
return;
}
try {
// Extract the short code from the URL
const urlParts = shortUrl.split('/');
const shortCode = urlParts[urlParts.length - 1];
// Fetch data from the /visits endpoint
const response = await fetch('https://postanote.org/visits');
// const response = await fetch('http://127.0.0.1:5500/visits');
if (!response.ok) {
throw new Error('Failed to fetch visit data.');
}
const data = await response.json();
// Find the matching short URL data
const match = data.find(item => item.short === shortCode);
if (match) {
originalUrlEl.textContent = match.original;
totalVisitsEl.textContent = match.visits;
lastAccessedEl.textContent = match.last_accessed ? `${match.last_accessed} UTC` : "N/A";
resultContainer.style.display = 'block';
} else {
errorContainer.textContent = 'Short URL not found in the database.';
errorContainer.style.display = 'block';
}
} catch (error) {
console.error(error);
errorContainer.textContent = 'An error occurred. Please try again.';
errorContainer.style.display = 'block';
}
});
</script>
<script src="footer.js"></script>
</body>
</html>