Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chhaugen/078541c93d26d722055de35251e4f308 to your computer and use it in GitHub Desktop.
Save chhaugen/078541c93d26d722055de35251e4f308 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-03-21
// @description Bring google maps button back
// @author You
// @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 addMapsButton() {
// Find the list container of existing tabs
const tabsContainer = document.querySelector('.crJ18e');
// If tabs exist, proceed
if (tabsContainer) {
// Create the Maps button elements (updated)
const mapsListItem = document.createElement('div');
mapsListItem.jsname = 'VIftV';
// mapsListItem.classList.add('Ap1Qsc');
mapsListItem.setAttribute('role', 'listitem');
// Replace this entire section with the provided <a> element
const mapsButton = document.createElement('a');
mapsButton.jsname = "ONH4Gc";
mapsButton.classList.add("LatpMc");
mapsButton.classList.add("nPDzT");
mapsButton.classList.add("T3FoJb");
mapsButton.dataset.navigation = "server"; // Update the attribute name
mapsButton.dataset.hveid = "CAEQCA";
// 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 = `//maps.google.com/maps?q=${searchQuery}`;
mapsButton.href = mapsLink;
//mapsButton.textContent = "Maps"; // Set the inner text
const mapsButtonText = document.createElement('div');
mapsButtonText.jsname = "bVqjv";
mapsButtonText.classList.add("YmvwI");
if (["nb-NO", "nn-NO", "nb", "nn"].includes(navigator.language)) {
mapsButtonText.textContent = "Kart";
}
else {
mapsButtonText.textContent = "Maps";
}
mapsButton.appendChild(mapsButtonText);
// Append the mapsButton to the list item
mapsListItem.appendChild(mapsButton);
// Insert the Maps button at the beginning of the tabs container
tabsContainer.insertBefore(mapsListItem,tabsContainer.children[2]);
}
}
// 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