-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
111 lines (103 loc) · 2.88 KB
/
index.js
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
106
107
108
109
110
111
const url = "https://avd.vercel.app/convert"
let converting = true
const urls = [
"9gag.com",
"www.9gag.com",
"douyin.com",
"www.douyin.com",
"facebook.com",
"www.facebook.com",
"www.fb.watch",
"fb.watch",
"instagram.com",
"www.instagram.com",
"linkedin.com",
"www.linkedin.com",
"reddit.com",
"www.reddit.com",
"tiktok.com",
"www.tiktok.com",
"tumblr.com",
"www.tumblr.com",
"youtube.com",
"www.youtube.com",
"youtu.be",
"www.youtu.be",
]
window.onload = async () => {
init()
}
window.onfocus = async () => {
init()
}
async function init(){
navigator.permissions.query({name: "clipboard-read"})
await navigator.clipboard.readText().then(c => {
let data = "this is just a dummy text"
const url = /https:\/\/(.*?)\/([\w\W]+)/
if(url.test(c)){
data = c.match(url)[1]
}
if(urls.includes(data)){
document.getElementById("title").textContent = "Auto fetch data using clipboard onload"
requestDownload(c)
document.getElementById("url").value = c
}
})
}
document.getElementById("url").onchange = () => {
const urlData = document.getElementById("url").value
const url = /https:\/\/(.*?)\/([\w\W]+)/
let data = "this is just a dummy text"
if(url.test(urlData)){
data = urlData.match(url)[1]
}
if(urls.includes(data)){
document.getElementById("title").textContent = `Please Wait...`
document.getElementById("source").textContent = ``
document.getElementById("duration").textContent = ``
document.getElementById("links").innerHTML = ""
requestDownload(urlData)
}else{
document.getElementById("title").textContent = `Audio Video Downloader`
document.getElementById("source").textContent = ``
document.getElementById("duration").textContent = ``
document.getElementById("links").innerHTML = ""
}
}
function requestDownload(videoURL){
if(converting){
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
url: encodeURI(videoURL)
})
}).then(response => {
return response.json()
}).then(response => {
const lists = document.getElementById("links")
document.getElementById("title").textContent = `${response.title}`
document.getElementById("source").textContent = `Source: ${response.source}`
document.getElementById("duration").textContent = `${response.duration}`
const data = response.medias
for(let d in data){
let type = ""
if(data[d].audioAvailable) type += "music"
if(data[d].videoAvailable) type += (type == "") ? " video no audio" : " and video"
const a = document.createElement("a")
a.href = data[d].url
a.download = `${response.title}.${data[d].extension}`
a.innerHTML = `Download (${type}) ${data[d].extension}<br>(<b>${data[d].quality}</b> - ${data[d].formattedSize})`
window.URL.revokeObjectURL(data[d].url)
lists.appendChild(a)
}
converting = false
}).catch(error => {
alert(error)
converting = false
})
}
}