Skip to content

Instantly share code, notes, and snippets.

@danielchc
Created August 14, 2024 15:12
Show Gist options
  • Save danielchc/2e2fdd5d80d2c348b8a04619fa2b710e to your computer and use it in GitHub Desktop.
Save danielchc/2e2fdd5d80d2c348b8a04619fa2b710e to your computer and use it in GitHub Desktop.
Bring back the THE BUTTON
// ==UserScript==
// @name Google Maps Button
// @namespace http://tampermonkey.net/
// @version 2024-08-14
// @description Bring Google Maps button back
// @author danielchc
// @match https://www.google.com/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 not exist, return
if (!tabsContainer) return;
// 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}`;
//Create item list
const mapsListItem = Object.assign(document.createElement('div'), {
role: 'listitem'
});
//Create Maps Button
const mapsButton = Object.assign(document.createElement('a'), {
href: mapsLink
});
mapsButton.classList.add("LatpMc", "nPDzT", "T3FoJb");
// Create text to button
const mapsButtonText = Object.assign(document.createElement('div'), {
textContent: "Maps"
});
mapsButtonText.classList.add("YmvwI");
// Append childs
mapsButton.appendChild(mapsButtonText);
mapsListItem.appendChild(mapsButton);
// Insert the Maps button
const tabList = tabsContainer.children[0];
const position = (tabList.length > 2 ? 2 : 0)
tabList.insertBefore(mapsListItem, tabList.children[position]);
}
// 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