-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
65 lines (60 loc) · 1.78 KB
/
app.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
let isRecording = false;
let mediaRecorder;
let recordBtn = document.querySelector(".record-btn");
let stopBtn = document.querySelector(".stop-btn");
let saveBtn = document.querySelector(".save-btn");
let video = document.querySelector("video");
recordBtn.addEventListener("click", async () => {
let stream = await navigator.mediaDevices.getDisplayMedia({
video: true,
audio: true,
});
const mime = MediaRecorder.isTypeSupported("video/webm; codecs=h264")
? "video/webm; codecs=h264"
: "video/webm";
mediaRecorder = new MediaRecorder(stream, {
mimeType: mime,
});
let chunks = [];
mediaRecorder.addEventListener("dataavailable", (e) => {
chunks.push(e.data);
});
mediaRecorder.addEventListener("stop", () => {
isRecording = false;
mediaRecorder.stream.getTracks().forEach((track) => track.stop());
let blob = new Blob(chunks, {
type: chunks[0].type,
});
let url = URL.createObjectURL(blob);
video.src = url;
video.controls = true;
video.autoplay = true;
video.style.display = "block";
});
mediaRecorder.start();
isRecording = true;
recordBtn.classList.add("dispn");
stopBtn.classList.remove("dispn");
saveBtn.classList.add("dispn");
});
stopBtn.addEventListener("click", () => {
mediaRecorder.stop();
stopBtn.classList.add("dispn");
saveBtn.classList.remove("dispn");
});
saveBtn.addEventListener("click", () => {
let a = document.createElement("a");
a.href = document.querySelector("video").src;
a.download = `screen-recording-${new Date().getTime()}.webm`;
video.style.display = "none";
recordBtn.classList.remove("dispn");
stopBtn.classList.add("dispn");
saveBtn.classList.add("dispn");
a.click();
});
let a = new Date();
if (a.getHours() >= 20 || a.getHours() <= 7) {
document.body.dataset.theme = "dark";
} else {
document.body.dataset.theme = "light";
}