Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save healla/b32a82181998d7e61730c3f3fb287faf to your computer and use it in GitHub Desktop.
Save healla/b32a82181998d7e61730c3f3fb287faf to your computer and use it in GitHub Desktop.
Bring back the google maps button and make map image clickable when searching on google
// ==UserScript==
// @name Google Search Maps Fix
// @namespace http://tampermonkey.net/
// @version 2024-03-14
// @description Bring Google maps button back
// @author Daan Grashoff / 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() {
// Find the existing results tabs (Images, News, etc.)
const tabsContainer = document.querySelector('.IUOThf');
const mapImage = document.querySelector('#lu_map');
const mapImage2 = document.querySelector('.Lx2b0d');
// 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}`;
// If map image exists
if (mapImage) {
const anchorElement = document.createElement('a');
anchorElement.href = mapsLink;
mapImage.parentNode.insertBefore(anchorElement, mapImage);
anchorElement.appendChild(mapImage);
}
// If map image exists
if (mapImage2) {
const anchorElement = document.createElement('a');
anchorElement.href = mapsLink;
mapImage2.parentNode.insertBefore(anchorElement, mapImage2);
anchorElement.appendChild(mapImage2);
}
// If tabs exist, proceed
if (tabsContainer) {
// Create the Maps button
const mapsButton = document.createElement('a');
mapsButton.classList.add('nPDzT', 'T3FoJb'); // Style to match other tabs
// Create the inner elements for the Maps button
const mapDiv = document.createElement('div');
mapDiv.jsname = 'bVqjv';
mapDiv.classList.add('GKS7s');
const mapSpan = document.createElement('span');
mapSpan.classList.add('FMKtTb', 'UqcIvb');
mapSpan.jsname = 'pIvPIe';
mapSpan.textContent = 'Maps';
// Assemble the elements
mapDiv.appendChild(mapSpan);
mapsButton.appendChild(mapDiv);
mapsButton.href = mapsLink;
// Insert the Maps button at the beginning of the tabs container
tabsContainer.prepend(mapsButton);
}
}
// Call the function to add the button
addMapsLink();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment