Spaces:
Running
Running
slimshadow
commited on
Update script.js
Browse files
script.js
CHANGED
@@ -1,39 +1,31 @@
|
|
1 |
-
async function
|
2 |
-
|
3 |
-
const messageDiv = document.getElementById('message');
|
4 |
-
const downloadLinkDiv = document.getElementById('downloadLink');
|
5 |
-
|
6 |
-
// Clear previous messages
|
7 |
-
messageDiv.textContent = '';
|
8 |
-
downloadLinkDiv.innerHTML = '';
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
messageDiv.textContent = 'Please enter a valid Instagram Reel URL.';
|
13 |
-
return;
|
14 |
-
}
|
15 |
-
|
16 |
-
// Display loading message
|
17 |
-
messageDiv.textContent = 'Processing... Please wait.';
|
18 |
|
19 |
try {
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
const data = await response.json();
|
22 |
|
23 |
-
if
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
27 |
} else {
|
28 |
-
|
29 |
}
|
30 |
} catch (error) {
|
31 |
-
|
|
|
32 |
}
|
33 |
-
}
|
34 |
-
|
35 |
-
// Function to validate the URL format
|
36 |
-
function isValidUrl(url) {
|
37 |
-
const regex = /^(https?:\/\/)?(www\.)?instagram\.com\/reel\/[A-Za-z0-9_-]+$/;
|
38 |
-
return regex.test(url);
|
39 |
-
}
|
|
|
1 |
+
document.getElementById("reelForm").addEventListener("submit", async function (e) {
|
2 |
+
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
const reelUrl = document.getElementById("reelUrl").value;
|
5 |
+
const apiUrl = `https://slimshadow-instagram-r-api.hf.space/download/?reel_url=${encodeURIComponent(reelUrl)}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
try {
|
8 |
+
// Make the API request
|
9 |
+
const response = await fetch(apiUrl);
|
10 |
+
if (!response.ok) {
|
11 |
+
throw new Error("Failed to fetch the reel. Please check the URL and try again.");
|
12 |
+
}
|
13 |
+
|
14 |
+
// Parse the JSON response
|
15 |
const data = await response.json();
|
16 |
|
17 |
+
// Check if the response contains a valid download link
|
18 |
+
if (data.download_link) {
|
19 |
+
// Show the download link to the user
|
20 |
+
document.getElementById("result").classList.remove("hidden");
|
21 |
+
const downloadLinkElement = document.getElementById("downloadLink");
|
22 |
+
downloadLinkElement.href = data.download_link;
|
23 |
+
downloadLinkElement.textContent = "Click here to download the reel";
|
24 |
} else {
|
25 |
+
throw new Error("Download link not available. Please try again.");
|
26 |
}
|
27 |
} catch (error) {
|
28 |
+
// Handle any errors that occur during the fetch or parsing
|
29 |
+
alert("Error: " + error.message);
|
30 |
}
|
31 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|