-
-
Save raconnay/07d547d5e9a43eb03f838cbfd429f175 to your computer and use it in GitHub Desktop.
Bring back the google maps button when searching on google
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Google maps addon | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-02-13 | |
// @description Bring google maps button back | |
// @author You | |
// @match https://www.google.com/* | |
// @icon https://www.google.com/ | |
// @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 = `http://maps.google.com/maps?q=${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