Google Search Maps Fix

Bring Google maps button back

当前为 2024-03-06 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Google Search Maps Fix
// @namespace    http://tampermonkey.net/
// @version      2024-03-06
// @description  Bring Google maps button back
// @author       Daan Grashoff / Delivator
// @match        https://www.google.*/search
// @icon         https://www.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    function addMapsLink() {
        // Find the existing results tabs (Images, News, etc.)
        const tabsContainer = document.querySelector('.IUOThf');
        const mapImage = document.querySelector('#lu_map');

        // 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 = `${window.location.origin}/maps?q=${searchQuery}`;

        // If map image exists
        if (mapImage) {
            const anchorElement = document.createElement('a');
            anchorElement.href = mapsLink;
            mapImage.parentNode.insertBefore(anchorElement, mapImage);
            anchorElement.appendChild(mapImage);
        }

        // 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);
            mapsButton.href = mapsLink;

            // Insert the Maps button at the beginning of the tabs container
            tabsContainer.prepend(mapsButton);
        }

    }

    // Call the function to add the button
    addMapsLink();

})();