跳到正文

个人记录

tx

cmf2012约 14 分钟
原文
文章信息与版本

文章信息

收录
2026年8月14日
更新
2026年8月14日
篇幅
约 14 分钟

版本

  1. v1当前
Python
javascript: (function () {
  if (window.__tuxunFinderInstalled) {
    alert("图寻助手已安装,请在街景加载后点击左上角按钮");
    return;
  }
  window.__tuxunFinderInstalled = true;
  window.__tuxunLocations = [];

  const originalFetch = window.fetch;
  window.fetch = function (...args) {
    return originalFetch.apply(this, args).then(async (response) => {
      try {
        const url = args[0] || "";
        const urlStr = typeof url === "string" ? url : url.url || "";
        if (
          urlStr.includes("map.baidu.com") ||
          urlStr.includes("apis.map.qq.com") ||
          urlStr.includes("googleapis.com/maps") ||
          urlStr.includes("streetview") ||
          urlStr.includes("pano")
        ) {
          const clone = response.clone();
          const text = await clone.text();
          let data = null;
          try {
            data = JSON.parse(text);
          } catch (e) {}
          if (data) {
            const result = { url: urlStr, timestamp: Date.now() };
            if (data.data && data.data.lat !== undefined) {
              result.type =
                data.data.pano && data.data.pano.length > 8 ? "tencent" : "baidu";
              result.lat = data.data.lat;
              result.lng = data.data.lng;
              result.bd09Lat = data.data.bd09Lat;
              result.bd09Lng = data.data.bd09Lng;
              result.pano = data.data.pano;
              result.heading = data.data.centerHeading;
            }
            if (Array.isArray(data) && data.length > 1) {
              try {
                const panoId = data[1][0][1][1];
                const location = data[1][0][5][1][2];
                if (location && location[2] !== undefined) {
                  result.type = "google";
                  result.pano = panoId;
                  result.lat = location[2];
                  result.lng = location[3];
                  result.heading = data[1][0][5][1][4];
                  result.address = data[1][0][3][2][0][0];
                }
              } catch (e) {}
            }
            if (result.lat !== undefined) {
              window.__tuxunLocations.push(result);
              showToast(
                "✅ 捕获到坐标: " +
                  result.lat.toFixed(4) +
                  ", " +
                  result.lng.toFixed(4)
              );
            }
          }
        }
      } catch (e) {}
      return response;
    });
  };

  function showToast(msg) {
    const t = document.createElement("div");
    t.textContent = msg;
    t.style.cssText =
      "position:fixed;top:80px;left:50%;transform:translateX(-50%);background:#16a34a;color:#fff;padding:10px 20px;border-radius:8px;z-index:999999;box-shadow:0 4px 12px rgba(0,0,0,.2);font-size:14px;transition:opacity .3s;opacity:0";
    document.body.appendChild(t);
    requestAnimationFrame(() => (t.style.opacity = "1"));
    setTimeout(() => {
      t.style.opacity = "0";
      setTimeout(() => t.remove(), 300);
    }, 3000);
  }

  const btn = document.createElement("button");
  btn.innerHTML = "📍 显示答案";
  btn.style.cssText =
    "position:fixed;top:15px;left:15px;z-index:999998;background:#2563eb;color:#fff;border:none;padding:10px 16px;border-radius:8px;font-size:14px;cursor:pointer;box-shadow:0 4px 12px rgba(0,0,0,.2);transition:all .2s;";
  btn.onmouseenter = () => (btn.style.background = "#1d4ed8");
  btn.onmouseleave = () => (btn.style.background = "#2563eb");
  btn.onclick = function () {
    const locs = window.__tuxunLocations;
    if (!locs.length) {
      alert("暂未捕获到坐标,请等待街景加载完成!");
      return;
    }
    const loc = locs[locs.length - 1];
    const source = { baidu: "百度", tencent: "腾讯", google: "谷歌" }[loc.type] || "未知";
    let html = `
      <div style="position:fixed;inset:0;background:rgba(0,0,0,.5);z-index:999999;display:flex;align-items:center;justify-content:center;" id="__tuxun_modal">
        <div style="background:#fff;border-radius:16px;padding:24px;max-width:520px;width:90%;box-shadow:0 20px 60px rgba(0,0,0,.3);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;">
          <h2 style="margin:0 0 16px;font-size:20px;color:#111;">🗺️ 图寻答案 <span style="font-size:13px;background:#dbeafe;color:#1e40af;padding:3px 10px;border-radius:999px;">${source}街景</span></h2>`;
    if (loc.pano) html += `<div style="margin-bottom:10px;"><span style="color:#6b7280;font-size:13px;">PanoID:</span><code style="background:#f3f4f6;padding:2px 8px;border-radius:4px;">${loc.pano}</code></div>`;
    html += `
          <div style="background:linear-gradient(135deg,#f0fdf4,#dcfce7);border-radius:12px;padding:16px;margin-bottom:14px;">
            <div style="font-size:13px;color:#166534;margin-bottom:4px;">📍 WGS84 坐标</div>
            <div style="font-size:22px;font-weight:700;color:#14532d;">${loc.lat.toFixed(6)}, ${loc.lng.toFixed(6)}</div>
          </div>`;
    if (loc.bd09Lat !== undefined) {
      html += `<div style="background:#fef3c7;border-radius:12px;padding:16px;margin-bottom:14px;"><div style="font-size:13px;color:#92400e;margin-bottom:4px;">📍 BD09 坐标</div><div style="font-size:18px;font-weight:600;color:#78350f;">${loc.bd09Lat.toFixed(6)}, ${loc.bd09Lng.toFixed(6)}</div></div>`;
    }
    html += `<div style="display:flex;gap:8px;flex-wrap:wrap;margin-bottom:14px;">`;
    html += `<a href="https://www.google.com/maps?q=${loc.lat},${loc.lng}" target="_blank" style="flex:1;text-align:center;padding:10px;background:#2563eb;color:#fff;border-radius:8px;text-decoration:none;font-size:14px;font-weight:500;">🔗 谷歌地图</a>`;
    html += `<a href="https://api.map.baidu.com/marker?location=${loc.lat},${loc.lng}&title=图寻答案&output=html" target="_blank" style="flex:1;text-align:center;padding:10px;background:#16a34a;color:#fff;border-radius:8px;text-decoration:none;font-size:14px;font-weight:500;">🔗 百度地图</a>`;
    html += `</div>`;
    if (loc.heading) html += `<div style="font-size:14px;color:#374151;margin-bottom:6px;">🧭 初始方向:<b>${loc.heading}°</b></div>`;
    if (loc.address) html += `<div style="font-size:14px;color:#374151;margin-bottom:14px;">🏠 地址:<b>${loc.address}</b></div>`;
    html += `<div style="display:flex;gap:10px;margin-top:18px;">
      <button onclick="navigator.clipboard.writeText('${loc.lat.toFixed(6)},${loc.lng.toFixed(6)}').then(()=>{this.textContent='✅ 已复制';setTimeout(()=>this.textContent='📋 复制坐标',1500)}).catch(()=>alert('复制失败,请手动复制'))" style="flex:1;padding:10px 16px;background:#6366f1;color:#fff;border:none;border-radius:8px;font-size:14px;cursor:pointer;font-weight:500;">📋 复制坐标</button>
      <button onclick="document.getElementById('__tuxun_modal').remove()" style="flex:1;padding:10px 16px;background:#6b7280;color:#fff;border:none;border-radius:8px;font-size:14px;cursor:pointer;font-weight:500;">关闭</button>
    </div>
    ${locs.length > 1 ? `<div style="margin-top:14px;padding-top:14px;border-top:1px solid #e5e7eb;font-size:12px;color:#6b7280;">历史坐标:共 ${locs.length} 条,当前显示最新一条</div>` : ""}
    </div></div>`;
    const div = document.createElement("div");
    div.innerHTML = html;
    document.body.appendChild(div.firstElementChild);
  };
  document.body.appendChild(btn);
  showToast("✅ 图寻助手已加载!街景加载完成后点击左上角「显示答案」");
})();
原文