Repository navigation
Expand file tree
/
Copy pathagent-map-rows.user.js
More file actions
158 lines (114 loc) · 3.96 KB
/
Copy pathagent-map-rows.user.js
File metadata and controls
158 lines (114 loc) · 3.96 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// ==UserScript==
// @name Agent Map Row Letters
// @namespace http://192.168.222.165/
// @version 2025-01-19.01
// @author You
// @description Add row letters to the agent map.
// @match http://192.168.222.165/wallboardcm10/frmAgentMap.aspx*
// @icon https://www.google.com/s2/favicons?sz=64&domain=222.165
// @grant none
// @updateURL https://github.com/ArtOfCode-/Userscripts/raw/master/agent-map-rows.user.js
// @downloadURL https://github.com/ArtOfCode-/Userscripts/raw/master/agent-map-rows.user.js
// ==/UserScript==
(function () {
'use strict';
let redrawPending = false;
let lastColumnSignature = '';
function getColumnPositions(desks) {
return [...new Set(
desks
.map(d => parseInt(getComputedStyle(d).left, 10))
.filter(v => !isNaN(v))
)].sort((a, b) => a - b);
}
function drawLetters() {
const desks = Array.from(
document.querySelectorAll('.extension_container')
);
if (!desks.length) {
return;
}
const columns = getColumnPositions(desks);
const signature = columns.join('|');
// Skip redraw if nothing changed
if (signature === lastColumnSignature) {
return;
}
lastColumnSignature = signature;
document
.querySelectorAll('.tm-column-letter')
.forEach(el => el.remove());
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
columns.forEach((left, index) => {
const desksInColumn = desks.filter(
d => parseInt(getComputedStyle(d).left, 10) === left
);
if (!desksInColumn.length) {
return;
}
const lowestDesk = desksInColumn.reduce((lowest, current) => {
const currentTop =
parseInt(getComputedStyle(current).top, 10);
const lowestTop =
parseInt(getComputedStyle(lowest).top, 10);
return currentTop > lowestTop
? current
: lowest;
});
const rect = lowestDesk.getBoundingClientRect();
const marker = document.createElement('div');
marker.className = 'tm-column-letter';
marker.textContent =
letters[index] || `C${index + 1}`;
marker.style.position = 'fixed';
marker.style.left = `${rect.left}px`;
marker.style.top = `${rect.bottom + 5}px`;
marker.style.width = `${rect.width}px`;
marker.style.textAlign = 'center';
marker.style.fontWeight = 'bold';
marker.style.fontSize = '18px';
marker.style.color = '#d00000';
marker.style.background = '#ffffff';
marker.style.zIndex = '99999';
marker.style.pointerEvents = 'none';
document.body.appendChild(marker);
});
console.log(
`Agent Map Letters: ${columns.length} columns rendered`
);
}
function scheduleDraw() {
if (redrawPending) {
return;
}
redrawPending = true;
setTimeout(() => {
redrawPending = false;
requestAnimationFrame(() => {
drawLetters();
});
}, 500);
}
function initialise() {
drawLetters();
const target =
document.querySelector('#divExtensions');
if (!target) {
console.warn(
'Agent Map Letters: #divExtensions not found'
);
return;
}
const observer = new MutationObserver(() => {
scheduleDraw();
});
observer.observe(target, {
childList: true,
subtree: true
});
console.log(
'Agent Map Letters: observer attached'
);
}
setTimeout(initialise, 1500);
})();