142 lines
4.7 KiB
HTML
142 lines
4.7 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>General Bots Desktop</title>
|
|
<script>var global = global || window;</script>
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script defer>
|
|
|
|
window.addEventListener('load', async() => {
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
console.log('HTML loaded.');
|
|
|
|
const startBtn = document.getElementById('startBtn');
|
|
const stopBtn = document.getElementById('stopBtn');
|
|
|
|
// Microphone.
|
|
|
|
navigator.mediaDevices.getUserMedia({
|
|
audio: true,
|
|
video: false
|
|
}).then(stream => {
|
|
// Now you have access to the stream
|
|
window.microphone = stream;
|
|
|
|
// Store in a global variable
|
|
window.getMicrophoneStream = () => stream;
|
|
|
|
// Expose it through a global function
|
|
window.stopMicrophone = () => {
|
|
stream.getTracks().forEach(track => track.stop());
|
|
window.microphone = null;
|
|
};
|
|
}).catch(error => {
|
|
console.error('Error accessing microphone:', error);
|
|
});
|
|
|
|
startBtn.addEventListener('click', async () => {
|
|
try {
|
|
await navigator.mediaDevices.getUserMedia({
|
|
audio: true,
|
|
video: false
|
|
}).then(stream => {
|
|
window.microphone = stream;
|
|
console.log('Microphone started');
|
|
});
|
|
} catch (error) {
|
|
console.error('Failed to start microphone:', error);
|
|
}
|
|
});
|
|
|
|
// Screenshot
|
|
|
|
function selectSource(source) {
|
|
navigator.mediaDevices.getUserMedia({
|
|
audio: false,
|
|
video: {
|
|
mandatory: {
|
|
chromeMediaSource: 'desktop',
|
|
chromeMediaSourceId: source.id
|
|
}
|
|
}
|
|
})
|
|
.then((stream) => {
|
|
window.screenStream = stream;
|
|
|
|
const video = document.getElementById('preview');
|
|
video.srcObject = stream;
|
|
})
|
|
.catch((error) => {
|
|
console.error('Error selecting source:', error);
|
|
});
|
|
}
|
|
|
|
function stopCapture() {
|
|
if (window.screenStream) {
|
|
window.screenStream.getTracks().forEach(track => track.stop());
|
|
window.screenStream = null;
|
|
|
|
const video = document.getElementById('preview');
|
|
video.srcObject = null;
|
|
|
|
document.getElementById('stopBtn').disabled = true;
|
|
document.getElementById('screenshotBtn').disabled = true;
|
|
}
|
|
}
|
|
|
|
function takeScreenshot() {
|
|
const stream = this.getStream();
|
|
if (!stream) {
|
|
throw new Error('No active screen capture');
|
|
}
|
|
|
|
const video = document.createElement('video');
|
|
video.srcObject = stream;
|
|
|
|
return new Promise((resolve, reject) => {
|
|
video.onloadedmetadata = () => {
|
|
video.play();
|
|
video.pause();
|
|
|
|
const canvas = document.createElement('canvas');
|
|
canvas.width = video.videoWidth;
|
|
canvas.height = video.videoHeight;
|
|
|
|
const context = canvas.getContext('2d');
|
|
if (!context) {
|
|
reject(new Error('Failed to get canvas context'));
|
|
return;
|
|
}
|
|
|
|
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
|
|
canvas.toBlob((blob) => {
|
|
if (blob) {
|
|
resolve(blob);
|
|
} else {
|
|
reject(new Error('Failed to convert canvas to blob'));
|
|
}
|
|
video.srcObject = null;
|
|
}, 'image/png');
|
|
};
|
|
|
|
video.onerror = () => {
|
|
reject(new Error('Failed to load video'));
|
|
};
|
|
});
|
|
}
|
|
|
|
}); // End of DOMContentLoaded listener
|
|
|
|
</script>
|
|
<div id="root"></div>
|
|
</body>
|
|
|
|
</html>
|