Geoguessr Map-Making Auto-Tag

tag by streetview date

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

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