Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
70 lines (63 loc) · 2.03 KB
/
Copy pathapp.js
File metadata and controls
70 lines (63 loc) · 2.03 KB
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
document.getElementById("link").addEventListener("keyup", function(event) {
if (event.key === 'Enter') {
event.preventDefault();
document.getElementById("but").click();
}
});
function validate() {
var url = document.getElementById('link').value;
if (!url.startsWith('http') && url.includes('giphy.com')) {
url = 'https://'+url
console.log('hi')
} else if (url.startsWith('http') && (url.includes('giphy.com/gifs') || url.includes('media.giphy.com')) && url.includes('://')) {
if (url.endsWith('/giphy.gif')) {
url = url.replace('/giphy.gif', '')
}
if (url.endsWith('#')) {
url = url.replace(/#/g, '')
}
}
else {
console.log('[!] - URL appears to be invalid.'.red)
url = false;
}
findGif(url)
}
function findGif(gif) {
if (gif == false) {
return
}
else {
var linkarray = gif.split('/')
if (gif.includes('-')) {
var x = linkarray[4].split('-')
linkarray[4] = x.slice(-1).toString()
}
var code = linkarray.slice(-1)
if (code.includes('/')) {
var temp = code.split('/')
code = temp[0]
}
if (code.toString().includes('\r')) {
var temp = code.toString().split('\r')
code = temp[0]
}
var mp4 = "https://media1.giphy.com/media/"+code+"/giphy.mp4"
var xhr = new XMLHttpRequest();
xhr.open('GET', mp4, true);
xhr.responseType = 'blob';
xhr.onload = function() {
var a = document.createElement('a');
a.href = window.URL.createObjectURL(this.response);;
a.target = '_blank';
a.download = code+'.mp4';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};
xhr.onerror = err => {
alert('Failed!');
};
xhr.send();
}
}