Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slackero/272cea354e0a9a385c65ef182c4aa0da to your computer and use it in GitHub Desktop.
Save slackero/272cea354e0a9a385c65ef182c4aa0da to your computer and use it in GitHub Desktop.
Bring back the google maps button when searching on google
// ==UserScript==
// @name Google maps addon
// @namespace http://tampermonkey.net/
// @version 2024-02-29
// @description Bring google maps button back
// @author You
// @match https://www.google.com/*
// @icon data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2216%22%20height%3D%2216%22%20fill%3D%22currentColor%22%20class%3D%22bi%20bi-geo-alt-fill%22%20viewBox%3D%220%200%2016%2016%22%3E%3Cpath%20d%3D%22M8%2016s6-5.686%206-10A6%206%200%200%200%202%206c0%204.314%206%2010%206%2010m0-7a3%203%200%201%201%200-6%203%203%200%200%201%200%206%22%2F%3E%3C%2Fsvg%3E
// @grant none
// ==/UserScript==
(function () {
'use strict';
function addMapsButton() {
// Find the existing results tabs (Images, News, etc.)
const tabsContainer = document.querySelector('.IUOThf');
// 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);
// 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 = `https://www.google.com/maps/search/?api=1&query=${searchQuery}`;
mapsButton.href = mapsLink;
// Insert the Maps button at the beginning of the tabs container
tabsContainer.prepend(mapsButton);
}
}
// Call the function to add the button
addMapsButton();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment