Google Maps Coordinates Grabber

Once in Google Maps, click on the map (Do not click on markers) a popup should show at the bottom with the place and the coordinates displayed in the last line, click on any white space of that popup. The coordinates should now be copied to clipboard.

当前为 2019-03-02 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name     		Google Maps Coordinates Grabber
// @version  		0.1.0
// @namespace   https://greasyfork.org/en/users/250979-mrmike
// @author      MrAmericanMike
// @description Once in Google Maps, click on the map (Do not click on markers) a popup should show at the bottom with the place and the coordinates displayed in the last line, click on any white space of that popup. The coordinates should now be copied to clipboard.
// @grant 		  none
// @include  		http*://*google*/maps/*
// @run-at   		document-end
// ==/UserScript==

document.addEventListener("mouseup", lookForCoordinates);

function lookForCoordinates(){
  
  let card = document.getElementById("reveal-card");
  
  if(card){
    let latlng = document.getElementsByClassName("widget-reveal-card-lat-lng");
    if(latlng[0]){
      copyTextToClipboard(latlng[0].innerText, latlng[0]);
    }
  }
  
}


function fallbackCopyTextToClipboard(text, element) {
    var textArea = document.createElement("textarea");
    textArea.value = text;
    document.body.appendChild(textArea);
    textArea.focus();
    textArea.select();
  
    try {
      document.execCommand('copy');
    } catch (err) {
      if(!err){
        element.innerText = "Copied to Clipboard";
        resetElement(element, text);
      }
    }
  
    document.body.removeChild(textArea);
}

function copyTextToClipboard(text, element) {
    if (!navigator.clipboard) {
        fallbackCopyTextToClipboard(text, element);
        return;
    }
    navigator.clipboard.writeText(text).then(function() {
      element.innerText = "Copied to Clipboard";
      resetElement(element, text);
    }, function(err) {
    });
}

function resetElement(element, text){
  setTimeout(() => {
	  element.innerText = text;
  }, 2500);  
}