-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinjected.js
More file actions
167 lines (150 loc) · 6.08 KB
/
Copy pathinjected.js
File metadata and controls
167 lines (150 loc) · 6.08 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
159
160
161
162
163
164
165
166
167
(function() {
const originalFetch = window.fetch;
const originalXHR = window.XMLHttpRequest;
let mapInstance = null;
let markers = [];
function sendLog(type, message) {
window.postMessage({ source: "GEOCOACH", type: "LOG", payload: { type, message } }, "*");
}
function sendToExtension(type, payload) {
window.postMessage({ source: "GEOCOACH", type, payload }, "*");
}
// Generic recursive finder for [null, null, lat, lng] pattern
function findCoords(obj, found = []) {
if (!obj || typeof obj !== 'object') return found;
if (Array.isArray(obj)) {
// Check for [null, null, lat, lng]
if (obj.length >= 4 && obj[0] === null && obj[1] === null &&
typeof obj[2] === 'number' && typeof obj[3] === 'number') {
// Sanity check coordinates
if (Math.abs(obj[2]) <= 90 && Math.abs(obj[3]) <= 180) {
// Check if not already found to avoid dups in this pass
const exists = found.some(c => c.lat === obj[2] && c.lng === obj[3]);
if (!exists) {
found.push({ lat: obj[2], lng: obj[3] });
}
}
}
for (let item of obj) {
findCoords(item, found);
}
} else {
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
findCoords(obj[key], found);
}
}
}
return found;
}
function processResponse(url, text) {
if (url.includes("GetMetadata") || url.includes("GetViewportInfo")) {
// sendLog("INFO", "Analyzing: " + url);
try {
// Clean prefix if exists
let jsonText = text;
if (text.startsWith(")]}'")) {
jsonText = text.substring(4);
}
const data = JSON.parse(jsonText);
const coords = findCoords(data);
if (coords.length > 0) {
sendLog("SUCCESS", `Found ${coords.length} coordinates in ${url}`);
sendToExtension("LOCATIONS_FOUND", coords);
}
} catch (e) {
// sendLog("ERROR", "Parse error: " + e.message);
}
}
}
// Hook Fetch
window.fetch = async function(...args) {
const response = await originalFetch.apply(this, args);
try {
const url = args[0] ? args[0].toString() : "";
const options = args[1] || {};
const method = options.method ? options.method.toUpperCase() : "GET";
// Detect guess submission (end of round/guess)
if (url.includes("/guesses") && method === "POST") {
sendLog("INFO", "Guess detected. Clearing coordinates.");
sendToExtension("CLEAR_LOCATIONS", null);
}
if (url.includes("google") && (url.includes("GetMetadata") || url.includes("GetViewportInfo"))) {
const clone = response.clone();
clone.text().then(text => processResponse(url, text));
}
} catch (e) {
console.error(e);
}
return response;
};
// Hook XHR
const originalOpen = originalXHR.prototype.open;
originalXHR.prototype.open = function(method, url) {
this._url = url;
originalOpen.apply(this, arguments);
};
const originalSend = originalXHR.prototype.send;
originalXHR.prototype.send = function(body) {
this.addEventListener('load', function() {
if (this._url && (this._url.includes("GetMetadata") || this._url.includes("GetViewportInfo"))) {
processResponse(this._url, this.responseText);
}
});
originalSend.apply(this, arguments);
};
// Hook Google Maps
function hookMap() {
if (window.google && window.google.maps && window.google.maps.Map) {
const originalMap = window.google.maps.Map;
// Avoid double hooking
if (originalMap._hooked) return;
window.google.maps.Map = function(...args) {
const map = new originalMap(...args);
mapInstance = map;
sendLog("INFO", "Map instance captured!");
return map;
};
window.google.maps.Map.prototype = originalMap.prototype;
// Copy statics
for (let key in originalMap) {
if (originalMap.hasOwnProperty(key)) {
window.google.maps.Map[key] = originalMap[key];
}
}
window.google.maps.Map._hooked = true;
} else {
setTimeout(hookMap, 500);
}
}
hookMap();
// Listen for commands
window.addEventListener("message", (event) => {
if (event.data && event.data.target === "INJECTED") {
if (event.data.type === "SHOW_PINS") {
const locations = event.data.payload;
if (mapInstance && window.google && window.google.maps) {
// Clear existing
markers.forEach(m => m.setMap(null));
markers = [];
locations.forEach(loc => {
const marker = new window.google.maps.Marker({
position: { lat: loc.lat, lng: loc.lng },
map: mapInstance,
title: "Ground Truth",
icon: {
path: window.google.maps.SymbolPath.CIRCLE,
scale: 6,
fillColor: '#FF0000',
fillOpacity: 0.8,
strokeWeight: 1,
strokeColor: '#FFFFFF'
}
});
markers.push(marker);
});
}
}
}
});
})();