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. If everything works as expected you should see a line of text on top of the map with the confirmation of the coordinates been copied to clipboard.

当前为 2021-08-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Google Maps Coordinates Grabber
  3. // @version 0.3.0
  4. // @namespace https://greasyfork.org/en/users/250979-mrmike
  5. // @author MrMike
  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. If everything works as expected you should see a line of text on top of the map with the confirmation of the coordinates been copied to clipboard.
  7. // @grant none
  8. // @include http*://*google*/maps/*
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. // Leave empty to get just the values separated by a comma
  13. // Example: `"lat": {{lat}}, "lng": {{lng}}`
  14. const FORMAT = ``;
  15.  
  16. let theCopiedCoords;
  17. let theCoords;
  18. let theLatLng;
  19. let theLat;
  20. let theLng;
  21. let tempCard;
  22.  
  23. //Look for card every X time
  24. setInterval(() => {
  25. //Get the card
  26. let theCard = document.getElementById("reveal-card");
  27. //Is the card not null?
  28. if (theCard != null) {
  29. let theDialog = theCard.querySelector("div[role='dialog']");
  30. if (theDialog != null) {
  31. theCoords = theDialog.lastElementChild.innerText;
  32. theLatLng = theCoords.replace(" ", "").split(",");
  33.  
  34. if (theLatLng.length == 2 && theCopiedCoords != theCoords) {
  35. theLat = theLatLng[0];
  36. theLng = theLatLng[1];
  37. if (!isNaN(theLat) && !isNaN(theLng)) {
  38. //Copy this data to clipboard
  39. if(FORMAT != ""){
  40. let out = FORMAT;
  41. copyTextToClipboard(out.replace("{{lat}}", theLat).replace("{{lng}}", theLng));
  42. theCopiedCoords = theCoords;
  43. }
  44. else{
  45. copyTextToClipboard(theCoords);
  46. theCopiedCoords = theCoords;
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }, 1000);
  53.  
  54. function doDisplay(theData) {
  55. let theInput = document.getElementById("omnibox");
  56. let inBold = document.createElement("div");
  57.  
  58. inBold.innerHTML = "<b style='font-size:20px'>Copied " + theData + "</b>";
  59. inBold.style.backgroundColor = "#202030CC";
  60. inBold.style.color = "#000099";
  61. inBold.style.width = "100vw";
  62. inBold.style.textAlign = "center";
  63.  
  64. theInput.parentNode.insertBefore(inBold, theInput.nextSibling);
  65.  
  66. setTimeout(() => {
  67. inBold.style.display = "none";
  68. }, 5000);
  69. }
  70.  
  71. function fallbackCopyTextToClipboard(text, element) {
  72. var textArea = document.createElement("textarea");
  73. textArea.value = text;
  74. document.body.appendChild(textArea);
  75. textArea.focus();
  76. textArea.select();
  77. try {
  78. var successful = document.execCommand('copy');
  79. if (successful) {
  80. doDisplay(text);
  81. }
  82. } catch (err) {
  83. }
  84. document.body.removeChild(textArea);
  85. }
  86.  
  87. function copyTextToClipboard(text, element) {
  88. if (!navigator.clipboard) {
  89. fallbackCopyTextToClipboard(text, element);
  90. return;
  91. }
  92. navigator.clipboard.writeText(text)
  93. .then(() => {
  94. doDisplay(text);
  95. }, (err) => {});
  96. }