Open archive

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

Tính đến 21-11-2025. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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,
  });
})();