Skip to content

Instantly share code, notes, and snippets.

@Delivator
Forked from Daan-Grashoff/google_search_maps_addon.js
Last active June 21, 2024 15:24
Show Gist options
  • Save Delivator/cbb71fc770b11b02b4269f26d65ce145 to your computer and use it in GitHub Desktop.
Save Delivator/cbb71fc770b11b02b4269f26d65ce145 to your computer and use it in GitHub Desktop.
Bring back the google maps button and make map image clickable when searching on google

Google Search Maps Fix

Bring back the "Maps" button and make some map tiles clickable again.

How to install

  1. Install a userscript addon like Violentmonkey
  2. Click HERE to install the user script
// ==UserScript==
// @name Google Search Maps Fix
// @namespace http://tampermonkey.net/
// @version 2024-06-05
// @description Bring Google maps button back (originally based off of Daan Grashoff's script)
// @author Delivator
// @match https://www.google.com/search*
// @include https://www.google.tld/search*
// @icon https://www.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png
// @grant none
// ==/UserScript==
(function() {
'use strict';
function addMapsLink() {
// Get the search query from the URL
const searchQuery = new URLSearchParams(window.location.search).get('q');
// Construct the Maps link with the query
const mapsLink = `${window.location.origin}/maps?q=${searchQuery}`;
// Select the menu container and map
const menuContainer = document.querySelector('.crJ18e > div[role="list"]');
const mapImage = document.querySelector('#lu_map, #dimg_95');
if (menuContainer) {
// Create a new list item div
const listItem = document.createElement('div');
listItem.setAttribute('role', 'listitem');
// Create the link element
const link = document.createElement('a');
link.href = mapsLink;
link.className = 'nPDzT T3FoJb';
link.setAttribute('jsname', 'VIftV');
link.setAttribute('role', 'link');
// Create the inner text div
const innerTextDiv = document.createElement('div');
innerTextDiv.setAttribute('jsname', 'bVqjv');
innerTextDiv.className = 'YmvwI';
innerTextDiv.textContent = 'Maps';
// Append the inner text div to the link
link.appendChild(innerTextDiv);
// Append the link to the list item
listItem.appendChild(link);
// Insert the new list item as the second-to-last element
if (menuContainer.children.length > 1) {
menuContainer.insertBefore(listItem, menuContainer.children[menuContainer.children.length - 1]);
} else {
menuContainer.appendChild(listItem);
}
}
if (mapImage) {
// Create a new anchor element for map element
const anchorElement = document.createElement('a');
anchorElement.href = mapsLink;
mapImage.parentNode.insertBefore(anchorElement, mapImage);
anchorElement.appendChild(mapImage);
}
}
// Run the function to add the Maps link when the page loads
window.addEventListener('load', addMapsLink);
})();
@Delivator
Copy link
Author

hi @Xornop , can you tell me what exactly is broken? For me it still works that the "Maps" tab is added but clicking on the map sometimes doesnt work.

@Xornop
Copy link

Xornop commented Jun 21, 2024

@Delivator yeah same for me, thats my issue. I dont use the maps tab, just in cases where it doesnt give me a minimap when i think it should have

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment