Google Maps Contributions Downloader

Download all the photospheres of a specific Google Maps contributor as a GeoGuessr json

目前為 2024-11-03 提交的版本,檢視 最新版本

// ==UserScript==
// @name Google Maps Contributions Downloader
// @namespace gmcd
// @description Download all the photospheres of a specific Google Maps contributor as a GeoGuessr json
// @version 0.1
// @match https://www.google.com/*
// @run-at document-start
// @license MIT
// ==/UserScript==

(function() {
  function downloadJSON(locations) {
    let file = new Blob([JSON.stringify(locations)], { type: "application/json" })
    let link = document.createElement("a")
    link.target= "_blank"
    link.href = URL.createObjectURL(file)
    link.download = document.querySelector("h1[jsaction='pane.profile-stats.showStats; keydown:pane.profile-stats.showStats']").innerText
    link.click()
    URL.revokeObjectURL(link.href)
  }
  
  function onClick(event) {
    locations = [];
    for (let img of document.getElementsByTagName("img")) {
      if (img.src.includes("-fo")) {
        let panoId = /AF1Q[^=]*/.exec(img.src)[0]
        if (panoId.length == 44) {
          panoId = btoa("\b\n\x12," + panoId)
        } else if (panoId.length == 43) {
          panoId = btoa("\b\n\x12+" + panoId).replaceAll("=", "")
        } else if (panoId.length == 42) {
          panoId = btoa("\b\n\x12+" + panoId).replaceAll("=", "")
        }
        locations.push({ lat: 0, lng:0, panoId: panoId })
      }
    }
    
    n = 0
    for (let location of locations) {
      let url = "https://maps.googleapis.com/$rpc/google.internal.maps.mapsjs.v1.MapsJsInternalService/GetMetadata"
      let init = {
				method: "POST",
				headers: {
				  "Content-Type": "application/json+protobuf",
				  "x-user-agent": "grpc-web-javascript/0.1"
				},
				body: JSON.stringify([["apiv3"],[],[[[10,atob(location.panoId.replaceAll(".", "")).slice(4)]]],[[1, 2, 3, 4, 6, 8]]])
			}
      fetch(url, init)
      	.then((response) => {
					return response.json()
				})
      	.then((response) => {
        	location.lat = response[1][0][5][0][1][0][2]
          location.lng = response[1][0][5][0][1][0][3]
        	n++
        	if (n == locations.length) {
            downloadJSON(locations)
          }
      	})
    }
  }
  
  function onLoad() {
    h1 = document.querySelector("h1[jsaction='pane.profile-stats.showStats; keydown:pane.profile-stats.showStats']")
    
    div = document.createElement("div")
    div.style = "display: flex; flex-direction: horizontal; align-items: center;"
    
    h1.parentNode.insertBefore(div, h1)
    div.appendChild(h1)
    
    button = document.createElement("button")
    button.innerText = "💾"
    button.classList = h1.classList
    button.addEventListener("click", onClick)
    div.appendChild(button)
  }
  
	window.addEventListener("load", onLoad)
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址