mirror of
https://github.com/SwingTheVine/Wplace-BlueMarble.git
synced 2026-03-11 17:15:38 +00:00
23 lines
4.8 KiB
JavaScript
23 lines
4.8 KiB
JavaScript
// ==UserScript==
|
|
// @name Blue Marble
|
|
// @namespace https://github.com/SwingTheVine/
|
|
// @version 0.12.0
|
|
// @description A userscript to automate and/or enhance the user experience on Wplace.live. Make sure to comply with the site's Terms of Service, and rules! This script is not affiliated with Wplace.live in any way, use at your own risk. This script is not affiliated with TamperMonkey. The author of this userscript is not responsible for any damages, issues, loss of data, or punishment that may occur as a result of using this script. This script is provided "as is" under the MPL-2.0 license. The "Blue Marble" icon is licensed under CC0 1.0 Universal (CC0 1.0) Public Domain Dedication. The image is owned by NASA.
|
|
// @author SwingTheVine
|
|
// @license MPL-2.0
|
|
// @supportURL https://discord.gg/tpeBPy46hf
|
|
// @homepageURL https://github.com/SwingTheVine/Wplace-BlueMarble
|
|
// @icon https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/src/assets/Favicon.png
|
|
// @updateURL https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/dist/BlueMarble.user.js
|
|
// @downloadURL https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/dist/BlueMarble.user.js
|
|
// @run-at document-start
|
|
// @match *://*.wplace.live/*
|
|
// @grant GM_getResourceText
|
|
// @grant GM_addStyle
|
|
// @resource CSS-Overlay https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/src/overlay.css
|
|
// ==/UserScript==
|
|
|
|
// Wplace --> https://wplace.live
|
|
// License --> https://www.mozilla.org/en-US/MPL/2.0/
|
|
|
|
(()=>{var l=class{constructor(){}create(){let e=document.createElement("div");e.id="bm-overlay",e.style.top="10px",e.style.right="75px";let o=document.createElement("div"),t=document.createElement("div");t.id="bm-bar-drag",o.appendChild(t);let c=document.createElement("img");c.src="https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/src/assets/Favicon.png",c.alt="Blue Marble Icon",o.appendChild(c);let s=document.createElement("h1");s.textContent="Blue Marble",o.appendChild(s);let n=document.createElement("div"),d=document.createElement("p");d.id="bm-user-name",d.textContent="Username:",n.appendChild(d);let r=document.createElement("p");r.id="bm-user-droplets",r.textContent="Droplets:",n.appendChild(r),e.appendChild(o),e.appendChild(document.createElement("hr")),e.appendChild(n),document.body.appendChild(e),this.handleDrag(e,t)}handleDrag(e,o){let t=!1,c,s=0;o.addEventListener("mousedown",function(n){t=!0,c=n.clientX-e.getBoundingClientRect().left,s=n.clientY-e.getBoundingClientRect().top,document.body.style.userSelect="none",e.style.right="",o.classList.add("dragging")}),o.addEventListener("touchstart",function(n){t=!0;let d=n?.touches?.[0];d&&(c=d.clientX-e.getBoundingClientRect().left,s=d.clientY-e.getBoundingClientRect().top,document.body.style.userSelect="none",e.style.right="",o.classList.add("dragging"))},{passive:!1}),document.addEventListener("mousemove",function(n){t&&(e.style.left=n.clientX-c+"px",e.style.top=n.clientY-s+"px")}),document.addEventListener("touchmove",function(n){if(t){let d=n?.touches?.[0];if(!d)return;e.style.left=d.clientX-c+"px",e.style.top=d.clientY-s+"px",n.preventDefault()}},{passive:!1}),document.addEventListener("mouseup",function(){t=!1,document.body.style.userSelect="",o.classList.remove("dragging")}),document.addEventListener("touchend",function(){t=!1,document.body.style.userSelect="",o.classList.remove("dragging")}),document.addEventListener("touchcancel",function(){t=!1,document.body.style.userSelect="",o.classList.remove("dragging")})}};var a=class{constructor(){this.disableAll=!1}spontaneousResponseListener(e){window.addEventListener("message",o=>{let t=o.data;if(t&&t.source==="blue-marble")switch(t.endpoint){case"me":let c=document.getElementById("bm-user-name"),s=document.getElementById("bm-user-droplets");c&&(c.textContent=`Username: ${t.jsonData?.name}`),s&&(s.textContent=`Droplets: ${t.jsonData?.droplets}`);break;case"robots":this.disableAll=t.jsonData?.userscript?.toString().toLowerCase()=="false"}})}};function p(i){let e=document.createElement("script");e.textContent=`(${i})();`,document.documentElement.appendChild(e),e.remove()}p(()=>{let i=window.fetch;window.fetch=async function(...e){let o=await i.apply(this,e),t=o.clone();if((t.headers.get("content-type")||"").includes("application/json")){let s=(e[0]instanceof Request?e[0]?.url:e[0])||"ignore";s=s.split("/").filter(Boolean).pop()||"ignore",console.log(`Sending JSON message about endpoint "${s}"`),t.json().then(n=>{window.postMessage({source:"blue-marble",endpoint:s,jsonData:n},"*")}).catch(n=>{console.error("BM - Failed to parse JSON:",n)})}return o}});var m=GM_getResourceText("CSS-Overlay");GM_addStyle(m);var u=new l;u.create();var g=new a;g.spontaneousResponseListener(u);console.log("Blue Marble userscript has loaded!");})();
|