Skip to content

Instantly share code, notes, and snippets.

@wichaksono
Forked from pentagonal/ob-map.js
Created May 13, 2018 16:28
Show Gist options
  • Save wichaksono/0a12f983880770a398cbdb68410aac62 to your computer and use it in GitHub Desktop.
Save wichaksono/0a12f983880770a398cbdb68410aac62 to your computer and use it in GitHub Desktop.
Resolve Google Map v3 without API Key
/*
* Resolve Google Map v3 without API Key
* since june 22 2016
* Put on body and load before map render
*/
(function (window) {
if (!window.document) {
return;
}
(new MutationObserver(function (mutations) {
if (typeof mutations !== 'object') {
return;
}
try {
for (var i = 0; mutations[i]; ++i) {
if (typeof mutations[i].addedNodes === 'undefined' || typeof mutations[i].addedNodes[0] === 'undefined') {
continue;
}
var node = mutations[i].addedNodes[0];
if (typeof node !== 'object' || typeof node.nodeName !== 'string' || typeof node.src !== 'string') {
continue;
}
// notify when script to hack is added in HTML head
if (node.nodeName.toUpperCase() === "SCRIPT"
&& node.src.match(/\/AuthenticationService.Authenticate?/g)
) {
var str = mutations[i].addedNodes[0].src.match(/[?&]callback=.*[&$]/g);
if (str) {
str = (str[0][str[0].length - 1] === '&')
? str[0].substring(10, str[0].length - 1)
: str[0].substring(10);
var split = str.split(".");
window[split[0]][split[1]] = null;
}
this.disconnect();
}
}
} catch (e) {
// pass error
}
})).observe(window.document.head, {
attributes: true,
childList: true,
characterData: true
});
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment