Greasy Fork

Greasy Fork is available in English.

Google Street View Panorama Info

Displays the country name, coordinates, and panoId for a given Google Street View panorama

当前为 2025-01-21 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Google Street View Panorama Info
// @description  Displays the country name, coordinates, and panoId for a given Google Street View panorama
// @version      1.7
// @match        *://*.google.*/maps/*
// @run-at       document-end
// @grant        GM_setClipboard
// @grant        GM_xmlhttpRequest
// @author       ZecaGeo
// @license      MIT
// @icon         https://www.google.com/s2/favicons?sz=64&domain=geohints.com
// @namespace    http://greasyfork.icu/users/1340965
// ==/UserScript==
/* jshint esversion: 11 */

(() => {
    'use strict'

    let country = 'Country not found', panoId = ''
    let latitude = 0, longitude = 0

    const regex = /@(-?\d+\.\d+),(-?\d+\.\d+).*!1s(.+)!2e/
    const match = window.location.href.match(regex)
    if (!match) {
        console.error('Coordinates not parsed.')
        window.alert(country)
        return
    }

    latitude = match[1], longitude = match[2], panoId = match[3]

    function updateTitleCard() {
        const addressElement = document.querySelector('.pB8Nmf div')
        if (addressElement) {
            observer.disconnect()

            let countryElement = addressElement.cloneNode(true)
            countryElement.querySelector('h2').innerText = country
            addressElement.parentNode.insertBefore(countryElement, addressElement.nextSibling)

            let latitudeElement = addressElement.cloneNode(true)
            latitudeElement.querySelector('h2').innerText = latitude
            latitudeElement.style.cursor = "pointer"
            latitudeElement.onclick = () => GM_setClipboard(latitude)
            addressElement.parentNode.insertBefore(latitudeElement, countryElement.nextSibling)

            let longitudeElement = addressElement.cloneNode(true)
            longitudeElement.querySelector('h2').innerText = longitude
            longitudeElement.style.cursor = "pointer"
            longitudeElement.onclick = () => GM_setClipboard(longitude)
            addressElement.parentNode.insertBefore(longitudeElement, latitudeElement.nextSibling)

            let panoIdElement = addressElement.cloneNode(true)
            panoIdElement.querySelector('h2').innerText = panoId
            panoIdElement.style.cursor = "pointer"
            panoIdElement.onclick = () => GM_setClipboard(panoId)
            addressElement.parentNode.insertBefore(panoIdElement, longitudeElement.nextSibling)

            let apiUrl = `https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=json`
            GM_xmlhttpRequest({
                headers: {
                    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36',
                },
                method: 'GET',
                onload: response => {
                    let data = JSON.parse(response.responseText)
                    country = data?.address?.country ?? "Country not found"
                    countryElement.querySelector('h2').innerText = country
                    console.log(data.address)
                },
                url: apiUrl
            })
        }
    }

    const observer = new MutationObserver(updateTitleCard)
    observer.observe(document.body, { childList: true, subtree: true })
})();