├── demo.html
├── README.md
└── mapsJavaScriptAPI.js
/demo.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Simple Map
5 |
6 |
7 |
20 |
21 |
22 |
23 |
32 |
34 |
35 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Usage
2 | ```html
3 |
4 | ```
5 | # Example
6 | Demo page: https://somanchiu.github.io/Keyless-Google-Maps-API/demo
7 | ```html
8 |
9 |
10 |
11 | Simple Map
12 |
13 |
14 |
27 |
28 |
29 |
30 |
39 |
41 |
42 |
43 | ```
44 | # Supporting this project
45 | [](https://www.buymeacoffee.com/somanchiu)
46 |
--------------------------------------------------------------------------------
/mapsJavaScriptAPI.js:
--------------------------------------------------------------------------------
1 | var CORSproxyURL = ['https://whateverorigin.org/get?url=', 'https://api.allorigins.win/get?url='];
2 | var CORSproxyIndex = 0;
3 |
4 | var args = '';
5 | if (typeof language != 'undefined') args += '&language=' + language;
6 |
7 | var bypass = function (googleAPIcomponentJS, googleAPIcomponentURL) {
8 | if (googleAPIcomponentURL.toString().indexOf("common.js") != -1) {
9 | var removeFailureAlert = function(googleAPIcomponentURL) {
10 | sendRequestThroughCROSproxy(googleAPIcomponentURL,(responseText)=>{
11 | var anotherAppendChildToHeadJSRegex = /\.head;.*src=(.*?);/;
12 | var anotherAppendChildToHeadJS = responseText.match(anotherAppendChildToHeadJSRegex);
13 | var googleAPItrustedScriptURL = anotherAppendChildToHeadJS[1];
14 | var bypassQuotaServicePayload = anotherAppendChildToHeadJS[0].replace(googleAPItrustedScriptURL, googleAPItrustedScriptURL+'.toString().indexOf("QuotaService.RecordEvent")!=-1?"":'+googleAPItrustedScriptURL);
15 |
16 | var script = document.createElement('script');
17 | script.innerHTML = responseText.replace(new RegExp(/;if\(![a-z]+?\).*Failure.*?\}/), ";").replace(new RegExp(/(\|\|\(\(\)=>\{\}\);\S+\?\S+?\()/), "$1true||").replace(anotherAppendChildToHeadJSRegex, bypassQuotaServicePayload);
18 | document.head.appendChild(script);
19 | });
20 | }
21 | googleAPIcomponentJS.innerHTML = '(' + removeFailureAlert.toString() + ')("' + googleAPIcomponentURL.toString() + '")';
22 | } else if(googleAPIcomponentURL.toString().indexOf("map.js") != -1){
23 | var hijackMapJS = function(googleAPIcomponentURL) {
24 | sendRequestThroughCROSproxy(googleAPIcomponentURL,(responseText)=>{
25 | var script = document.createElement('script');
26 | script.innerHTML = responseText.replace(new RegExp(/if\(\w+!==1&&\w+!==2\)/), "if(false)");
27 | document.head.appendChild(script);
28 | });
29 | }
30 | googleAPIcomponentJS.innerHTML = '(' + hijackMapJS.toString() + ')("' + googleAPIcomponentURL.toString() + '")';
31 | } else {
32 | googleAPIcomponentJS.src = googleAPIcomponentURL;
33 | }
34 | }
35 |
36 | var createAndExecutePayload = function (googleAPIjs){
37 | var script = document.createElement('script');
38 | var appendChildToHeadJS = googleAPIjs.match(/(\w+)\.src=(_.*?);/);
39 | var googleAPIcomponentJS = appendChildToHeadJS[1];
40 | var googleAPIcomponentURL = appendChildToHeadJS[2];
41 | script.innerHTML = googleAPIjs.replace(appendChildToHeadJS[0], '(' + bypass.toString() + ')(' + googleAPIcomponentJS + ', ' + googleAPIcomponentURL + ');');
42 | document.head.appendChild(script);
43 | }
44 |
45 | sendRequestThroughCROSproxy('https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap' + args, (googleAPIjs)=>{
46 | createAndExecutePayload(googleAPIjs);
47 | });
48 |
49 | function sendRequestThroughCROSproxy(url, callback){
50 | var xhttp = new XMLHttpRequest();
51 | xhttp.onreadystatechange = function() {
52 | if (this.readyState == 4) {
53 | if(this.status == 200){
54 | if(callback) callback(JSON.parse(this.responseText).contents);
55 | }else{
56 | CORSproxyIndex++;
57 | sendRequestThroughCROSproxy(url, callback);//retry
58 | }
59 | }
60 | };
61 | xhttp.open("GET", CORSproxyURL[CORSproxyIndex%CORSproxyURL.length] + encodeURIComponent(url), true);
62 | xhttp.send();
63 | }
64 |
--------------------------------------------------------------------------------