-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
95 lines (79 loc) · 2.49 KB
/
main.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
window.onload = () => {
// TODO: replace with https://github.com/eligrey/FileSaver.js
const saveFile = (function () {
const a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (data, fileName) {
const url = window.URL.createObjectURL(data);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
};
})();
const data = (() => {
const d = {
head: [["Year", "Make", "Model", "Description", "Price"]],
body: [
["1997", "Ford", "E350", "ac, abs, moon", "3000.00"],
["1999", "Chevyr", "Venture", "Extended Edition", "4900.00"],
["1999", "Chevy,Venture", "Extended Edition, Very Large", "5000.00"],
["1996", "Jeep", "Grand Cherokee", "moon roof, loaded", "4799.00"],
],
};
for (i = 0; i < 100000; i++) {
d.body.push(["1997", "Ford", "E350", "ac, abs, moon", "3000.00"]);
}
return d;
})();
const nonBlockingPDFDownload = () => {
var worker;
if (typeof Worker !== "undefined") {
if (typeof worker == "undefined") {
worker = new Worker("worker.js");
}
// send data to the worker
worker.postMessage(data);
worker.onmessage = function (event) {
const blob = event.data;
saveFile(blob, "mypdf.pdf");
worker.terminate(); // Terminates the worker.
};
} else {
console.log("Sorry, your browser does not support Web Workers...");
}
};
function blockingPDFdonwload() {
const doc = new self.jspdf.jsPDF();
doc.autoTable(data);
doc.save("blocking");
}
///////////////////////
//// btn listeners ////
//////////////////////
document
.getElementById("blockingDownload")
.addEventListener("click", blockingPDFdonwload);
document
.getElementById("nonBlockingDownload")
.addEventListener("click", nonBlockingPDFDownload);
///////////////
//// clock ////
//////////////
const showClock = () => {
var date = new Date();
var h = date.getHours(); // 0 - 23
var m = date.getMinutes(); // 0 - 59
var s = date.getSeconds(); // 0 - 59
var milli = date.getMilliseconds(); // 0 - 999
h = h < 10 ? "0" + h : h;
m = m < 10 ? "0" + m : m;
s = s < 10 ? "0" + s : s;
var time = h + ":" + m + ":" + s + ":" + milli;
document.getElementById("clock").innerText = time;
document.getElementById("clock").textContent = time;
setTimeout(showClock, 100);
};
showClock();
};