-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeocache-injected.js
72 lines (55 loc) · 1.56 KB
/
geocache-injected.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
Object.defineProperty(window, "L", {
configurable: true,
set(L) {
delete window.L; // Remove the property to redefine it normally
window.L = L; // Assign it back
if (L.Map) {
addFreemapLayers();
} else {
Object.defineProperty(L, "Map", {
configurable: true,
set(Map) {
delete L.Map;
L.Map = Map;
addFreemapLayers();
},
});
}
},
});
function addFreemapLayers() {
L.Map.addInitHook(function () {
const iRef = setInterval(() => {
let removed = false;
this.eachLayer((layer) => {
if (layer !== freemapLayer && layer !== ortoLayer && layer._url) {
removed = true;
this.removeLayer(layer);
}
});
if (removed) {
clearInterval(iRef);
}
}, 200);
const [freemapLayer, ortoLayer] = freemap_createLayers();
L.control
.layers({
"Freemap Outdoor": freemapLayer,
"Ortofotomozaika SR": ortoLayer,
})
.addTo(this);
freemapLayer.addTo(this);
const mapLinks = document.querySelector(
"#ctl00_ContentBody_MapLinks_MapLinks > ul"
);
const m = /lat=([\\d.]+)&lng=([\\d.]+)/.exec(
mapLinks.firstChild.firstChild.href
);
console.log(mapLinks.firstChild.firstChild.href, { m });
if (m) {
const li = document.createElement("li");
li.innerHTML = `<a target="_blank" href="https://www.freemap.sk/?map=16/\${m[1]}/\${m[2]}&point=\${m[1]}/\${m[2]}">Freemap.sk</a>`;
mapLinks.insertBefore(li, mapLinks.firstChild);
}
});
}