-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
105 lines (97 loc) · 3.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Video Downloader</title>
</head>
<body>
<main>
<h2> Download Video from Instagram and Twitter </h2>
<h4> Note: This Only Works for Videos </h4>
<p> Kindly note, a delay is involved when using the site for the first time </p>
<p> Twitter download may fail more often. Check the Accuracy of the URL and Try again </p>
<div>
<form>
<input type="text" id="vid-input" placeholder="Paste Video link here">
<input type="submit" value="Get Download Link">
</form>
</div>
<div class="vid-loader" style="margin: auto; display: none; width: 50%; height: 100px; z-index: 5; background-color: #fff; border: 1px solid grey;text-align: center;">
Loading...
Please wait
</div>
<div class="download-box" style="display: none;"></div>
</main>
<script>
(function () {
function validURL(str) {
var pattern = new RegExp('^(https?:\\/\\/)?'+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+
'((\\d{1,3}\\.){3}\\d{1,3}))'+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+
'(\\?[;&a-z\\d%_.~+=-]*)?'+
'(\\#[-a-z\\d_]*)?$','i');
return !!pattern.test(str);
}
function showDownloadBox(poster, vidLink) {
const downloadBoxEle = document.querySelector('.download-box');
const text = `
<h2> Download Link </h2>
<a href="${vidLink}" referrerpolicy="no-referrer" rel="noreferrer noopener" download">
<img height="400px" src="${poster}" alt="Video Poster Image" anonymous referrerpolicy="no-referrer" />
Click here to download
</a>
`;
downloadBoxEle.insertAdjacentHTML('afterbegin', text);
downloadBoxEle.style.display = 'block';
}
function showLoader(value) {
const loaderEle = document.querySelector('.vid-loader');
if (value) {
loaderEle.style.display = 'block';
} else {
loaderEle.style.display = 'none';
}
}
document.querySelector('form').addEventListener('submit', getDownloadLink);
function getDownloadLink(event) {
event.preventDefault();
// show loader
showLoader(true);
const inputValue = document.querySelector('#vid-input').value;
if (inputValue && validURL(inputValue)) {
// make request
fetch('/api/content?url='+inputValue)
.then(res => {
showLoader(false);
if (! res.ok) {
const error = res.json();
error.then(res => alert('Error: ' + res.message))
} else {
return res.json();
}
})
.then(res => {
console.log('API Res: ', res);
if (res && res.data) {
const {poster, src} = res.data;
showDownloadBox(poster, src);
}
})
.catch(err => {
showLoader(false);
console.error('Got Error from API: ', err);
alert('Error: ' + JSON.stringify(err));
})
} else {
showLoader(false);
const errmssg = `input not valid URL: ${inputValue}`;
console.error('input not valid URL: ', inputValue);
alert(errmssg);
}
}
})()
</script>
</body>
</html>