slimshadow commited on
Commit
5efa6b0
·
verified ·
1 Parent(s): 78abcd0

Create script.js

Browse files
Files changed (1) hide show
  1. script.js +39 -0
script.js ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ async function downloadReel() {
2
+ const reelUrl = document.getElementById('reelUrl').value.trim();
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
+ // Check if the URL is empty or invalid
11
+ if (!reelUrl || !isValidUrl(reelUrl)) {
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
+ const response = await fetch(`https://slimshadow-instagram-r-api.hf.space/download/?reel_url=${encodeURIComponent(reelUrl)}`);
21
+ const data = await response.json();
22
+
23
+ if (data && data.url) {
24
+ // Display download link
25
+ messageDiv.textContent = 'Reel downloaded successfully!';
26
+ downloadLinkDiv.innerHTML = `<a href="${data.url}" download>Click here to download the Reel</a>`;
27
+ } else {
28
+ messageDiv.textContent = 'Failed to fetch Reel. Please try again later.';
29
+ }
30
+ } catch (error) {
31
+ messageDiv.textContent = 'An error occurred. Please try again later.';
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
+ }