-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (43 loc) · 1.29 KB
/
Copy pathscript.js
File metadata and controls
51 lines (43 loc) · 1.29 KB
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
let screenshotInterval;
let screenshotCount = 0;
function showError(msg) {
$('#errorMessage').text(msg).removeClass('d-none');
setTimeout(() => $('#errorMessage').addClass('d-none'), 3000);
}
function captureScreenshot() {
const container = $('#screenshotContainer');
const div = $('<div class="col"></div>');
const image = $('<div></div>')
.css({
height: '150px',
backgroundColor: `hsl(${Math.random() * 360}, 70%, 60%)`,
borderRadius: '10px'
});
div.append(image);
container.prepend(div);
screenshotCount++;
}
$('#startBtn').click(() => {
if (screenshotInterval) return;
const min = parseInt($('#intervalMin').val(), 10);
const sec = parseInt($('#intervalSec').val(), 10);
const intervalMs = ((min * 60) + sec) * 1000;
if (intervalMs <= 0) {
showError('Interval must be greater than 0');
return;
}
captureScreenshot(); // immediate shot
screenshotInterval = setInterval(captureScreenshot, intervalMs);
});
$('#stopBtn').click(() => {
clearInterval(screenshotInterval);
screenshotInterval = null;
});
$('#downloadBtn').click(() => {
html2canvas(document.body).then(canvas => {
const link = document.createElement('a');
link.download = `screenshot_${Date.now()}.png`;
link.href = canvas.toDataURL();
link.click();
});
});