-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
60 lines (50 loc) · 1.91 KB
/
script.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
function generateUniqueKey() {
return 'windowCenter_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
}
const uniqueKey = generateUniqueKey();
function updateCenterPosition() {
const position = {
x: window.innerWidth / 2 + window.screenX,
y: window.innerHeight / 2 + window.screenY,
timestamp: Date.now() // Include a timestamp for each update
};
localStorage.setItem(uniqueKey, JSON.stringify(position));
}
setInterval(updateCenterPosition, 20);
window.onbeforeunload = () => {
localStorage.removeItem(uniqueKey);
};
function getOtherWindowsPositions() {
let positions = [];
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key.startsWith('windowCenter_') && key !== uniqueKey) {
const positionData = JSON.parse(localStorage.getItem(key));
// Check if the position data is older than 100ms
if (Date.now() - positionData.timestamp < 100) {
positions.push({ key, ...positionData });
} else {
localStorage.removeItem(key); // Remove outdated position data
}
}
}
return positions;
}
function updateArrows() {
const currentPosition = JSON.parse(localStorage.getItem(uniqueKey));
const otherPositions = getOtherWindowsPositions();
const container = document.getElementById('container');
container.innerHTML = '';
otherPositions.forEach(pos => {
const dx = pos.x - currentPosition.x;
const dy = pos.y - currentPosition.y;
const angle = Math.atan2(dy, dx) * 180 / Math.PI;
const arrow = document.createElement('img');
arrow.src = './resources/arrow.png';
arrow.className = 'arrow';
arrow.style.transform = `rotate(${angle}deg)`;
arrow.style.display = 'block';
container.appendChild(arrow);
});
}
setInterval(updateArrows, 1);