Geoguessr Map-Making Auto-Tag

for map-making tag

当前为 2023-09-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Geoguessr Map-Making Auto-Tag
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description for map-making tag
  6. // @author KaKa
  7. // @match https://map-making.app/*
  8. // @grant GM_setValue
  9. // @grant GM_getValue
  10. // @grant GM_setClipboard
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. async function runScript() {
  18. var api_key = GM_getValue("api_key");
  19. if (!api_key) {
  20. api_key = prompt("Please enter your API key");
  21. GM_setValue("api_key", api_key);
  22. }
  23. var text = await navigator.clipboard.readText();
  24. var data = JSON.parse(text);
  25. var newData = [];
  26.  
  27. function get_Meta(id) {
  28. var url = "https://maps.googleapis.com/maps/api/streetview/metadata?pano=" + id + "&key=" + api_key;
  29. return fetch(url)
  30. .then(function(response) {
  31. return response.json();
  32. })
  33. .then(function(data) {
  34. console.log(data);
  35. if (data.status == "OK") {
  36. var date = data.date;
  37. var cr = data.copyright;
  38. var year = 'nodate';
  39. var match = date.match(/\d{4}/);
  40. if (match) {
  41. year = match[0];
  42. }
  43.  
  44. var panoType = 'unofficial';
  45. if (cr.includes('Google')) {
  46. panoType = 'official';
  47. }
  48.  
  49. return [year, panoType, cr];
  50. } else {
  51. console.log("Error: " + data.status);
  52. }
  53. })
  54. .catch(function(error) {
  55. console.log(error);
  56. });
  57. }
  58.  
  59. function search_Meta(lat, lng) {
  60. var url = "https://maps.googleapis.com/maps/api/streetview/metadata?location=" + lat + "," + lng + "&key=" + api_key;
  61. return fetch(url)
  62. .then(function(response) {
  63. return response.json();
  64. })
  65. .then(function(data) {
  66. console.log(data);
  67. if (data.status == "OK") {
  68. var date = data.date;
  69. var cr = data.copyright;
  70. var year = 'nodate';
  71. var match = date.match(/\d{4}/);
  72. if (match) {
  73. year = match[0];
  74. }
  75.  
  76. var panoType = 'unofficial';
  77. if (cr.includes('Google')) {
  78. panoType = 'official';
  79. }
  80.  
  81. return [year, panoType, cr];
  82. } else {
  83. console.log("Error: " + data.status);
  84. }
  85. })
  86. .catch(function(error) {
  87. console.log(error);
  88. });
  89. }
  90.  
  91. var promises = [];
  92.  
  93. for (let i in data.customCoordinates) {
  94. if (data.customCoordinates[i].panoId) {
  95. promises.push(get_Meta(data.customCoordinates[i].panoId).then(function(meta) {
  96. if (meta && meta.length >= 2) {
  97. var year_tag = meta[0];
  98. var type_tag = meta[1];
  99. data.customCoordinates[i].extra.tags.push(year_tag);
  100. data.customCoordinates[i].extra.tags.push(type_tag);
  101. newData.push(data.customCoordinates[i]);
  102. }
  103. }));
  104. } else {
  105. promises.push(search_Meta(data.customCoordinates[i].lat,data.customCoordinates[i].lng).then(function(meta) {
  106. if (meta && meta.length >= 2) {
  107. var year_tag = meta[0];
  108. var type_tag = meta[1];
  109. data.customCoordinates[i].extra.tags.push(year_tag);
  110. data.customCoordinates[i].extra.tags.push(type_tag);
  111. newData.push(data.customCoordinates[i]);
  112. }
  113. }));
  114. }
  115. }
  116.  
  117. Promise.all(promises).then(function() {
  118. GM_setClipboard(JSON.stringify(newData));
  119. alert("New JSON data has been copied to the clipboard!");
  120. });
  121. }
  122.  
  123. var button = document.createElement('button');
  124. button.textContent = 'Auto-Tag';
  125. button.addEventListener('click', runScript);
  126. document.body.appendChild(button);
  127. })();