MAPG-123 [WIP] use MutationObserver
This commit is contained in:
parent
15b5869d5a
commit
84cdb84c1b
@ -336,23 +336,34 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
rewriteGoogleLink: function () {
|
rewriteGoogleLink: function () {
|
||||||
if (!Game.googleLink) {
|
if (Game.googleLink) {
|
||||||
var anchors = document.getElementById('panorama').getElementsByTagName('a');
|
return;
|
||||||
for (var i = 0; i < anchors.length; i++) {
|
}
|
||||||
var a = anchors[i];
|
|
||||||
if (a.href.indexOf('maps.google.com/maps') !== -1) {
|
var anchors = document.getElementById('panorama').getElementsByTagName('a');
|
||||||
Game.googleLink = a;
|
for (var i = 0; i < anchors.length; i++) {
|
||||||
break;
|
var a = anchors[i];
|
||||||
}
|
if (a.href.indexOf('maps.google.com/maps') !== -1) {
|
||||||
|
Game.googleLink = a;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(function () {
|
if (!Game.googleLink) {
|
||||||
if (Game.googleLink) {
|
return;
|
||||||
Game.googleLink.title = 'Google Maps';
|
}
|
||||||
Game.googleLink.href = 'https://maps.google.com/maps';
|
|
||||||
|
var observer = new MutationObserver(function(mutationsList, observer) {
|
||||||
|
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.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 () {
|
||||||
|
Loading…
Reference in New Issue
Block a user