mirror of
https://github.com/MrUnknownDE/utools.git
synced 2026-04-19 06:03:45 +02:00
feat: add shareable links
This commit is contained in:
@@ -96,6 +96,35 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- URL Parameter Functions ---
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the URL with DNS lookup parameters
|
||||||
|
* @param {string} domain - The domain name
|
||||||
|
* @param {string} type - The DNS record type
|
||||||
|
*/
|
||||||
|
function updateUrlParams(domain, type) {
|
||||||
|
const url = new URL(window.location);
|
||||||
|
url.searchParams.set('domain', domain);
|
||||||
|
url.searchParams.set('type', type);
|
||||||
|
window.history.pushState({}, '', url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads URL parameters and returns domain and type if present
|
||||||
|
* @returns {object|null} Object with domain and type, or null if not present
|
||||||
|
*/
|
||||||
|
function getUrlParams() {
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const domain = urlParams.get('domain');
|
||||||
|
const type = urlParams.get('type');
|
||||||
|
|
||||||
|
if (domain && type) {
|
||||||
|
return { domain, type };
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// --- DNS Lookup Specific Functions ---
|
// --- DNS Lookup Specific Functions ---
|
||||||
function displayDnsResults(data, outputEl) {
|
function displayDnsResults(data, outputEl) {
|
||||||
if (!data.records || Object.keys(data.records).length === 0) {
|
if (!data.records || Object.keys(data.records).length === 0) {
|
||||||
@@ -114,6 +143,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
dnsLookupErrorEl.classList.remove('hidden');
|
dnsLookupErrorEl.classList.remove('hidden');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update URL with parameters
|
||||||
|
updateUrlParams(domain, type);
|
||||||
|
|
||||||
fetchAndDisplay(
|
fetchAndDisplay(
|
||||||
'/dns-lookup',
|
'/dns-lookup',
|
||||||
{ domain, type },
|
{ domain, type },
|
||||||
@@ -126,6 +159,21 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes DNS lookup from URL parameters if they exist
|
||||||
|
*/
|
||||||
|
function executeLookupFromUrl() {
|
||||||
|
const params = getUrlParams();
|
||||||
|
if (params) {
|
||||||
|
// Populate the input fields
|
||||||
|
dnsDomainInput.value = params.domain;
|
||||||
|
dnsTypeSelect.value = params.type;
|
||||||
|
|
||||||
|
// Trigger the lookup
|
||||||
|
handleDnsLookupClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// --- Initial Load & Event Listeners ---
|
// --- Initial Load & Event Listeners ---
|
||||||
fetchVersionInfo(); // Lade Versionsinfo für Footer
|
fetchVersionInfo(); // Lade Versionsinfo für Footer
|
||||||
|
|
||||||
@@ -134,4 +182,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (event.key === 'Enter') handleDnsLookupClick();
|
if (event.key === 'Enter') handleDnsLookupClick();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Execute lookup from URL parameters if present
|
||||||
|
executeLookupFromUrl();
|
||||||
|
|
||||||
}); // End DOMContentLoaded
|
}); // End DOMContentLoaded
|
||||||
@@ -328,6 +328,28 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
// --- Lookup Functions ---
|
// --- Lookup Functions ---
|
||||||
|
|
||||||
|
// --- URL Parameter Functions ---
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the URL with IP lookup parameter
|
||||||
|
* @param {string} ip - The IP address or domain to lookup
|
||||||
|
*/
|
||||||
|
function updateLookupUrlParams(ip) {
|
||||||
|
const url = new URL(window.location);
|
||||||
|
url.searchParams.set('ip', ip);
|
||||||
|
window.history.pushState({}, '', url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads URL parameters and returns IP if present
|
||||||
|
* @returns {string|null} IP or domain from URL, or null if not present
|
||||||
|
*/
|
||||||
|
function getLookupUrlParams() {
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
return urlParams.get('ip');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Zeigt Fehler im Lookup-Bereich an */
|
/** Zeigt Fehler im Lookup-Bereich an */
|
||||||
function showLookupError(message) {
|
function showLookupError(message) {
|
||||||
if (!lookupErrorEl) return;
|
if (!lookupErrorEl) return;
|
||||||
@@ -780,6 +802,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
resetLookupResults(); // Reset results before starting
|
resetLookupResults(); // Reset results before starting
|
||||||
hideLookupError();
|
hideLookupError();
|
||||||
|
|
||||||
|
// Update URL with the query parameter
|
||||||
|
updateLookupUrlParams(query);
|
||||||
|
|
||||||
if (isValidIpAddress(query)) {
|
if (isValidIpAddress(query)) {
|
||||||
// Input is an IP address
|
// Input is an IP address
|
||||||
console.log(`Lookup button clicked for IP: ${query}`);
|
console.log(`Lookup button clicked for IP: ${query}`);
|
||||||
@@ -829,6 +854,20 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes IP lookup from URL parameters if they exist
|
||||||
|
*/
|
||||||
|
function executeLookupFromUrl() {
|
||||||
|
const ipParam = getLookupUrlParams();
|
||||||
|
if (ipParam && lookupIpInput) {
|
||||||
|
// Populate the input field
|
||||||
|
lookupIpInput.value = ipParam;
|
||||||
|
|
||||||
|
// Trigger the lookup
|
||||||
|
handleLookupClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// --- Initial Load & Event Listeners ---
|
// --- Initial Load & Event Listeners ---
|
||||||
fetchIpInfo(); // Lade Infos zur eigenen IP
|
fetchIpInfo(); // Lade Infos zur eigenen IP
|
||||||
fetchVersionInfo(); // Lade Versionsinfo für Footer
|
fetchVersionInfo(); // Lade Versionsinfo für Footer
|
||||||
@@ -845,4 +884,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
// Der Event Listener für den IP-Link wird jetzt in fetchIpInfo() hinzugefügt,
|
// Der Event Listener für den IP-Link wird jetzt in fetchIpInfo() hinzugefügt,
|
||||||
// nachdem die IP erfolgreich abgerufen wurde.
|
// nachdem die IP erfolgreich abgerufen wurde.
|
||||||
|
|
||||||
|
// Execute lookup from URL parameters if present
|
||||||
|
executeLookupFromUrl();
|
||||||
|
|
||||||
}); // End DOMContentLoaded
|
}); // End DOMContentLoaded
|
||||||
Reference in New Issue
Block a user