-
Notifications
You must be signed in to change notification settings - Fork 3
/
popup.js
56 lines (45 loc) · 1.12 KB
/
popup.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
// Store images so we can remove them after they hit an upper limit
let images = [];
// Store mouse position
let mousePos = { x: -1000, y: -1000};
let lastX = -1000;
let lastY = -1000;
function spawnImage(x, y) {
if (lastX === x && lastY === y) {
return
}
lastX = x;
lastY = y;
var image = document.createElement('img');
image.setAttribute('src', './circle.png');
image.setAttribute('class', 'overlays');
image.setAttribute('width', 128);
image.setAttribute('height', 128);
image.style.left = x - 64 + 'px';
image.style.top = y - 64 + 'px';
images.push(image);
document.body.appendChild(image);
}
function repeater() {
setTimeout(function () {
spawnImage(mousePos.x, mousePos.y);
repeater();
}, 10);
}
document.addEventListener('mousemove', function(e) {
mousePos.x = e.pageX;
mousePos.y = e.pageY;
});
function removeImage() {
setTimeout(function() {
if (images.length > 1) {
images.shift().remove();
}
removeImage();
}, 20);
}
document.addEventListener('DOMContentLoaded', function(event) {
spawnImage(mousePos.x, mousePos.y);
repeater();
removeImage();
});