From 9265e3fee2080680f78dadbfd6700a3d0ffa5c36 Mon Sep 17 00:00:00 2001 From: Jonas van Leeuwen <159904649+jonasvanleeuwen19@users.noreply.github.com> Date: Fri, 27 Sep 2024 13:00:09 +0200 Subject: [PATCH] Update index.html --- redirect/index.html | 51 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/redirect/index.html b/redirect/index.html index f307976..cdcf5be 100644 --- a/redirect/index.html +++ b/redirect/index.html @@ -28,6 +28,12 @@ width: 3rem; height: 3rem; } + + .favicon { + width: 24px; + height: 24px; + margin-right: 10px; + } @@ -37,7 +43,6 @@
Loading...
-
Redirecting...
@@ -50,6 +55,30 @@ return urlParams.get(param); } + // Function to get the base URL from a full URL + function getBaseUrl(fullUrl) { + const url = new URL(fullUrl); + return url.hostname; + } + + // Function to get favicon from the site + function getFaviconUrl(baseUrl) { + return `https://www.google.com/s2/favicons?domain=${baseUrl}`; + } + + // Function to get the site title + async function getSiteTitle(url) { + try { + const response = await fetch(url); + const text = await response.text(); + const titleMatch = text.match(/(.*?)<\/title>/); + return titleMatch ? titleMatch[1] : 'No Title Found'; + } catch (error) { + console.error('Error fetching site title:', error); + return 'No Title Found'; + } + } + // Get the 'url' parameter from the querystring const targetUrl = getQueryParam('url'); @@ -58,12 +87,22 @@ try { // Validate the URL const url = new URL(targetUrl); - document.getElementById('message').textContent = `Redirecting to ${url.toString()}...`; + const baseUrl = getBaseUrl(targetUrl); + const faviconUrl = getFaviconUrl(baseUrl); + + // Fetch the site title + getSiteTitle(targetUrl).then(title => { + document.getElementById('message').innerHTML = ` + <img src="${faviconUrl}" alt="favicon" class="favicon"> + Redirecting to <strong>${title}</strong> (${baseUrl}) + `; + + // Show loader and redirect after a short delay + setTimeout(() => { + window.location.href = targetUrl; + }, 1500); // Optional delay of 1.5 seconds to show the message and loader + }); - // Show loader and redirect after a short delay - setTimeout(() => { - window.location.href = url.toString(); - }, 1500); // Optional delay of 1.5 seconds to show the message and loader } catch (error) { // Invalid URL document.getElementById('message').textContent = "Invalid URL provided in the querystring.";