Google Search Maps Fix

Bring Google maps button back

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Google Search Maps Fix
// @namespace    http://tampermonkey.net/
// @version      2.0.1
// @description  Bring Google maps button back
// @author       Ovinomaster
// @include      https://www.google.tld/search*
// @icon         https://www.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png
// @grant        none
// @license      CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
// @homepageURL  https://greasyfork.org/it/users/1271103-ovinomaster
// ==/UserScript==
(function() {
  'use strict';

  function addMapsTab() {
    // Target the new navigation container
    const navList = document.querySelector('div.beZ0tf.O1uzAe[role="list"]');
    if (!navList) return;

    // Skip if "Maps" already exists
    if (navList.querySelector('span.R1QWuf')?.textContent === 'Maps' ||
        navList.querySelector('a[data-added-by-userscript="maps"]')) return;

    // Clone an existing tab for structure consistency
    const refItem = navList.querySelector('div[role="listitem"]');
    if (!refItem) return;

    const newItem = refItem.cloneNode(true);
    const newLink = newItem.querySelector('a.C6AK7c');
    const q = new URLSearchParams(window.location.search).get('q') || '';

    if (!newLink) return;

    // Update link
    newLink.href = `https://www.google.com/maps?q=${encodeURIComponent(q)}`;
    // newLink.target = '_blank';
    newLink.setAttribute('data-added-by-userscript', 'maps');

    // Clean up styles & attributes
    newLink.removeAttribute('aria-disabled');
    newLink.removeAttribute('aria-current');
    newLink.removeAttribute('selected');
    newLink.style.color = '';
    newLink.style.textDecoration = '';

    // Replace text
    const label = newLink.querySelector('span.R1QWuf');
    if (label) label.textContent = 'Maps';

    // Insert the new tab after the first one (usually "All")
    navList.insertBefore(newItem, navList.children[1]);
  }

  // function makeMiniMapClickable() {
    // const q = new URLSearchParams(window.location.search).get('q') || '';
    // const mapsLink = `https://www.google.com/maps?q=${encodeURIComponent(q)}`;
    // const mini = document.querySelector('.pyitY, [data-attrid*="map"]');
    // if (mini && !mini.closest('a')) {
      // const a = document.createElement('a');
      // a.href = mapsLink;
      // a.target = '_blank';
      // a.style.display = 'block';
      // a.style.textDecoration = 'none';
      // while (mini.firstChild) a.appendChild(mini.firstChild);
      // mini.appendChild(a);
    // }
  // }

  // Keep trying since Google loads this asynchronously
  const observer = new MutationObserver(() => addMapsTab());
  observer.observe(document.body, { childList: true, subtree: true });

  // Run now and periodically
  addMapsTab();
  makeMiniMapClickable();
  setInterval(addMapsTab, 3000);
})();