Discussions » Development

Trying to Auto switch to Google maps Satellite View Help

§
Posted: 15.06.2024

Hello, I dont know what Im doing but Im trying to change a script Ive used before to automatically switch to Satellite view in google maps.

Im unsure if I have the container chosen right. Or the syntax (ie .app-container, #app-container or just app-container)

Nor if the selection "[aria-label="widget-minimap-icon-overlay"]" is the right or best choice.

I also realized that even if I get this to work if will toggle a view change on every refresh witch is an issue and why Im asking for some help.

I can see this Div class changing to a different class when I change view: <div class="vasquette id-app-container pane-empty-mode app-imagery-mode app-globe-mode" id="app-container"

Can I specify this class so it will only work when specifying one of the classes and not in the other view?

And also The "vet"? on this button changes from 27741 to 27742 <button aria-expanded="false" aria-labelledby="widget-minimap-icon-overlay" vet="27741"

But I dont know how Id use that...

Even if you can lead me in the right direction that would be great.

Hayden.

Here is the code: document.addEventListener('DOMContentLoaded', () => { const container = document.querySelector('app-container'); // Replace with appropriate selector

const mo = new MutationObserver(() => {
    // Replace with code to find and click the satellite button or handle the desired state change
    // Example:
    const satelliteButton = container.querySelector('[aria-label="widget-minimap-icon-overlay"]');
    if (satelliteButton) {
        satelliteButton.click();
        mo.disconnect();
    }
});

mo.observe(container, { attributes: true, attributeFilter: ['style'] });
woxxomMod
§
Posted: 15.06.2024

I see that aria-label is changed to aria-labelledby after the map is loaded, so observing the old attribute won't help.

A more reliable selector might be '#minimap button[jsaction*="minimap.main"]'

§
Posted: 15.06.2024

Oh okay. I used chatGPT at some point to see if it could reference the website and convert it changed the label to that and I wasnt sure about it. Cant say I could tell minimap.main would work as a button.

I changed it over and its still doing the nothing unfortunately.

Is the syntax for the container I chose correct? just app-container ?

Appreciate the help!

document.addEventListener('DOMContentLoaded', () => { const container = document.querySelector('#app-container');

const mo = new MutationObserver(() => {
    const satelliteButton = container.querySelector('#minimap button[jsaction*="minimap.main"]');
    if (satelliteButton) {
        satelliteButton.click();
        mo.disconnect();
    }
});

mo.observe(container, { attributes: true, attributeFilter: ['style'] });

});

woxxomMod
§
Posted: 15.06.2024
Edited: 15.06.2024

This works for me:

const mo = new MutationObserver(() => {
  const el = document.querySelector('#minimap button[jsaction*="minimap.main"]');
  if (el) {
    el.click();
    mo.disconnect();
  }
});
mo.observe(document.body, {childList: true, subtree: true});

Note that this is the entire code, no need for document.addEventListener('DOMContentLoaded

§
Posted: 15.06.2024

Daamn thats simpler. Very nice!

This is fantastic and was the last step in optimizing my workflow.
Cannot thank you enough!

I spent a minute trying to get it to work ^.^'

Champion

Post reply

Sign in to post a reply.