mirror of
https://github.com/SwingTheVine/Wplace-BlueMarble.git
synced 2026-04-20 18:32:04 +00:00
23 lines
No EOL
19 KiB
JavaScript
23 lines
No EOL
19 KiB
JavaScript
// ==UserScript==
|
|
// @name Blue Marble
|
|
// @namespace https://github.com/SwingTheVine/
|
|
// @version 0.65.51
|
|
// @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/51b906a447aa39e6ea82ece26696d73fb6c9b693/dist/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/51b906a447aa39e6ea82ece26696d73fb6c9b693/dist/BlueMarble.user.css
|
|
// ==/UserScript==
|
|
|
|
// Wplace --> https://wplace.live
|
|
// License --> https://www.mozilla.org/en-US/MPL/2.0/
|
|
|
|
(()=>{var t,e,s=t=>{throw TypeError(t)},n=(t,e,n)=>e.has(t)?s("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),i=(t,e,n)=>(((t,e)=>{e.has(t)||s("Cannot access private method")})(t,e),n);t=new WeakSet,e=function(t,e={},s={}){const n=document.createElement(t);this.t?(this.i.appendChild(n),this.o.push(this.i),this.i=n):(this.t=n,this.i=n);for(const[t,s]of Object.entries(e))n[t]=s;for(const[t,e]of Object.entries(s))n[t]=e;return n};var o,a=class{constructor({displayName:t="My template",l:e=0,h:s="",url:n="",file:i=null,coords:o=null,m:a=null,u:r=1e3}={}){this.displayName=t,this.l=e,this.h=s,this.url=n,this.file=i,this.coords=o,this.m=a,this.u=r}async p(){console.log(this.coords);const t=await createImageBitmap(this.file),e=t.width,s=t.height,n={},i=new OffscreenCanvas(this.u,this.u),o=i.getContext("2d",{$:!0});for(let a=this.coords[3];a<s+this.coords[3];){const r=Math.min(this.u-a%this.u,s-(a-this.coords[3])*(a!=this.coords[3]));console.log(`Math.min(${this.u} - (${a} % ${this.u}), ${s} - (${a-this.coords[3]} * (${a} != ${this.coords[3]})))`);for(let s=this.coords[2];s<e+this.coords[2];){console.log(`Pixel X: ${s}\nPixel Y: ${a}`);const c=Math.min(this.u-s%this.u,e-(s-this.coords[2])*(s!=this.coords[2]));console.log(`Math.min(${this.u} - (${s} % ${this.u}), ${e} - (${s} * (${s} != ${this.coords[2]})))`),console.log(`Draw Size X: ${c}\nDraw Size Y: ${r}`),console.log(`Draw X: ${c}\nDraw Y: ${r}\nCanvas Width: ${3*c}\nCanvas Height: ${3*r}`),i.width=3*c,i.height=3*r,console.log(`Getting X ${s}-${s+c}\nGetting Y ${a}-${a+r}`),o.clearRect(0,0,3*c,3*r),o.drawImage(t,s,a,c,r,0,0,3*c,3*r);const l=o.getImageData(0,0,3*c,3*r);for(let t=0;t<3*r;t++)for(let e=0;e<3*c;e++)if(e%3!=1||t%3!=1){const s=4*(t*c+e);l.data[s+3]=0}console.log(`Shreaded pixels for ${s}, ${a}`,l),o.putImageData(l,0,0),n[`${(this.coords[0]+Math.floor(s/1e3)).toString().padStart(4,"0")},${(this.coords[1]+Math.floor(a/1e3)).toString().padStart(4,"0")},${(s%1e3).toString().padStart(3,"0")},${(a%1e3).toString().padStart(3,"0")}`]=await i.convertToBlob({type:"image/png"}),console.log(n),s+=c}a+=r}return console.log("Template Tiles: ",n),n}};function r(t,e){if(0===t)return e[0];let s="";const n=e.length;for(;t>0;)s=e[t%n]+s,t=Math.floor(t/n);return s}o=new WeakSet;var c=GM_info.script.name.toString(),l=GM_info.script.version.toString();!function(t){const e=document.createElement("script");e.setAttribute("bm-s",c),e.setAttribute("bm-q","color: cornflowerblue;"),e.textContent=`(${t})();`,document.documentElement.appendChild(e),e.remove()}(()=>{const t=document.currentScript,e=t?.getAttribute("bm-s")||"Blue Marble",s=t?.getAttribute("bm-q")||"",n=new Map;window.addEventListener("message",t=>{const{source:i,endpoint:o,blobID:a,blobData:r,blink:c}=t.data,l=Date.now()-c;console.groupCollapsed(`%c${e}%c: ${n.size} Recieved IMAGE message about blob "${a}"`,s,""),console.log(`Blob fetch took %c${String(Math.floor(l/6e4)).padStart(2,"0")}:${String(Math.floor(l/1e3)%60).padStart(2,"0")}.${String(l%1e3).padStart(3,"0")}%c MM:SS.mmm`,s,""),console.log(n),console.groupEnd(),"blue-marble"==i&&a&&r&&!o&&n.get(a)(r)});const i=window.fetch;window.fetch=async function(...t){const o=await i.apply(this,t),a=o.clone(),r=(t[0]instanceof Request?t[0]?.url:t[0])||"ignore",c=a.headers.get("content-type")||"";if(c.includes("application/json"))console.log(`%c${e}%c: Sending JSON message about endpoint "${r}"`,s,""),a.json().then(t=>{window.postMessage({source:"blue-marble",endpoint:r,jsonData:t},"*")}).catch(t=>{console.error(`%c${e}%c: Failed to parse JSON: `,s,"",t)});else if(c.includes("image/")&&!r.includes("openfreemap")){const t=Date.now(),i=await a.blob();return console.log(`%c${e}%c: ${n.size} Sending IMAGE message about endpoint "${r}"`,s,""),new Promise(o=>{const c=crypto.randomUUID();n.set(c,t=>{o(new Response(t,{headers:a.headers,status:a.status,statusText:a.statusText})),n.delete(c),console.log(`%c${e}%c: ${n.size} Processed blob "${c}"`,s,"")}),window.postMessage({source:"blue-marble",endpoint:r,blobID:c,blobData:i,blink:t})}).catch(i=>{const o=Date.now();console.error(`%c${e}%c: Failed to Promise blob!`,s,""),console.groupCollapsed(`%c${e}%c: Details of failed blob Promise:`,s,""),console.log(`Endpoint: ${r}\nThere are ${n.size} blobs processing...\nBlink: ${t.toLocaleString()}\nTime Since Blink: ${String(Math.floor(o/6e4)).padStart(2,"0")}:${String(Math.floor(o/1e3)%60).padStart(2,"0")}.${String(o%1e3).padStart(3,"0")} MM:SS.mmm`),console.error("Exception stack:",i),console.groupEnd()})}return o}});var h=GM_getResourceText("CSS-BM-File");GM_addStyle(h);var m=document.createElement("link");m.href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap",m.rel="preload",m.as="style",m.onload=function(){this.onload=null,this.rel="stylesheet"},document.head.appendChild(m),new class{constructor(){this.v=null,this.M=null,this.S="#bm-9"}C(t){return this.M=t,this.v=new MutationObserver(t=>{for(const e of t)for(const t of e.addedNodes)t instanceof HTMLElement&&t.matches?.(this.S)}),this}D(){return this.v}observe(t,e=!1,s=!1){t.observe(this.M,{childList:e,subtree:s})}};var d=new class{constructor(e,s){n(this,t),this.name=e,this.version=s,this.k=null,this.T="bm-e",this.t=null,this.i=null,this.o=[]}I(t){this.k=t}N(){return this.o.length>0&&(this.i=this.o.pop()),this}B(t){t.appendChild(this.t),this.t=null,this.i=null,this.o=[]}O(s={},n=()=>{}){return n(this,i(this,t,e).call(this,"div",{},s)),this}P(s={},n=()=>{}){return n(this,i(this,t,e).call(this,"p",{},s)),this}H(s={},n=()=>{}){return n(this,i(this,t,e).call(this,"small",{},s)),this}L(s={},n=()=>{}){return n(this,i(this,t,e).call(this,"img",{},s)),this}R(s,n={},o=()=>{}){return o(this,i(this,t,e).call(this,"h"+s,{},n)),this}Y(s={},n=()=>{}){return n(this,i(this,t,e).call(this,"hr",{},s)),this}q(s={},n=()=>{}){return n(this,i(this,t,e).call(this,"br",{},s)),this}G(s={},n=()=>{}){const o=i(this,t,e).call(this,"label",{textContent:s.textContent??""});delete s.textContent;const a=i(this,t,e).call(this,"input",{type:"checkbox"},s);return o.insertBefore(a,o.firstChild),this.N(),n(this,o,a),this}X(s={},n=()=>{}){return n(this,i(this,t,e).call(this,"button",{},s)),this}j(s={},n=()=>{}){const o=s.title??s.textContent??"Help: No info";delete s.textContent,s.title=`Help: ${o}`;const a={textContent:"?",className:"bm-t",onclick:()=>{this._(this.T,o)}};return n(this,i(this,t,e).call(this,"button",a,s)),this}F(s={},n=()=>{}){return n(this,i(this,t,e).call(this,"input",{},s)),this}W(s={},n=()=>{}){const o=s.textContent??"";delete s.textContent;const a=i(this,t,e).call(this,"div"),r=i(this,t,e).call(this,"input",{type:"file",style:"display: none;"},s);this.N();const c=i(this,t,e).call(this,"button",{textContent:o});return this.N(),this.N(),c.addEventListener("click",()=>{r.click()}),r.addEventListener("change",()=>{c.style.maxWidth=`${c.offsetWidth}px`,r.files.length>0?c.textContent=r.files[0].name:c.textContent=o}),n(this,a,r,c),this}J(s={},n=()=>{}){return n(this,i(this,t,e).call(this,"textarea",{},s)),this}_(t,e,s=!1){const n=document.getElementById(t.replace(/^#/,""));n&&(n instanceof HTMLInputElement?n.value=e:s?n.textContent=e:n.innerHTML=e)}V(t,e){let s,n=!1,i=0;t=document.querySelector("#"==t?.[0]?t:"#"+t),e=document.querySelector("#"==e?.[0]?e:"#"+e),t&&e?(e.addEventListener("mousedown",function(o){n=!0,s=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){n=!0;const a=o?.touches?.[0];a&&(s=a.clientX-t.getBoundingClientRect().left,i=a.clientY-t.getBoundingClientRect().top,document.body.style.userSelect="none",e.classList.add("dragging"))},{passive:!1}),document.addEventListener("mousemove",function(e){n&&(t.style.left=e.clientX-s+"px",t.style.top=e.clientY-i+"px",t.style.right="")}),document.addEventListener("touchmove",function(e){if(n){const n=e?.touches?.[0];if(!n)return;t.style.left=n.clientX-s+"px",t.style.top=n.clientY-i+"px",e.preventDefault()}},{passive:!1}),document.addEventListener("mouseup",function(){n=!1,document.body.style.userSelect="",e.classList.remove("dragging")}),document.addEventListener("touchend",function(){n=!1,document.body.style.userSelect="",e.classList.remove("dragging")}),document.addEventListener("touchcancel",function(){n=!1,document.body.style.userSelect="",e.classList.remove("dragging")})):this.A(`Can not drag! ${t?"":"moveMe"} ${t||e?"":"and "}${e?"":"iMoveThings "}was not found!`)}U(t){(0,console.info)(`${this.name}: ${t}`),this._(this.T,"Status: "+t,!0)}A(t){(0,console.error)(`${this.name}: ${t}`),this._(this.T,"Error: "+t,!0)}}(c,l),u=new class{constructor(t,e){n(this,o),this.name=t,this.version=e,this.Z="1.0.0",this.K=null,this.tt="!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~",this.et=null,this.st=null,this.nt="bm-r",this.it="div#map canvas.maplibregl-canvas",this.ot=null,this.rt="",this.ct=[],this.lt=null}ht(){if(document.body.contains(this.et))return this.et;document.getElementById(this.nt)?.remove();const t=document.querySelector(this.it),e=document.createElement("canvas");return e.id=this.nt,e.className="maplibregl-canvas",e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.height=t?.clientHeight*(window.devicePixelRatio||1)+"px",e.style.width=t?.clientWidth*(window.devicePixelRatio||1)+"px",e.height=t?.clientHeight*(window.devicePixelRatio||1),e.width=t?.clientWidth*(window.devicePixelRatio||1),e.style.zIndex="8999",e.style.pointerEvents="none",t?.parentElement?.appendChild(e),this.et=e,window.addEventListener("move",this.dt),window.addEventListener("zoom",this.ut),window.addEventListener("resize",this.bt),this.et}async ft(){return{whoami:this.name.replace(" ",""),scriptVersion:this.version,schemaVersion:this.Z,templates:{}}}async gt(t,e,s){this.lt||(this.lt=await this.ft(),console.log("Creating JSON...")),console.log("Awaiting creation...");const n=new a({displayName:e,l:Object.keys(this.lt.templates).length||0,h:r(this.K||0,this.tt),file:t,coords:s});n.m=await n.p(1e3),this.lt.templates[`${n.l} ${n.h}`]={name:n.displayName,tiles:n.m},this.ct.push(n),console.log(Object.keys(this.lt.templates).length),console.log(this.lt),console.log(this.ct)}wt(){}$t(){}vt(){}yt(t){this.ot=t,this.rt="file"}async xt(t,e=[0,0,0,0]){if("file"!=this.rt&&"template"!=this.rt)return;const s=3e3;e=e?.length?e:[0,0,0,0],console.log(this.ot);const n="template"==this.rt?this.ot:await createImageBitmap(await this.Mt(this.ot)),i=await createImageBitmap(t),o=new OffscreenCanvas(s,s),a=o.getContext("2d");a.imageSmoothingEnabled=!1,a.beginPath(),a.rect(0,0,s,s),a.clip(),a.clearRect(0,0,s,s),a.drawImage(i,0,0,s,s),a.drawImage(n,3*e[2],3*e[3]);const r=await o.convertToBlob({type:"image/png"});return"template"!=this.rt&&(this.ot=n,this.rt="template"),r}async Mt(t,e=3,s="image/png"){const n=await createImageBitmap(t);e|=1;const i=n.width*Math.round(e),o=n.height*Math.round(e),a=document.createElement("canvas");a.width=i,a.height=o;const r=a.getContext("2d");r.imageSmoothingEnabled=!1,r.drawImage(n,0,0,i,o);const c=r.getImageData(0,0,i,o);for(let t=0;t<o;t++)for(let s=0;s<i;s++)if(s%e!==1||t%e!==1){const e=4*(t*i+s);c.data[e+3]=0}return r.putImageData(c,0,0),new Promise(t=>{a.toBlob(t,s)})}}(c,l),p=new class{constructor(t){this.St=t,this.Ct=!1,this.Dt=[],this.kt=[]}Tt(t){window.addEventListener("message",async e=>{const s=e.data,n=s.jsonData;if(!s||"blue-marble"!==s.source)return;if(!s.endpoint)return;const i=s.endpoint?.split("?")[0].split("/").filter(t=>t&&isNaN(Number(t))).filter(t=>t&&!t.includes(".")).pop();switch(console.log(`%cBlue Marble%c: Recieved message about "${i}"`,"color: cornflowerblue;",""),i){case"me":if(n.status&&"2"!=n.status?.toString()[0])return void t.A("You are not logged in!\nCould not fetch userdata.");const e=Math.ceil(Math.pow(Math.floor(n.level)*Math.pow(30,.65),1/.65)-n.pixelsPainted);console.log(n.id),(n.id||0===n.id)&&console.log(r(n.id,"!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~")),this.St.K=n.id,t._("bm-j",`Username: <b>${function(t){const e=document.createElement("div");return e.textContent=t,e.innerHTML}(n.name)}</b>`),t._("bm-f",`Droplets: <b>${(new Intl.NumberFormat).format(n.droplets)}</b>`),t._("bm-a",`Next level in <b>${(new Intl.NumberFormat).format(e)}</b> pixel${1==e?"":"s"}`);break;case"pixel":const i=s.endpoint.split("?")[0].split("/").filter(t=>t&&!isNaN(Number(t))),c=new URLSearchParams(s.endpoint.split("?")[1]),l=[c.get("x"),c.get("y")];if(this.Dt.length&&(!i.length||!l.length))return void t.A("Coordinates are malformed!\nDid you try clicking the canvas first?");this.Dt=[...i,...l];const h=(o=i,a=l,[parseInt(o[0])%4*1e3+parseInt(a[0]),parseInt(o[1])%4*1e3+parseInt(a[1])]),m=document.querySelectorAll("span");for(const t of m)if(t.textContent.trim().includes(`${h[0]}, ${h[1]}`)){let e=document.querySelector("#bm-9");const s=`(Tl X: ${i[0]}, Tl Y: ${i[1]}, Px X: ${l[0]}, Px Y: ${l[1]})`;e?e.textContent=s:(e=document.createElement("span"),e.id="bm-9",e.textContent=s,e.style="margin-left: calc(var(--spacing)*3); font-size: small;",t.parentNode.parentNode.parentNode.insertAdjacentElement("afterend",e))}break;case"tiles":let d=s.endpoint.split("/");d=[parseInt(d[d.length-2]),parseInt(d[d.length-1].replace(".png",""))];const u=s.blobID,p=s.blobData;let b=p;this.kt?.length>=4&&d[0]==this.kt[0]&&d[1]==this.kt[1]&&(console.log(`templateState: ${this.St.rt||null}`),b=this.St.rt?await this.St.xt(p,this.kt):p),window.postMessage({source:"blue-marble",blobID:u,blobData:b,blink:s.blink});break;case"robots":this.Ct="false"==n.userscript?.toString().toLowerCase();break}var o,a})}}(u);d.I(p),d.O({id:"bm-p",style:"top: 10px; right: 75px;"}).O({id:"bm-b"}).O({id:"bm-k"}).N().L({alt:"Blue Marble Icon",src:"https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/dist/assets/Favicon.png"}).N().R(1,{textContent:c}).N().N().Y().N().O({id:"bm-4"}).P({id:"bm-j",textContent:"Username:"}).N().P({id:"bm-f",textContent:"Droplets:"}).N().P({id:"bm-a",textContent:"Next level in..."}).N().N().Y().N().O({id:"bm-3"}).G({id:"bm-g",textContent:"Stealth",checked:!0}).N().j({title:"Waits for the website to make requests, instead of sending requests."}).N().q().N().G({id:"bm-6",textContent:"Possessed",checked:!0}).N().j({title:"Controls the website as if it were possessed."}).N().q().N().O({id:"bm-c"}).X({id:"bm-h",className:"bm-t",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.k?.Dt;e?.[0]?(t._("bm-l",e?.[0]||""),t._("bm-m",e?.[1]||""),t._("bm-n",e?.[2]||""),t._("bm-o",e?.[3]||"")):t.A("Coordinates are malformed! Did you try clicking on the canvas first?")}}).N().F({type:"number",id:"bm-l",placeholder:"Tl X",min:0,max:2047,step:1,required:!0}).N().F({type:"number",id:"bm-m",placeholder:"Tl Y",min:0,max:2047,step:1,required:!0}).N().F({type:"number",id:"bm-n",placeholder:"Px X",min:0,max:2047,step:1,required:!0}).N().F({type:"number",id:"bm-o",placeholder:"Px Y",min:0,max:2047,step:1,required:!0}).N().N().W({id:"bm-2",textContent:"Upload Template",accept:"image/png, image/jpeg, image/webp, image/bmp, image/gif"}).N().O({id:"bm-0"}).X({id:"bm-i",textContent:"Enable"},(t,e)=>{e.onclick=()=>{const e=document.querySelector("#bm-2"),s=document.querySelector("#bm-l");if(!s.checkValidity())return s.reportValidity(),void t.A("Coordinates are malformed! Did you try clicking on the canvas first?");const n=document.querySelector("#bm-m");if(!n.checkValidity())return n.reportValidity(),void t.A("Coordinates are malformed! Did you try clicking on the canvas first?");const i=document.querySelector("#bm-n");if(!i.checkValidity())return i.reportValidity(),void t.A("Coordinates are malformed! Did you try clicking on the canvas first?");const o=document.querySelector("#bm-o");if(!o.checkValidity())return o.reportValidity(),void t.A("Coordinates are malformed! Did you try clicking on the canvas first?");e?.files[0]?(u.gt(e.files[0],e.files[0]?.name.replace(/\.[^/.]+$/,""),[Number(s.value),Number(n.value),Number(i.value),Number(o.value)]),t.U("Drew to canvas!")):t.A("No file selected!")}}).N().X({id:"bm-d",textContent:"Disable"}).N().N().J({id:d.T,placeholder:`Status: Sleeping...\nVersion: ${l}`,readOnly:!0}).N().O({id:"bm-1"}).O().X({id:"bm-7",className:"bm-t",textContent:"✈"}).N().X({id:"bm-8",className:"bm-t",innerHTML:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><polygon points="10,2 12,7.5 18,7.5 13.5,11.5 15.5,18 10,14 4.5,18 6.5,11.5 2,7.5 8,7.5" fill="white"></polygon></svg>'}).N().X({id:"bm-5",className:"bm-t",innerHTML:"🖌"}).N().X({id:"bm-K",className:"bm-t",innerHTML:"🎨"},(t,e)=>{e.addEventListener("click",()=>{window.open("https://pepoafonso.github.io/color_converter_wplace/","_blank","noopener noreferrer")})}).N().N().H({textContent:"Made by SwingTheVine",style:"margin-top: auto;"}).N().N().N().B(document.body),d.V("#bm-p","#bm-k"),p.Tt(d),function(...t){(0,console.log)(...t)}(`%c${c}%c (${l}) userscript has loaded!`,"color: cornflowerblue;","")})(); |