-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (46 loc) · 1.48 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
let btn = document.querySelector(".record-btn");
window.onload = () => {
if (localStorage.getItem("theme") === 'light-theme') {
themeToggle();
}
}
btn.addEventListener("click", async function () {
let stream = await navigator.mediaDevices.getDisplayMedia({
video: true,
audio: true,
})
//needed for better browser support
const mime = MediaRecorder.isTypeSupported("video/webm; codecs=vp9")
? "video/webm; codecs=vp9"
: "video/webm"
let mediaRecorder = new MediaRecorder(stream, {
mimeType: mime
})
let chunks = []
mediaRecorder.addEventListener('dataavailable', function(e) {
chunks.push(e.data)
})
mediaRecorder.addEventListener('stop', function(){
let blob = new Blob(chunks, {
type: chunks[0].type
})
let url = URL.createObjectURL(blob);
console.log(url)
let video = document.querySelector("video")
video.classList.remove("hidden");
video.src = url
let a = document.createElement('a')
a.href = url
a.download = `screenwiz-recording-${Date.now()}.mp4`;
a.click()
})
//we have to start the recorder manually
mediaRecorder.start()
})
function themeToggle() {
// Toggle the theme class on the root element
const rootElement = document.body; // Get the root HTML element
rootElement.classList.toggle("dark-theme");
rootElement.classList.toggle("light-theme");
localStorage.setItem("theme", rootElement.className);
}