-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplete.js
56 lines (52 loc) · 1.97 KB
/
complete.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
document.addEventListener('DOMContentLoaded', () => {
const encodeProgress = document.getElementById('encodeProgress');
const saveButton = document.getElementById('saveCapture');
const closeButton = document.getElementById('close');
const review = document.getElementById('review');
const status = document.getElementById('status');
let format;
let audioURL;
let encoding = false;
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if(request.type === "createTab") {
format = request.format;
let startID = request.startID;
status.innerHTML = "Please wait..."
closeButton.onclick = () => {
chrome.runtime.sendMessage({cancelEncodeID: startID});
chrome.tabs.getCurrent((tab) => {
chrome.tabs.remove(tab.id);
});
}
//if the encoding completed before the page has loaded
if(request.audioURL) {
encodeProgress.style.width = '100%';
status.innerHTML = "File is ready!"
generateSave(request.audioURL);
} else {
encoding = true;
}
}
//when encoding completes
if(request.type === "encodingComplete" && encoding) {
encoding = false;
status.innerHTML = "File is ready!";
encodeProgress.style.width = '100%';
generateSave(request.audioURL);
}
//updates encoding process bar upon messages
if(request.type === "encodingProgress" && encoding) {
encodeProgress.style.width = `${request.progress * 100}%`;
}
function generateSave(url) { //creates the save button
const currentDate = new Date(Date.now()).toDateString();
saveButton.onclick = () => {
chrome.downloads.download({url: url, filename: `${currentDate}.${format}`, saveAs: true});
};
saveButton.style.display = "inline-block";
}
});
review.onclick = () => {
chrome.tabs.create({url: "https://chrome.google.com/webstore/detail/chrome-audio-capture/kfokdmfpdnokpmpbjhjbcabgligoelgp/reviews"});
}
})