// ==UserScript== // @name Google Street View Panorama Info // @description Displays the country name, coordinates, and panoId for a given Google Street View panorama // @version 1.8 // @match https://*.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 https://greasyfork.org/users/1340965 // @downloadURL none // ==/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 url = `https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=json` makeGetRequest(url) .then(result => { const data = JSON.parse(result) console.log(data.address) country = data?.address?.country ?? "Country not found" countryElement.querySelector('h2').innerText = country }) .catch(error => { console.error(`Request failed with error code ${error.status}\nMessage: ${error.responseText}`) }) } } function makeGetRequest(url) { return new Promise((resolve, reject) => { GM_xmlhttpRequest({ method: "GET", url: url, onload: response => resolve(response.responseText), onerror: error => reject(error) }); }); } const observer = new MutationObserver(updateTitleCard) observer.observe(document.body, { childList: true, subtree: true }) })();