-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsafecast-popup-fix.js
More file actions
89 lines (78 loc) · 3.76 KB
/
Copy pathsafecast-popup-fix.js
File metadata and controls
89 lines (78 loc) · 3.76 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
/**
* Safecast Popup Fix
* This script patches the rt_viewer.js functionality to correctly display
* device names and radiation values in the popup.
*/
(function() {
// Wait for the page to load
window.addEventListener('load', function() {
console.log('Safecast Popup Fix loaded');
// Check if RTMKS exists
if (typeof RTMKS === 'undefined') {
console.error('RTMKS not found, cannot apply popup fix');
return;
}
// Store the original GetInfoWindowHtmlForParams function
const originalGetInfoWindowHtmlForParams = RTMKS.GetInfoWindowHtmlForParams;
// Override the GetInfoWindowHtmlForParams function
RTMKS.GetInfoWindowHtmlForParams = function(
locations, ids, device_urns, device_classes,
values, unixSSs, imgs, loc,
mini, tblw, fontCssClass, showGraph, showID
) {
console.log('Patched GetInfoWindowHtmlForParams called');
// Log the inputs for debugging
console.log('Popup inputs:', {
locations: locations,
ids: ids,
device_urns: device_urns,
device_classes: device_classes,
values: values,
imgs: imgs
});
// Create a better display location
let displayLocation = '';
// Try to parse device info from imgs
try {
const deviceInfo = imgs[0] ? JSON.parse(imgs[0]) : null;
console.log('Parsed device info:', deviceInfo);
if (deviceInfo && deviceInfo.location) {
displayLocation = deviceInfo.location;
console.log('Using location from deviceInfo:', displayLocation);
}
} catch (e) {
console.error('Error parsing device info:', e);
}
// If we couldn't get a location from the device info, try other methods
if (!displayLocation) {
if (device_classes[0] && device_urns[0]) {
const deviceNumber = device_urns[0].split(':')[1] || '';
displayLocation = device_classes[0] + (deviceNumber ? (' ' + deviceNumber) : '');
console.log('Created display location from device_class and device_urn:', displayLocation);
} else if (locations[0] && locations[0] !== 'Unknown') {
displayLocation = locations[0];
console.log('Using location from locations array:', displayLocation);
} else if (device_classes[0]) {
displayLocation = device_classes[0];
console.log('Using device_class as location:', displayLocation);
} else {
// Force a better name if we're still showing "Device 10030"
if (ids[0] === 10030) {
displayLocation = 'Geigiecast Device';
console.log('Forcing better name for Device 10030');
} else {
displayLocation = ids[0] ? 'Device ' + ids[0] : 'Unknown Device';
console.log('Using fallback device ID as location:', displayLocation);
}
}
}
// Call the original function
return originalGetInfoWindowHtmlForParams(
[displayLocation], ids, device_urns, device_classes,
values, unixSSs, imgs, displayLocation,
mini, tblw, fontCssClass, showGraph, showID
);
};
console.log('Safecast Popup Fix applied successfully');
});
})();