-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelectingCoordinates.js
74 lines (62 loc) · 2.42 KB
/
SelectingCoordinates.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
66
67
68
69
70
71
72
73
74
class ClickRecorder {
constructor() {
this.clicks = [];
this.createUI();
this.addClickListener();
}
createUI() {
const container = document.createElement("div");
container.style.position = "fixed";
container.style.top = "10px";
container.style.right = "10px";
container.style.backgroundColor = "rgba(255, 255, 255, 0.9)";
container.style.border = "1px solid #ccc";
container.style.borderRadius = "5px";
container.style.padding = "10px";
container.style.zIndex = "9999";
container.style.width = "250px";
container.style.boxShadow = "0 4px 8px rgba(0, 0, 0, 0.1)";
container.style.overflowY = "auto";
container.style.maxHeight = "300px";
const title = document.createElement("h3");
title.textContent = "Click Recorder";
title.style.margin = "0 0 10px 0";
title.style.fontSize = "16px";
this.list = document.createElement("ul");
this.list.style.listStyleType = "none";
this.list.style.padding = "0";
this.list.style.margin = "0";
const clearButton = document.createElement("button");
clearButton.textContent = "Clear";
clearButton.style.padding = "8px";
clearButton.style.backgroundColor = "#f44336";
clearButton.style.color = "white";
clearButton.style.border = "none";
clearButton.style.borderRadius = "5px";
clearButton.style.cursor = "pointer";
clearButton.style.marginTop = "10px";
clearButton.addEventListener("click", () => this.clearClicks());
container.appendChild(title);
container.appendChild(this.list);
container.appendChild(clearButton);
document.body.appendChild(container);
}
addClickListener() {
document.addEventListener("click", (event) => this.recordClick(event));
}
recordClick(event) {
const x = event.clientX;
const y = event.clientY;
this.clicks.push({ x, y });
const listItem = document.createElement("li");
listItem.textContent = `Click ${this.clicks.length}: (${x}, ${y})`;
listItem.style.padding = "5px 0";
this.list.appendChild(listItem);
console.log(`Click ${this.clicks.length}: (${x}, ${y})`);
}
clearClicks() {
this.clicks = [];
this.list.innerHTML = "";
}
}
const clickRecorder = new ClickRecorder();