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 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Google Maps Coordinates Grabber
  3. // @version 0.1.0
  4. // @namespace https://greasyfork.org/en/users/250979-mrmike
  5. // @author MrAmericanMike
  6. // @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.
  7. // @grant none
  8. // @include http*://*google*/maps/*
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. document.addEventListener("mouseup", lookForCoordinates);
  13.  
  14. function lookForCoordinates(){
  15. let card = document.getElementById("reveal-card");
  16. if(card){
  17. let latlng = document.getElementsByClassName("widget-reveal-card-lat-lng");
  18. if(latlng[0]){
  19. copyTextToClipboard(latlng[0].innerText, latlng[0]);
  20. }
  21. }
  22. }
  23.  
  24.  
  25. function fallbackCopyTextToClipboard(text, element) {
  26. var textArea = document.createElement("textarea");
  27. textArea.value = text;
  28. document.body.appendChild(textArea);
  29. textArea.focus();
  30. textArea.select();
  31. try {
  32. document.execCommand('copy');
  33. } catch (err) {
  34. if(!err){
  35. element.innerText = "Copied to Clipboard";
  36. resetElement(element, text);
  37. }
  38. }
  39. document.body.removeChild(textArea);
  40. }
  41.  
  42. function copyTextToClipboard(text, element) {
  43. if (!navigator.clipboard) {
  44. fallbackCopyTextToClipboard(text, element);
  45. return;
  46. }
  47. navigator.clipboard.writeText(text).then(function() {
  48. element.innerText = "Copied to Clipboard";
  49. resetElement(element, text);
  50. }, function(err) {
  51. });
  52. }
  53.  
  54. function resetElement(element, text){
  55. setTimeout(() => {
  56. element.innerText = text;
  57. }, 2500);
  58. }