Open archive

11/21/2025, 1:04:55 AM

当前为 2025-11-21 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Open archive
// @namespace   Violentmonkey Scripts
// @match       https://wplace.live/*
// @grant       none
// @version     1.0
// @author      nopeee
// @description 11/21/2025, 1:04:55 AM
// @license MIT
// ==/UserScript==

(function() {
  'use strict';

  const targetElement = document.querySelector("input[readonly='']");
  let openArchiveButton = null;

  const observer = new MutationObserver((mutations) => {
    const container = targetElement.parentNode;
    if (container) {
      const copyButton = container.querySelector('button.btn-primary');
      if (copyButton && !openArchiveButton) {
        openArchiveButton = document.createElement('button');
        openArchiveButton.textContent = 'Open Archive';
        openArchiveButton.classList.add('btn');
        openArchiveButton.classList.add('btn-primary');
        container.insertBefore(openArchiveButton, copyButton.nextSibling);

        openArchiveButton.addEventListener('click', () => {
          const inputValue = targetElement.value;
          const url = new URL(inputValue);
          const params = new URLSearchParams(url.search);
          const lat = params.get('lat');
          const lng = params.get('lng');
          const zoom = params.get('zoom');
          const archiveUrl = `https://wplace.samuelscheit.com/#lat=${lat}&lng=${lng}&zoom=${zoom}`;
          window.open(archiveUrl, '_blank');
        });
      } else if (copyButton && openArchiveButton) {
        // if button already exists, check if it's still in the correct position
        if (openArchiveButton.parentNode !== container) {
          container.insertBefore(openArchiveButton, copyButton.nextSibling);
        }
      } else if (!copyButton && openArchiveButton) {
        // if copy button is gone, remove open archive button
        openArchiveButton.remove();
        openArchiveButton = null;
      }
    }
  });

  observer.observe(targetElement.parentElement.parentElement, {
    childList: true,
  });
})();