Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save meGAmeS1/720a581fc61757142686e380cd9c8415 to your computer and use it in GitHub Desktop.
Save meGAmeS1/720a581fc61757142686e380cd9c8415 to your computer and use it in GitHub Desktop.
Bring back the google maps button when searching on google
// ==UserScript==
// @name Google Search Maps Fix
// @namespace http://tampermonkey.net/
// @version 2024-06-19
// @description Bring Google maps button back
// @author Daan Grashoff / Delivator / meGAmeS1
// @match https://www.google.com/search*
// @match https://www.google.fr/search*
// @include https://www.google.tld/search*
// @grant none
// @icon https://www.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png
// ==/UserScript==
(function () {
'use strict';
function addMapsLink() {
// Find the existing results tabs (Images, News, etc.)
const linksContainer = document.querySelector('.crJ18e');
const tabsContainer = document.querySelector('.IUOThf');
const mapImage = document.querySelector('#lu_map');
// 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 links exist, proceed
if (linksContainer) {
// Create the Maps button
const mapsButtonL = document.createElement('a');
mapsButtonL.classList.add('nPDzT', 'T3FoJb'); // Style to match other tabs
// Create the inner elements for the Maps button
const mapDivL = document.createElement('div');
mapDivL.jsname = 'bVqjv';
mapDivL.classList.add('YmvwI'); //GKS7s
const mapSpanL = document.createElement('span');
mapSpanL.classList.add('FMKtTb', 'UqcIvb');
mapSpanL.jsname = 'pIvPIe';
mapSpanL.textContent = 'Maps';
// Assemble the elements
// mapDivL.appendChild(mapSpanL);
// mapsButtonL.appendChild(mapDivL);
mapsButtonL.href = mapsLink;
// Insert the Maps button at the beginning of the tabs container
linksContainer.insertBefore(mapsButtonL,linksContainer.children[linksContainer.children.length - 1]);
}
// If tabs exist, proceed
if (tabsContainer) {
// Create the Maps button
const mapsButtonT = document.createElement('a');
mapsButtonT.classList.add('nPDzT', 'T3FoJb'); // Style to match other tabs
// Create the inner elements for the Maps button
const mapDivT = document.createElement('div');
mapDivT.jsname = 'bVqjv';
mapDivT.classList.add('GKS7s');
const mapSpanT = document.createElement('span');
mapSpanT.classList.add('FMKtTb', 'UqcIvb');
mapSpanT.jsname = 'pIvPIe';
mapSpanT.textContent = 'Maps';
// Assemble the elements
// mapDivT.appendChild(mapSpanT);
// mapsButtonT.appendChild(mapDivT);
mapsButtonT.href = mapsLink;
// Insert the Maps button at the beginning of the tabs container
tabsContainer.insertBefore(mapsListItem,tabsContainer.children[tabsContainer.children.length - 1]);
}
}
// 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