-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
35 lines (34 loc) · 1.2 KB
/
script.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
document.getElementById('downloadAudio').addEventListener('click', async function () {
var audioUrl = this.getAttribute('data-audiourl');
const response = await fetch(audioUrl);
const blob = await response.blob();
const blobUrl = URL.createObjectURL(blob);
var link = document.createElement('a');
link.href = blobUrl;
link.download = 'audio.mp3';
document.body.appendChild(link);
var clickEvent = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
link.dispatchEvent(clickEvent);
document.body.removeChild(link);
});
document.getElementById('downloadVideo').addEventListener('click', async function () {
var videoUrl = this.getAttribute('data-videourl');
const response = await fetch(videoUrl);
const blob = await response.blob();
const blobUrl = URL.createObjectURL(blob);
var link = document.createElement('a');
link.href = blobUrl;
link.download = 'video.mp4';
document.body.appendChild(link);
var clickEvent = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
link.dispatchEvent(clickEvent);
document.body.removeChild(link);
});