No Google Maps Crap

Removes google maps crap replacing it with OSM

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         No Google Maps Crap
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Removes google maps crap replacing it with OSM
// @author       Anonim
// @match        https://*.google.com/maps/*
// @match        https://maps.google.com/*
// @match        https://maps.app.goo.gl/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Display "redirecting..." message
    document.documentElement.innerHTML = '<html><body><h1>Redirecting...</h1></body></html>';

    // Redirect to OpenStreetMap
    function redirectToOSM(url) {
        setTimeout(() => {
            window.location.replace(url);
        }, 1000); // Delay to reduce bugs
    }

    // Parser
    function getQueryParams(url) {
        let params = {};
        let parser = new URL(url);
        parser.searchParams.forEach((value, key) => {
            params[key] = value;
        });
        return params;
    }

    // Check for Crap Maps with coordinates in the query string
    if (window.location.href.includes("maps.google.com") || window.location.href.includes("maps.app.goo.gl")) {
        const params = getQueryParams(window.location.href);
        if (params.q) {
            const [lat, lon] = params.q.split(',');
            const osmUrl = `https://www.openstreetmap.org/#map=18/${lat}/${lon}`;
            redirectToOSM(osmUrl);
        }
    }

    // Check for crappy Maps place link
    if (window.location.href.includes("/maps/place/")) {
        const match = window.location.href.match(/@(-?\d+\.\d+),(-?\d+\.\d+)/);
        if (match) {
            const lat = match[1];
            const lon = match[2];
            const osmUrl = `https://www.openstreetmap.org/#map=18/${lat}/${lon}`;
            redirectToOSM(osmUrl);
        }
    }

    // Check for shitty Maps short links (maps.app.goo.gl)
    if (window.location.href.includes("maps.app.goo.gl")) {
        // As short links redirect to longer URLs, set an interval to handle redirection after the URL changes
        const interval = setInterval(() => {
            const match = window.location.href.match(/@(-?\d+\.\d+),(-?\d+\.\d+)/);
            if (match) {
                clearInterval(interval);
                const lat = match[1];
                const lon = match[2];
                const osmUrl = `https://www.openstreetmap.org/#map=18/${lat}/${lon}`;
                redirectToOSM(osmUrl);
            }
        }, 500);
    }
})();