From b8a7be3c34e1083ac39e021cd2bf5304d39c9316 Mon Sep 17 00:00:00 2001 From: Siddhi Thoke Date: Sun, 19 May 2024 11:52:47 +0530 Subject: [PATCH 1/2] feature complete --- Url_shortener/index.html | 45 ++++++++++++++++++++++++++++ Url_shortener/script.js | 64 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 Url_shortener/index.html create mode 100644 Url_shortener/script.js diff --git a/Url_shortener/index.html b/Url_shortener/index.html new file mode 100644 index 00000000..ae9e9932 --- /dev/null +++ b/Url_shortener/index.html @@ -0,0 +1,45 @@ + + + + + + URL Shortener + + + +
+

URL Shortener

+ + + +
+ + + diff --git a/Url_shortener/script.js b/Url_shortener/script.js new file mode 100644 index 00000000..035a333e --- /dev/null +++ b/Url_shortener/script.js @@ -0,0 +1,64 @@ +document.getElementById("shorten-btn").addEventListener("click", async () => { + const urlInput = document.getElementById("url-input").value.trim(); + if (urlInput) { + const apiUrl = "https://spoo-me-url-shortener.p.rapidapi.com/"; + const options = { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + Accept: "application/json", + "X-RapidAPI-Key": "a9691f48eemsh89135388428c926p181a59jsn952d884f92e7", + "X-RapidAPI-Host": "spoo-me-url-shortener.p.rapidapi.com", + }, + body: new URLSearchParams({ + url: urlInput, + }), + }; + + try { + const response = await fetch(apiUrl, options); + const result = await response.json(); + console.log("API response:", result); // Log the response for debugging + + if (result && result.short_url) { + const shortUrl = result.short_url; + document.getElementById("short-url").textContent = shortUrl; + document.getElementById("result").classList.remove("hidden"); + } else { + alert("Error shortening URL: " + (result.message || "Unknown error")); + } + } catch (error) { + console.error("Error:", error); + alert("Error shortening URL: " + error.message); + } + } else { + alert("Please enter a valid URL."); + } +}); + +document.getElementById("copy-btn").addEventListener("click", () => { + const shortUrl = document.getElementById("short-url").textContent; + navigator.clipboard + .writeText(shortUrl) + .then(() => { + alert("URL copied to clipboard!"); + }) + .catch((err) => { + console.error("Could not copy text: ", err); + alert("Failed to copy URL."); + }); +}); + +document.getElementById("share-btn").addEventListener("click", () => { + const shortUrl = document.getElementById("short-url").textContent; + if (navigator.share) { + navigator + .share({ + title: "Check out this URL", + url: shortUrl, + }) + .catch((error) => console.error("Error sharing:", error)); + } else { + alert("Sharing not supported on this browser"); + } +}); From 38e99aaa0e02f5e9fd323b7ae8bab1c094d991ea Mon Sep 17 00:00:00 2001 From: Siddhi Thoke Date: Mon, 20 May 2024 22:43:57 +0530 Subject: [PATCH 2/2] changed the directory name as suggested --- {Url_shortener => URL Shortener}/index.html | 0 {Url_shortener => URL Shortener}/script.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {Url_shortener => URL Shortener}/index.html (100%) rename {Url_shortener => URL Shortener}/script.js (100%) diff --git a/Url_shortener/index.html b/URL Shortener/index.html similarity index 100% rename from Url_shortener/index.html rename to URL Shortener/index.html diff --git a/Url_shortener/script.js b/URL Shortener/script.js similarity index 100% rename from Url_shortener/script.js rename to URL Shortener/script.js