Compare commits

...

1 Commits

Author SHA1 Message Date
84cdb84c1b MAPG-123 [WIP] use MutationObserver 2020-06-14 22:05:41 +02:00

View File

@ -336,7 +336,10 @@
}, },
rewriteGoogleLink: function () { rewriteGoogleLink: function () {
if (!Game.googleLink) { if (Game.googleLink) {
return;
}
var anchors = document.getElementById('panorama').getElementsByTagName('a'); var anchors = document.getElementById('panorama').getElementsByTagName('a');
for (var i = 0; i < anchors.length; i++) { for (var i = 0; i < anchors.length; i++) {
var a = anchors[i]; var a = anchors[i];
@ -345,14 +348,22 @@
break; break;
} }
} }
if (!Game.googleLink) {
return;
} }
setTimeout(function () { var observer = new MutationObserver(function(mutationsList, observer) {
if (Game.googleLink) { for (let mutation of mutationsList) {
if (mutation.attributeName === 'href' && Game.googleLink.href !== 'https://maps.google.com/maps') {
console.log(Game.googleLink.href + ' is changed.')
Game.googleLink.title = 'Google Maps'; Game.googleLink.title = 'Google Maps';
Game.googleLink.href = 'https://maps.google.com/maps'; Game.googleLink.href = 'https://maps.google.com/maps';
} }
}, 1); }
});
observer.observe(Game.googleLink, { attributes: true });
} }
}; };
@ -425,10 +436,6 @@
Game.rewriteGoogleLink(); Game.rewriteGoogleLink();
}); });
Game.panorama.addListener('pov_changed', function () {
Game.rewriteGoogleLink();
});
Game.initialize(); Game.initialize();
document.getElementById('showGuessButton').onclick = function () { document.getElementById('showGuessButton').onclick = function () {