Skip to content

Commit 9265e3f

Browse files
Update index.html
1 parent daa0968 commit 9265e3f

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

redirect/index.html

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
width: 3rem;
2929
height: 3rem;
3030
}
31+
32+
.favicon {
33+
width: 24px;
34+
height: 24px;
35+
margin-right: 10px;
36+
}
3137
</style>
3238
</head>
3339
<body>
@@ -37,7 +43,6 @@
3743
<div class="spinner-border text-primary" role="status" id="loader">
3844
<span class="sr-only">Loading...</span>
3945
</div>
40-
<br>
4146
<div class="message" id="message">Redirecting...</div>
4247
</div>
4348

@@ -50,6 +55,30 @@
5055
return urlParams.get(param);
5156
}
5257

58+
// Function to get the base URL from a full URL
59+
function getBaseUrl(fullUrl) {
60+
const url = new URL(fullUrl);
61+
return url.hostname;
62+
}
63+
64+
// Function to get favicon from the site
65+
function getFaviconUrl(baseUrl) {
66+
return `https://www.google.com/s2/favicons?domain=${baseUrl}`;
67+
}
68+
69+
// Function to get the site title
70+
async function getSiteTitle(url) {
71+
try {
72+
const response = await fetch(url);
73+
const text = await response.text();
74+
const titleMatch = text.match(/<title>(.*?)<\/title>/);
75+
return titleMatch ? titleMatch[1] : 'No Title Found';
76+
} catch (error) {
77+
console.error('Error fetching site title:', error);
78+
return 'No Title Found';
79+
}
80+
}
81+
5382
// Get the 'url' parameter from the querystring
5483
const targetUrl = getQueryParam('url');
5584

@@ -58,12 +87,22 @@
5887
try {
5988
// Validate the URL
6089
const url = new URL(targetUrl);
61-
document.getElementById('message').textContent = `Redirecting to ${url.toString()}...`;
90+
const baseUrl = getBaseUrl(targetUrl);
91+
const faviconUrl = getFaviconUrl(baseUrl);
92+
93+
// Fetch the site title
94+
getSiteTitle(targetUrl).then(title => {
95+
document.getElementById('message').innerHTML = `
96+
<img src="${faviconUrl}" alt="favicon" class="favicon">
97+
Redirecting to <strong>${title}</strong> (${baseUrl})
98+
`;
99+
100+
// Show loader and redirect after a short delay
101+
setTimeout(() => {
102+
window.location.href = targetUrl;
103+
}, 1500); // Optional delay of 1.5 seconds to show the message and loader
104+
});
62105

63-
// Show loader and redirect after a short delay
64-
setTimeout(() => {
65-
window.location.href = url.toString();
66-
}, 1500); // Optional delay of 1.5 seconds to show the message and loader
67106
} catch (error) {
68107
// Invalid URL
69108
document.getElementById('message').textContent = "Invalid URL provided in the querystring.";

0 commit comments

Comments
 (0)