Wplace chunk position

Print selected pixel's chunk position to console

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Wplace chunk position
// @namespace    http://tampermonkey.net/
// @version      0.0.2
// @description  Print selected pixel's chunk position to console
// @author       rice-cracker-dev
// @match        https://wplace.live/*
// @grant        unsafeWindow
// @connect      *
// @run-at       document-start
// @license      MIT
// ==/UserScript==
(() => {
  const originalFetch = window.fetch;

  const hookedFetch = async (resource, init) => {
    const url = new URL(
      typeof resource === "string" ? resource : resource.url || "",
    );

    try {
      const res = await originalFetch(resource, init);

      const x = url.searchParams.get("x");
      const y = url.searchParams.get("y");

      if (x && y) {
        const pathnames = url.pathname.split("/");
        const chunkX = pathnames[pathnames.length - 2];
        const chunkY = pathnames[pathnames.length - 1];
        const chunkUrl = `https://backend.wplace.live/files/s0/tiles/${chunkX}/${chunkY}.png`;
        console.log(
          `You clicked on chunk ${chunkX}/${chunkY}, pixel ${x}/${y}\nChunk image: ${chunkUrl}`,
        );
      }

      return res;
    } catch (e) {
      console.error(e);
      return originalFetch(resource, init);
    }
  };

  window.fetch = hookedFetch;
  unsafeWindow.fetch = hookedFetch;
})();