diff --git a/templates/assets/js/curl.js b/templates/assets/js/curl.js index 82a0821..dc7300a 100644 --- a/templates/assets/js/curl.js +++ b/templates/assets/js/curl.js @@ -1,64 +1,64 @@ -document.addEventListener('DOMContentLoaded', function() { +document.addEventListener('DOMContentLoaded', function () { // Get references to elements const curlButton = document.getElementById('curl'); const curlUrlInput = document.getElementById('curl-url'); const resultsContainer = document.getElementById('curl-results'); - - // Add click event listener to the button - curlButton.addEventListener('click', function() { - // Get the URL from the input - const url = curlUrlInput.value.trim(); - - // Validate URL - if (!url) { - showMessage('Please enter a URL', 'error'); - return; - } - // Update the url - const params = new URLSearchParams(); - params.append('url', url); - history.pushState(null, null, `?${params.toString()}`); - - // Show loading state - curlButton.disabled = true; - curlButton.innerHTML = 'Loading...'; - - // Clear previous results - resultsContainer.innerHTML = ''; - showMessage('Fetching content...', 'info'); - - // Make the request - handleCurlRequest(url); + // Add click event listener to the button + curlButton.addEventListener('click', function () { + // Get the URL from the input + const url = curlUrlInput.value.trim(); + + // Validate URL + if (!url) { + showMessage('Please enter a URL', 'error'); + return; + } + + // Update the url + const params = new URLSearchParams(); + params.append('url', url); + history.pushState(null, null, `?${params.toString()}`); + + // Show loading state + curlButton.disabled = true; + curlButton.innerHTML = 'Loading...'; + + // Clear previous results + resultsContainer.innerHTML = ''; + showMessage('Fetching content...', 'info'); + + // Make the request + handleCurlRequest(url); }); // Add enter key listener to input - curlUrlInput.addEventListener('keyup', function(event) { + curlUrlInput.addEventListener('keyup', function (event) { if (event.key === 'Enter') { - curlButton.click(); + curlButton.click(); } }); - + /** * Handle the curl API request * @param {string} url - The URL to curl */ function handleCurlRequest(url) { - // Encode the URL for the API endpoint - const encodedUrl = encodeURIComponent(url); - const apiEndpoint = `/api/v1/curl/${encodedUrl}`; - - fetch(apiEndpoint) - .then(response => response.json()) - .then(data => { - // Clear loading message - resultsContainer.innerHTML = ''; - - if (data.success === true) { - // Create a result card with iframe - const resultCard = document.createElement('div'); - resultCard.className = 'card shadow border-0 rounded-lg mb-5'; - - resultCard.innerHTML = ` + // Encode the URL for the API endpoint + const encodedUrl = encodeURIComponent(url); + const apiEndpoint = `/api/v1/curl/${encodedUrl}`; + + fetch(apiEndpoint) + .then(response => response.json()) + .then(data => { + // Clear loading message + resultsContainer.innerHTML = ''; + + if (data.success === true) { + // Create a result card with iframe + const resultCard = document.createElement('div'); + resultCard.className = 'card shadow border-0 rounded-lg mb-5'; + + resultCard.innerHTML = `