Skip to content
This repository was archived by the owner on Apr 16, 2025. It is now read-only.

Commit 35021ee

Browse files
committed
feat: add Google hack for maps
This allows anyone to run the live map without having to get an API key from Google (wohoo, freedom)
1 parent c020a34 commit 35021ee

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

index.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@
4949
<script src="js/jquery-3.2.1.min.js"></script>
5050

5151
<!-- Change the key below -->
52-
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBbYDZMGkewhRTGRJS4wwSVuBipYlYf-SU"></script>
52+
<script type="text/javascript" src="https://maps.google.com/maps/api/js"></script>
5353

5454
<script>
55+
5556
///////////////////////////////////////////////////////////////////////////
5657
// CONFIGURATION STARTS HERE
5758
///////////////////////////////////////////////////////////////////////////
@@ -75,11 +76,37 @@
7576
var _MAP_UVInvMap = false;
7677

7778
// Set to the IP of the GTA server running "live_map" and change the port to the
78-
// number that is in the "server.lua" file
79+
// number that is set
7980
var _SETTINGS_socketUrl = "ws://localhost:30121"
8081

81-
</script>
82+
// Do not remove unless you know what you're doing (and you have a google api key)
83+
// Hack from https://stackoverflow.com/questions/38148097/google-maps-api-without-key/38809129#38809129
84+
// hack Google Maps to bypass API v3 key (needed since 22 June 2016 http://googlegeodevelopers.blogspot.com.es/2016/06/building-for-scale-updates-to-google.html)
85+
var target = document.head;
86+
var observer = new MutationObserver(function(mutations) {
87+
for (var i = 0; mutations[i]; ++i) { // notify when script to hack is added in HTML head
88+
if (mutations[i].addedNodes[0].nodeName == "SCRIPT" && mutations[i].addedNodes[0].src.match(/\/AuthenticationService.Authenticate?/g)) {
89+
var str = mutations[i].addedNodes[0].src.match(/[?&]callback=.*[&$]/g);
90+
if (str) {
91+
if (str[0][str[0].length - 1] == '&') {
92+
str = str[0].substring(10, str[0].length - 1);
93+
} else {
94+
str = str[0].substring(10);
95+
}
96+
var split = str.split(".");
97+
var object = split[0];
98+
var method = split[1];
99+
window[object][method] = null; // remove censorship message function _xdc_._jmzdv6 (AJAX callback name "_jmzdv6" differs depending on URL)
100+
//window[object] = {}; // when we removed the complete object _xdc_, Google Maps tiles did not load when we moved the map with the mouse (no problem with OpenStreetMap)
101+
}
102+
observer.disconnect();
103+
}
104+
}
105+
});
106+
var config = { attributes: true, childList: true, characterData: true }
107+
observer.observe(target, config);
82108

109+
</script>
83110

84111
<?php
85112
printFirstJs($debug);

0 commit comments

Comments
 (0)