Wplace-BlueMarble/dist/BlueMarble.user.js
2025-07-27 15:11:54 +00:00

23 lines
No EOL
10 KiB
JavaScript

// ==UserScript==
// @name Blue Marble
// @namespace https://github.com/SwingTheVine/
// @version 0.53.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-BM-File https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/dist/BlueMarble.user.css
// ==/UserScript==
// Wplace --> https://wplace.live
// License --> https://www.mozilla.org/en-US/MPL/2.0/
(()=>{var t,e,n=t=>{throw TypeError(t)},s=(t,e,s)=>(((t,e)=>{e.has(t)||n("Cannot access private method")})(t,e),s);t=new WeakSet,e=function(t,e={},n={}){const s=document.createElement(t);this.t?(this.i.appendChild(s),this.o.push(this.i),this.i=s):(this.t=s,this.i=s);for(const[t,n]of Object.entries(e))s[t]=n;for(const[t,e]of Object.entries(n))s[t]=e;return s};var i=class{static h(t){const e=document.createElement("div");return e.textContent=t,e.innerHTML}},o=GM_info.script.name.toString(),r=GM_info.script.version.toString();!function(t){const e=document.createElement("script");e.textContent=`(${t})();`,document.documentElement.appendChild(e),e.remove()}(()=>{const t=window.fetch;window.fetch=async function(...e){const n=await t.apply(this,e),s=n.clone();if((s.headers.get("content-type")||"").includes("application/json")){let t=(e[0]instanceof Request?e[0]?.url:e[0])||"ignore";s.json().then(e=>{window.postMessage({source:"blue-marble",endpoint:t,jsonData:e},"*")}).catch(t=>{})}return n}});var a=GM_getResourceText("CSS-BM-File");GM_addStyle(a);var c=document.createElement("link");c.href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap",c.rel="preload",c.as="style",c.onload=function(){this.onload=null,this.rel="stylesheet"},document.head.appendChild(c),new class{constructor(){this.l=null,this.u=null,this.m="#bm-display-coords"}p(t){return this.u=t,this.l=new MutationObserver(t=>{for(const e of t)for(const t of e.addedNodes)t instanceof HTMLElement&&t.matches?.(this.m)}),this}v(){return this.l}observe(t,e=!1,n=!1){t.observe(this.u,{childList:e,subtree:n})}};var h=new class{constructor(e,s){var i,o;i=this,(o=t).has(i)?n("Cannot add the same private member more than once"):o instanceof WeakSet?o.add(i):o.set(i,undefined),this.name=e,this.version=s,this.M=null,this.C="bm-output-status",this.t=null,this.i=null,this.o=[]}$(t){this.M=t}T(){return this.o.length>0&&(this.i=this.o.pop()),this}k(t){t.appendChild(this.t),this.t=null,this.i=null,this.o=[]}I(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"div",{},n)),this}H(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"p",{},n)),this}N(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"img",{},n)),this}L(n,i={},o=()=>{}){return o(this,s(this,t,e).call(this,"h"+n,{},i)),this}S(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"hr",{},n)),this}B(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"br",{},n)),this}D(n={},i=()=>{}){const o=s(this,t,e).call(this,"label",{textContent:n.textContent??""});delete n.textContent;const r=s(this,t,e).call(this,"input",{type:"checkbox"},n);return o.insertBefore(r,o.firstChild),this.T(),i(this,o,r),this}P(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"button",{},n)),this}O(n={},i=()=>{}){const o=n.title??n.textContent??"Help: No info";delete n.textContent,n.title=`Help: ${o}`;const r={textContent:"?",className:"bm-help",onclick:()=>{this.R(this.C,o)}};return i(this,s(this,t,e).call(this,"button",r,n)),this}j(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"input",{},n)),this}G(n={},i=()=>{}){const o=n.textContent??"";delete n.textContent;const r=s(this,t,e).call(this,"div"),a=s(this,t,e).call(this,"input",{type:"file",style:"display: none;"},n);this.T();const c=s(this,t,e).call(this,"button",{textContent:o});return this.T(),this.T(),c.addEventListener("click",()=>{a.click()}),a.addEventListener("change",()=>{c.style.maxWidth=`${c.offsetWidth}px`,a.files.length>0?c.textContent=a.files[0].name:c.textContent=o}),i(this,r,a,c),this}U(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"textarea",{},n)),this}R(t,e,n=!1){const s=document.getElementById(t.replace(/^#/,""));s&&(s instanceof HTMLInputElement?s.value=e:n?s.textContent=e:s.innerHTML=e)}W(t,e){let n,s=!1,i=0;t=document.querySelector("#"==t?.[0]?t:"#"+t),e=document.querySelector("#"==e?.[0]?e:"#"+e),t&&e?(e.addEventListener("mousedown",function(o){s=!0,n=o.clientX-t.getBoundingClientRect().left,i=o.clientY-t.getBoundingClientRect().top,document.body.style.userSelect="none",e.classList.add("dragging")}),e.addEventListener("touchstart",function(o){s=!0;const r=o?.touches?.[0];r&&(n=r.clientX-t.getBoundingClientRect().left,i=r.clientY-t.getBoundingClientRect().top,document.body.style.userSelect="none",e.classList.add("dragging"))},{passive:!1}),document.addEventListener("mousemove",function(e){s&&(t.style.left=e.clientX-n+"px",t.style.top=e.clientY-i+"px",t.style.right="")}),document.addEventListener("touchmove",function(e){if(s){const s=e?.touches?.[0];if(!s)return;t.style.left=s.clientX-n+"px",t.style.top=s.clientY-i+"px",e.preventDefault()}},{passive:!1}),document.addEventListener("mouseup",function(){s=!1,document.body.style.userSelect="",e.classList.remove("dragging")}),document.addEventListener("touchend",function(){s=!1,document.body.style.userSelect="",e.classList.remove("dragging")}),document.addEventListener("touchcancel",function(){s=!1,document.body.style.userSelect="",e.classList.remove("dragging")})):this.X(`Can not drag! ${t?"":"moveMe"} ${t||e?"":"and "}${e?"":"iMoveThings "}was not found!`)}X(t){(0,console.error)(`${this.name}: ${t}`),this.R(this.C,"Error: "+t,!0)}}(o,r),d=new class{Y(t,e){return[parseInt(t[0])%4*1e3+parseInt(e[0]),parseInt(t[1])%4*1e3+parseInt(e[1])]}},l=new class{constructor(t){this._=t,this.q=!1,this.F=[]}V(t){window.addEventListener("message",e=>{const n=e.data,s=n.jsonData;if(n&&"blue-marble"===n.source)switch(n.endpoint.split("?")[0].split("/").filter(t=>t&&isNaN(Number(t))).pop()){case"me":if(s.status&&"2"!=s.status?.toString()[0])return void t.X("The game is down!\nCould not fetch userdata.");const e=Math.ceil(Math.pow(Math.floor(s.level)*Math.pow(30,.65),1/.65)-s.pixelsPainted);t.R("bm-user-name",`Username: <b>${i.h(s.name)}</b>`),t.R("bm-user-droplets",`Droplets: <b>${(new Intl.NumberFormat).format(s.droplets)}</b>`),t.R("bm-user-nextlevel",`Next level in <b>${(new Intl.NumberFormat).format(e)}</b> pixel${1==e?"":"s"}`);break;case"pixel":const o=n.endpoint.split("?")[0].split("/").filter(t=>t&&!isNaN(Number(t))),r=new URLSearchParams(n.endpoint.split("?")[1]),a=[r.get("x"),r.get("y")];this.F=[...o,...a];const c=this._.Y(o,a),h=document.querySelectorAll("span");for(const t of h)if(t.textContent.trim().includes(`${c[0]}, ${c[1]}`)){let e=document.querySelector("#bm-display-coords");const n=`(Tl X: ${o[0]}, Tl Y: ${o[1]}, Px X: ${a[0]}, Px Y: ${a[1]})`;e?e.textContent=n:(e=document.createElement("span"),e.id="bm-display-coords",e.textContent=n,e.style="margin-left: calc(var(--spacing)*3); font-size: small;",t.parentNode.parentNode.parentNode.insertAdjacentElement("afterend",e))}break;case"robots":this.q="false"==s.userscript?.toString().toLowerCase()}})}}(d);h.$(l),h.I({id:"bm-overlay",style:"top: 10px; right: 75px;"}).I({id:"bm-contain-header"}).I({id:"bm-bar-drag"}).T().N({alt:"Blue Marble Icon",src:"https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/src/assets/Favicon.png"}).T().L(1,{textContent:o}).T().T().S().T().I({id:"bm-contain-userinfo"}).H({id:"bm-user-name",textContent:"Username:"}).T().H({id:"bm-user-droplets",textContent:"Droplets:"}).T().H({id:"bm-user-nextlevel",textContent:"Next level in..."}).T().T().S().T().I({id:"bm-contain-automation"}).D({id:"bm-input-stealth",textContent:"Stealth",checked:!0}).T().O({title:"Waits for the website to make requests, instead of sending requests."}).T().B().T().D({id:"bm-input-possessed",textContent:"Possessed",checked:!0}).T().O({title:"Controls the website as if it were possessed."}).T().B().T().I({id:"bm-contain-coords"}).P({id:"bm-button-coords",className:"bm-help",style:"margin-top: 0;",innerHTML:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4 6"><circle cx="2" cy="2" r="2"></circle><path d="M2 6 L3.7 3 L0.3 3 Z"></path><circle cx="2" cy="2" r="0.7" fill="white"></circle></svg></svg>'},(t,e)=>{e.onclick=()=>{const e=t.M?.F;e?.[0]?(t.R("bm-input-tx",e?.[0]||""),t.R("bm-input-ty",e?.[1]||""),t.R("bm-input-px",e?.[2]||""),t.R("bm-input-py",e?.[3]||"")):t.X("Coordinates are malformed! Did you try clicking on the canvas first?")}}).T().j({type:"number",id:"bm-input-tx",placeholder:"Tl X",min:0,max:2047,step:1}).T().j({type:"number",id:"bm-input-ty",placeholder:"Tl Y",min:0,max:2047,step:1}).T().j({type:"number",id:"bm-input-px",placeholder:"Px X",min:0,max:2047,step:1}).T().j({type:"number",id:"bm-input-py",placeholder:"Px Y",min:0,max:2047,step:1}).T().T().G({id:"bm-input-file-template",textContent:"Upload Template"}).T().I({id:"bm-contain-buttons"}).P({id:"bm-button-enable",textContent:"Enable"}).T().P({id:"bm-button-disable",textContent:"Disable"}).T().T().U({id:h.C,placeholder:`Status: Sleeping...\nVersion: ${r}`,readOnly:!0}).T().T().k(document.body),h.W("#bm-overlay","#bm-bar-drag"),l.V(h)})();