Last active
November 24, 2025 17:13
-
-
Save artttj/e9320e8d749ce836585c93c568417dcc to your computer and use it in GitHub Desktop.
Restore Google Maps Tab in Google Search
This file contains hidden or 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 Tab | |
| // @namespace http://tampermonkey.net/ | |
| // @version 2025-11-24 | |
| // @description Adds a missing “Maps” tab back to Google Search | |
| // @author Artyom Yagovdik <artyom.yagovdik(at)gmail.com> | |
| // @match https://www.google.com/search* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=google.com | |
| // @grant none | |
| // ==/UserScript== | |
| (() => { | |
| 'use strict'; | |
| const MAPS_URL = 'https://www.google.com/maps/?q='; | |
| const getQuery = () => { | |
| const params = new URLSearchParams(location.search); | |
| const q = params.get('q'); | |
| if (q) return q; | |
| return document.querySelector('input[name="q"]')?.value || ''; | |
| }; | |
| const getNavigation = () => { | |
| return ( | |
| document.querySelector('div[role="list"]') || | |
| document.querySelector('div[role="navigation"] div[role="list"]') | |
| ); | |
| }; | |
| const createMapsTab = (nav, query) => { | |
| if (nav.querySelector('[data-gmaps-tab="true"]')) return; | |
| const templateItem = nav.querySelector('[role="listitem"], [role="link"]'); | |
| if (!templateItem) return; | |
| const node = templateItem.cloneNode(true); | |
| const anchor = node.querySelector('a') || node; | |
| const labelSpan = node.querySelector('span') || node; | |
| labelSpan.textContent = 'Maps'; | |
| anchor.href = MAPS_URL + encodeURIComponent(query); | |
| anchor.setAttribute('data-gmaps-tab', 'true'); | |
| anchor.removeAttribute('aria-disabled'); | |
| if (nav.firstChild) { | |
| nav.firstChild.after(node); | |
| } else { | |
| nav.appendChild(node); | |
| } | |
| }; | |
| const addMapsTab = () => { | |
| const query = getQuery(); | |
| if (!query) return; | |
| const nav = getNavigation(); | |
| if (!nav) return; | |
| createMapsTab(nav, query); | |
| }; | |
| const init = () => { | |
| if (document.readyState === 'loading') { | |
| document.addEventListener('DOMContentLoaded', addMapsTab); | |
| } else { | |
| addMapsTab(); | |
| } | |
| new MutationObserver(addMapsTab).observe(document.documentElement, { | |
| subtree: true, | |
| childList: true, | |
| }); | |
| }; | |
| init(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment