// ==UserScript== // @name Blue Marble // @namespace https://github.com/SwingTheVine/ // @version 0.81.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/a3b4a288514dc48a9232b1aeeb6b377af6fdfe7c/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 // @grant GM.setValue // @grant GM_getValue // @resource CSS-BM-File https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/a3b4a288514dc48a9232b1aeeb6b377af6fdfe7c/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)},o=(t,e,o)=>e.has(t)?n("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,o),i=(t,e,o)=>(((t,e)=>{e.has(t)||n("Cannot access private method")})(t,e),o),s=class{constructor(e,n){o(this,t),this.name=e,this.version=n,this.t=null,this.o="bm-b",this.i=null,this.l=null,this.m=[]}h(t){this.t=t}u(){return this.m.length>0&&(this.l=this.m.pop()),this}p(t){t?.appendChild(this.i),this.i=null,this.l=null,this.m=[]}$(n={},o=()=>{}){return o(this,i(this,t,e).call(this,"div",{},n)),this}v(n={},o=()=>{}){return o(this,i(this,t,e).call(this,"p",{},n)),this}M(n={},o=()=>{}){return o(this,i(this,t,e).call(this,"small",{},n)),this}D(n={},o=()=>{}){return o(this,i(this,t,e).call(this,"img",{},n)),this}S(n,o={},s=()=>{}){return s(this,i(this,t,e).call(this,"h"+n,{},o)),this}k(n={},o=()=>{}){return o(this,i(this,t,e).call(this,"hr",{},n)),this}C(n={},o=()=>{}){return o(this,i(this,t,e).call(this,"br",{},n)),this}T(n={},o=()=>{}){const s=i(this,t,e).call(this,"label",{textContent:n.textContent??""});delete n.textContent;const a=i(this,t,e).call(this,"input",{type:"checkbox"},n);return s.insertBefore(a,s.firstChild),this.u(),o(this,s,a),this}N(n={},o=()=>{}){return o(this,i(this,t,e).call(this,"button",{},n)),this}O(n={},o=()=>{}){const s=n.title??n.textContent??"Help: No info";delete n.textContent,n.title=`Help: ${s}`;const a={textContent:"?",className:"bm-q",onclick:()=>{this.B(this.o,s)}};return o(this,i(this,t,e).call(this,"button",a,n)),this}I(n={},o=()=>{}){return o(this,i(this,t,e).call(this,"input",{},n)),this}L(n={},o=()=>{}){const s=n.textContent??"";delete n.textContent;const a=i(this,t,e).call(this,"div"),r=i(this,t,e).call(this,"input",{type:"file",style:"display: none !important; visibility: hidden !important; position: absolute !important; left: -9999px !important; width: 0 !important; height: 0 !important; opacity: 0 !important;"},n);this.u();const c=i(this,t,e).call(this,"button",{textContent:s});return this.u(),this.u(),r.setAttribute("tabindex","-1"),r.setAttribute("aria-hidden","true"),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=s}),o(this,a,r,c),this}G(n={},o=()=>{}){return o(this,i(this,t,e).call(this,"textarea",{},n)),this}B(t,e,n=!1){const o=document.getElementById(t.replace(/^#/,""));o&&(o instanceof HTMLInputElement?o.value=e:n?o.textContent=e:o.innerHTML=e)}P(t,e){let n,o=!1,i=0,s=null,a=0,r=0,c=0,l=0;if(t=document.querySelector("#"==t?.[0]?t:"#"+t),e=document.querySelector("#"==e?.[0]?e:"#"+e),!t||!e)return void this.F(`Can not drag! ${t?"":"moveMe"} ${t||e?"":"and "}${e?"":"iMoveThings "}was not found!`);const m=()=>{if(o){const e=Math.abs(a-c),n=Math.abs(r-l);(e>.5||n>.5)&&(a=c,r=l,t.style.transform=`translate(${a}px, ${r}px)`,t.style.left="0px",t.style.top="0px",t.style.right=""),s=requestAnimationFrame(m)}};let h=null;const u=(u,b)=>{o=!0,h=t.getBoundingClientRect(),n=u-h.left,i=b-h.top;const d=window.getComputedStyle(t).transform;if(d&&"none"!==d){const t=new DOMMatrix(d);a=t.m41,r=t.m42}else a=h.left,r=h.top;c=a,l=r,document.body.style.userSelect="none",e.classList.add("dragging"),s&&cancelAnimationFrame(s),m()},b=()=>{o=!1,s&&(cancelAnimationFrame(s),s=null),document.body.style.userSelect="",e.classList.remove("dragging")};e.addEventListener("mousedown",function(t){t.preventDefault(),u(t.clientX,t.clientY)}),e.addEventListener("touchstart",function(t){const e=t?.touches?.[0];e&&(u(e.clientX,e.clientY),t.preventDefault())},{passive:!1}),document.addEventListener("mousemove",function(t){o&&h&&(c=t.clientX-n,l=t.clientY-i)},{passive:!0}),document.addEventListener("touchmove",function(t){if(o&&h){const e=t?.touches?.[0];if(!e)return;c=e.clientX-n,l=e.clientY-i,t.preventDefault()}},{passive:!1}),document.addEventListener("mouseup",b),document.addEventListener("touchend",b),document.addEventListener("touchcancel",b)}j(t){(0,console.info)(`${this.name}: ${t}`),this.B(this.o,"Status: "+t,!0)}F(t){(0,console.error)(`${this.name}: ${t}`),this.B(this.o,"Error: "+t,!0)}};function a(t,e){if(0===t)return e[0];let n="";const o=e.length;for(;t>0;)n=e[t%o]+n,t=Math.floor(t/o);return n}function r(t){let e="";for(let n=0;n=32)}}catch(t){}var m,h,u,b=class{constructor({displayName:t="My template",q:e=0,A:n="",url:o="",file:i=null,coords:s=null,J:a=null,H:r=1e3}={}){this.displayName=t,this.q=e,this.A=n,this.url=o,this.file=i,this.coords=s,this.J=a,this.H=r,this.Y=0,this._=0,this.X=0,this.V={},this.W=new Set,this.U=null;const c=Array.isArray(l)?l:[];this.Z=new Set(c.filter(t=>"transparent"!==(t?.name||"").toLowerCase()&&Array.isArray(t?.rgb)).map(t=>`${t.rgb[0]},${t.rgb[1]},${t.rgb[2]}`)),this.K=new Map(c.filter(t=>Array.isArray(t?.rgb)).map(t=>[`${t.rgb[0]},${t.rgb[1]},${t.rgb[2]}`,{id:t.id,R:!!t.R,name:t.name}]))}async tt(){console.log("Template coordinates:",this.coords);const t=await createImageBitmap(this.file),e=t.width,n=t.height,o=e*n;console.log(`Template pixel analysis - Dimensions: ${e}×${n} = ${o.toLocaleString()} pixels`),this.Y=o;try{const o=new OffscreenCanvas(e,n).getContext("2d",{et:!0});o.imageSmoothingEnabled=!1,o.clearRect(0,0,e,n),o.drawImage(t,0,0);const i=o.getImageData(0,0,e,n).data;let s=0,a=0;const r=new Map;for(let t=0;t0){for(const t in e){const n=t,o=e[t];if(console.log(n),e.hasOwnProperty(t)){const t=n.split(" "),i=Number(t?.[0]),s=t?.[1]||"0",a=o.name||`Template ${i||""}`,r=o.tiles,l={};let m=0;const h=new Map;for(const t in r)if(console.log(t),r.hasOwnProperty(t)){const e=c(r[t]),n=new Blob([e],{type:"image/png"}),o=await createImageBitmap(n);l[t]=o;try{const t=o.width,e=o.height,n=new OffscreenCanvas(t,e).getContext("2d",{et:!0});n.imageSmoothingEnabled=!1,n.clearRect(0,0,t,e),n.drawImage(o,0,0);const i=n.getImageData(0,0,t,e).data;for(let n=0;n{u.W?.add(t.split(",").slice(0,2).join(","))})}catch(t){}try{const t=e?.[n]?.palette;if(t)for(const[e,n]of Object.entries(t))u.V[e]?u.V[e].enabled=!!n?.enabled:u.V[e]={count:n?.count||0,enabled:!!n?.enabled}}catch(t){}u.U=n,this.rt.push(u),console.log(this.rt),console.log("^^^ This ^^^")}}try{const t=document.querySelector("#bm-y");t&&(t.style.display=""),window.postMessage({source:"blue-marble",ct:"bm-A"},"*")}catch(t){}}};var d=GM_info.script.name.toString(),p=GM_info.script.version.toString();!function(t){const e=document.createElement("script");e.setAttribute("bm-r",d),e.setAttribute("bm-o","color: cornflowerblue;"),e.textContent=`(${t})();`,document.documentElement?.appendChild(e),e.remove()}(()=>{const t=document.currentScript,e=t?.getAttribute("bm-r")||"Blue Marble",n=t?.getAttribute("bm-o")||"",o=new Map;window.addEventListener("message",t=>{const{source:i,endpoint:s,blobID:a,blobData:r,blink:c}=t.data,l=Date.now()-c;if(console.groupCollapsed(`%c${e}%c: ${o.size} Recieved IMAGE message about blob "${a}"`,n,""),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`,n,""),console.log(o),console.groupEnd(),"blue-marble"==i&&a&&r&&!s){const t=o.get(a);"function"==typeof t?t(r):function(...t){(0,console.warn)(...t)}(`%c${e}%c: Attempted to retrieve a blob (%s) from queue, but the blobID was not a function! Skipping...`,n,"",a),o.delete(a)}});const i=window.fetch;window.fetch=async function(...t){const s=await i.apply(this,t),a=s.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}"`,n,""),a.json().then(t=>{window.postMessage({source:"blue-marble",endpoint:r,jsonData:t},"*")}).catch(t=>{console.error(`%c${e}%c: Failed to parse JSON: `,n,"",t)});else if(c.includes("image/")&&!r.includes("openfreemap")&&!r.includes("maps")){const t=Date.now(),i=await a.blob();return console.log(`%c${e}%c: ${o.size} Sending IMAGE message about endpoint "${r}"`,n,""),new Promise(s=>{const c=crypto.randomUUID();o.set(c,t=>{s(new Response(t,{headers:a.headers,status:a.status,statusText:a.statusText})),console.log(`%c${e}%c: ${o.size} Processed blob "${c}"`,n,"")}),window.postMessage({source:"blue-marble",endpoint:r,blobID:c,blobData:i,blink:t})}).catch(i=>{const s=Date.now();console.error(`%c${e}%c: Failed to Promise blob!`,n,""),console.groupCollapsed(`%c${e}%c: Details of failed blob Promise:`,n,""),console.log(`Endpoint: ${r}\nThere are ${o.size} blobs processing...\nBlink: ${t.toLocaleString()}\nTime Since Blink: ${String(Math.floor(s/6e4)).padStart(2,"0")}:${String(Math.floor(s/1e3)%60).padStart(2,"0")}.${String(s%1e3).padStart(3,"0")} MM:SS.mmm`),console.error("Exception stack:",i),console.groupEnd()})}return s}});var g=GM_getResourceText("CSS-BM-File");GM_addStyle(g);var f=document.createElement("link");f.href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap",f.rel="preload",f.as="style",f.onload=function(){this.onload=null,this.rel="stylesheet"},document.head?.appendChild(f),new class{constructor(){this.lt=null,this.ht=null,this.ut="#bm-5"}bt(t){return this.ht=t,this.lt=new MutationObserver(t=>{for(const e of t)for(const t of e.addedNodes)t instanceof HTMLElement&&t.matches?.(this.ut)}),this}dt(){return this.lt}observe(t,e=!1,n=!1){t.observe(this.ht,{childList:e,subtree:n})}};var w=new s(d,p),$=(new s(d,p),new class{constructor(t,e,n){o(this,m),this.name=t,this.version=e,this.i=n,this.gt="1.0.0",this.ft=null,this.wt="!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~",this.H=1e3,this.st=3,this.$t=null,this.yt=null,this.xt="bm-p",this.vt="div#map canvas.maplibregl-canvas",this.Mt=null,this.Dt="",this.rt=[],this.it=null,this.St=!0,this.kt=new Map}Ct(){if(document.body.contains(this.$t))return this.$t;document.getElementById(this.xt)?.remove();const t=document.querySelector(this.vt),e=document.createElement("canvas");return e.id=this.xt,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.$t=e,window.addEventListener("move",this.Tt),window.addEventListener("zoom",this.Nt),window.addEventListener("resize",this.Ot),this.$t}async Bt(){return{whoami:this.name.replace(" ",""),scriptVersion:this.version,schemaVersion:this.gt,templates:{}}}async It(t,e,n){this.it||(this.it=await this.Bt(),console.log("Creating JSON...")),this.i.j(`Creating template at ${n.join(", ")}...`);const o=new b({displayName:e,q:0,A:a(this.ft||0,this.wt),file:t,coords:n}),{nt:s,ot:r}=await o.tt(this.H);o.J=s;const c=`${o.q} ${o.A}`;o.U=c,this.it.templates[c]={name:o.displayName,coords:n.join(", "),enabled:!0,tiles:r,palette:o.V},this.rt=[],this.rt.push(o);const l=(new Intl.NumberFormat).format(o.Y);this.i.j(`Template created at ${n.join(", ")}! Total pixels: ${l}`);try{const t=document.querySelector("#bm-y");t&&(t.style.display=""),window.postMessage({source:"blue-marble",ct:"bm-A"},"*")}catch(t){}console.log(Object.keys(this.it.templates).length),console.log(this.it),console.log(this.rt),console.log(JSON.stringify(this.it)),await i(this,m,h).call(this)}Lt(){}async Gt(){this.it||(this.it=await this.Bt(),console.log("Creating JSON..."))}async Pt(t,e){if(!this.St)return t;const n=this.H*this.st;e=e[0].toString().padStart(4,"0")+","+e[1].toString().padStart(4,"0"),console.log(`Searching for templates in tile: "${e}"`);const o=this.rt;if(console.log(o),o.sort((t,e)=>t.q-e.q),console.log(o),!o.some(t=>!!t?.J&&(t.W&&t.W.size>0?t.W.has(e):Object.keys(t.J).some(t=>t.startsWith(e)))))return t;const i=o.map(t=>{const n=Object.keys(t.J).filter(t=>t.startsWith(e));if(0===n.length)return null;const o=n.map(e=>{const n=e.split(",");return{Ft:t.J[e],jt:[n[0],n[1]],Et:[n[2],n[3]]}});return o?.[0]}).filter(Boolean);console.log(i);const s=i?.length||0;console.log(`templateCount = ${s}`);let a=0,r=0,c=0;const l=await createImageBitmap(t),m=new OffscreenCanvas(n,n),h=m.getContext("2d");h.imageSmoothingEnabled=!1,h.beginPath(),h.rect(0,0,n,n),h.clip(),h.clearRect(0,0,n,n),h.drawImage(l,0,0,n,n);let u=null;try{u=h.getImageData(0,0,n,n).data}catch(t){}for(const t of i){if(console.log("Template:"),console.log(t),u)try{const e=t.Ft.width,o=t.Ft.height,i=new OffscreenCanvas(e,o).getContext("2d",{et:!0});i.imageSmoothingEnabled=!1,i.clearRect(0,0,e,o),i.drawImage(t.Ft,0,0);const s=i.getImageData(0,0,e,o).data,l=Number(t.Et[0])*this.st,m=Number(t.Et[1])*this.st;for(let t=0;t=n||h>=n)continue;const b=4*(t*e+o),d=s[b],p=s[b+1],g=s[b+2];if(s[b+3]<64)continue;if(222===d&&250===p&&206===g)continue;try{const t=this.rt?.[0];if(t?.Z&&!t.Z.has(`${d},${p},${g}`))continue}catch(t){}c++;const f=4*(h*n+i),w=u[f],$=u[f+1],y=u[f+2];u[f+3]<64||(w===d&&$===p&&y===g?a++:r++)}}catch(t){console.warn("Failed to compute per-tile painted/wrong stats:",t)}try{const e=this.rt?.[0],n=e?.V||{};if(Object.values(n).some(t=>!1===t?.enabled)){const o=t.Ft.width,i=t.Ft.height,s=new OffscreenCanvas(o,i),a=s.getContext("2d",{et:!0});a.imageSmoothingEnabled=!1,a.clearRect(0,0,o,i),a.drawImage(t.Ft,0,0);const r=a.getImageData(0,0,o,i),c=r.data;for(let t=0;t0){const t=e;this.kt.set(t,{Rt:a,required:c,qt:r});let n=0,o=0,i=0;for(const t of this.kt.values())n+=t.Rt||0,o+=t.required||0,i+=t.qt||0;const l=this.rt.reduce((t,e)=>t+(e._||e.Y||0),0),m=l>0?l:o,h=(new Intl.NumberFormat).format(n),u=(new Intl.NumberFormat).format(m),b=(new Intl.NumberFormat).format(i);this.i.j(`Displaying ${s} template${1==s?"":"s"}.\nPainted ${h} / ${u} • Wrong ${b}`)}else this.i.j(`Displaying ${s} templates.`);return await m.convertToBlob({type:"image/png"})}At(t){console.log("Importing JSON..."),console.log(t),"BlueMarble"==t?.whoami&&i(this,m,u).call(this,t)}Jt(t){this.St=t}}(d,p,w)),y=new class{constructor(t){this.zt=t,this.Ht=!1,this.Yt=[],this._t=[]}Xt(t){window.addEventListener("message",async e=>{const n=e.data,o=n.jsonData;if(!n||"blue-marble"!==n.source)return;if(!n.endpoint)return;const i=n.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 "%s"',"color: cornflowerblue;","",i),i){case"me":if(o.status&&"2"!=o.status?.toString()[0])return void t.F("You are not logged in!\nCould not fetch userdata.");const e=Math.ceil(Math.pow(Math.floor(o.level)*Math.pow(30,.65),1/.65)-o.pixelsPainted);console.log(o.id),(o.id||0===o.id)&&console.log(a(o.id,"!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~")),this.zt.ft=o.id,t.B("bm-h",`Username: ${function(t){const e=document.createElement("div");return e.textContent=t,e.innerHTML}(o.name)}`),t.B("bm-c",`Droplets: ${(new Intl.NumberFormat).format(o.droplets)}`),t.B("bm-6",`Next level in ${(new Intl.NumberFormat).format(e)} pixel${1==e?"":"s"}`);break;case"pixel":const i=n.endpoint.split("?")[0].split("/").filter(t=>t&&!isNaN(Number(t))),c=new URLSearchParams(n.endpoint.split("?")[1]),l=[c.get("x"),c.get("y")];if(this.Yt.length&&(!i.length||!l.length))return void t.F("Coordinates are malformed!\nDid you try clicking the canvas first?");this.Yt=[...i,...l];const m=(s=i,r=l,[parseInt(s[0])%4*1e3+parseInt(r[0]),parseInt(s[1])%4*1e3+parseInt(r[1])]),h=document.querySelectorAll("span");for(const t of h)if(t.textContent.trim().includes(`${m[0]}, ${m[1]}`)){let e=document.querySelector("#bm-5");const n=`(Tl X: ${i[0]}, Tl Y: ${i[1]}, Px X: ${l[0]}, Px Y: ${l[1]})`;e?e.textContent=n:(e=document.createElement("span"),e.id="bm-5",e.textContent=n,e.style="margin-left: calc(var(--spacing)*3); font-size: small;",t.parentNode.parentNode.parentNode.insertAdjacentElement("afterend",e))}break;case"tiles":let u=n.endpoint.split("/");u=[parseInt(u[u.length-2]),parseInt(u[u.length-1].replace(".png",""))];const b=n.blobID,d=n.blobData,p=await this.zt.Pt(d,u);window.postMessage({source:"blue-marble",blobID:b,blobData:p,blink:n.blink});break;case"robots":this.Ht="false"==o.userscript?.toString().toLowerCase();break}var s,r})}}($);w.h(y);var x=JSON.parse(GM_getValue("bmTemplates","{}"));console.log(x),$.At(x),function(){let t=!1,e={};try{e=JSON.parse(GM_getValue("bmCoords","{}"))||{}}catch(t){e={}}const n=()=>{try{const t=Number(document.querySelector("#bm-j")?.value||""),e=Number(document.querySelector("#bm-k")?.value||""),n={Vt:t,Wt:e,px:Number(document.querySelector("#bm-l")?.value||""),Ut:Number(document.querySelector("#bm-m")?.value||"")};GM.setValue("bmCoords",JSON.stringify(n))}catch(t){}};w.$({id:"bm-n",style:"top: 10px; right: 75px;"}).$({id:"bm-7"}).$({id:"bm-i"}).u().D({alt:"Blue Marble Icon - Click to minimize/maximize",src:"https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/dist/assets/Favicon.png",style:"cursor: pointer;"},(e,n)=>{n.addEventListener("click",()=>{t=!t;const o=document.querySelector("#bm-n"),i=document.querySelector("#bm-7"),s=document.querySelector("#bm-i"),a=document.querySelector("#bm-8"),r=document.querySelector("#bm-d"),c=document.querySelector("#bm-e"),l=document.querySelector("#bm-f"),m=document.querySelector("#bm-9"),h=document.querySelectorAll("#bm-8 input");t||(o.style.width="auto",o.style.maxWidth="300px",o.style.minWidth="200px",o.style.padding="10px"),["#bm-n h1","#bm-4","#bm-n hr","#bm-3 > *:not(#bm-8)","#bm-2","#bm-1",`#${e.o}`,"#bm-y"].forEach(e=>{document.querySelectorAll(e).forEach(e=>{e.style.display=t?"none":""})}),t?(a&&(a.style.display="none"),r&&(r.style.display="none"),c&&(c.style.display="none"),l&&(l.style.display="none"),m&&(m.style.display="none"),h.forEach(t=>{t.style.display="none"}),o.style.width="60px",o.style.height="76px",o.style.maxWidth="60px",o.style.minWidth="60px",o.style.padding="8px",n.style.marginLeft="3px",i.style.textAlign="center",i.style.margin="0",i.style.marginBottom="0",s&&(s.style.display="",s.style.marginBottom="0.25em")):(a&&(a.style.display="",a.style.flexDirection="",a.style.justifyContent="",a.style.alignItems="",a.style.gap="",a.style.textAlign="",a.style.margin=""),r&&(r.style.display=""),c&&(c.style.display="",c.style.marginTop=""),l&&(l.style.display="",l.style.marginTop=""),m&&(m.style.display="",m.style.marginTop=""),h.forEach(t=>{t.style.display=""}),n.style.marginLeft="",o.style.padding="10px",i.style.textAlign="",i.style.margin="",i.style.marginBottom="",s&&(s.style.marginBottom="0.5em"),o.style.width="",o.style.height=""),n.alt=t?"Blue Marble Icon - Minimized (Click to maximize)":"Blue Marble Icon - Maximized (Click to minimize)"})}).u().S(1,{textContent:d}).u().u().k().u().$({id:"bm-4"}).v({id:"bm-h",textContent:"Username:"}).u().v({id:"bm-c",textContent:"Droplets:"}).u().v({id:"bm-6",textContent:"Next level in..."}).u().u().k().u().$({id:"bm-3"}).$({id:"bm-8"}).N({id:"bm-d",className:"bm-q",style:"margin-top: 0;",innerHTML:''},(t,e)=>{e.onclick=()=>{const e=t.t?.Yt;e?.[0]?(t.B("bm-j",e?.[0]||""),t.B("bm-k",e?.[1]||""),t.B("bm-l",e?.[2]||""),t.B("bm-m",e?.[3]||""),n()):t.F("Coordinates are malformed! Did you try clicking on the canvas first?")}}).u().I({type:"number",id:"bm-j",placeholder:"Tl X",min:0,max:2047,step:1,required:!0,value:e.Vt??""},(t,e)=>{const o=()=>n();e.addEventListener("input",o),e.addEventListener("change",o)}).u().I({type:"number",id:"bm-k",placeholder:"Tl Y",min:0,max:2047,step:1,required:!0,value:e.Wt??""},(t,e)=>{const o=()=>n();e.addEventListener("input",o),e.addEventListener("change",o)}).u().I({type:"number",id:"bm-l",placeholder:"Px X",min:0,max:2047,step:1,required:!0,value:e.px??""},(t,e)=>{const o=()=>n();e.addEventListener("input",o),e.addEventListener("change",o)}).u().I({type:"number",id:"bm-m",placeholder:"Px Y",min:0,max:2047,step:1,required:!0,value:e.Ut??""},(t,e)=>{const o=()=>n();e.addEventListener("input",o),e.addEventListener("change",o)}).u().u().$({id:"bm-y",style:"max-height: 140px; overflow: auto; border: 1px solid rgba(255,255,255,0.1); padding: 4px; border-radius: 4px; display: none;"}).$({style:"display: flex; gap: 6px; margin-bottom: 6px;"}).N({id:"bm-v",textContent:"Enable All"},(t,e)=>{e.onclick=()=>{const e=$.rt[0];e?.V&&(Object.values(e.V).forEach(t=>t.enabled=!0),buildColorFilterList(),t.j("Enabled all colors"))}}).u().N({id:"bm-u",textContent:"Disable All"},(t,e)=>{e.onclick=()=>{const e=$.rt[0];e?.V&&(Object.values(e.V).forEach(t=>t.enabled=!1),buildColorFilterList(),t.j("Disabled all colors"))}}).u().u().$({id:"bm-D"}).u().u().L({id:"bm-2",textContent:"Upload Template",accept:"image/png, image/jpeg, image/webp, image/bmp, image/gif"}).u().$({id:"bm-0"}).N({id:"bm-f",textContent:"Enable"},(t,e)=>{e.onclick=()=>{t.t?.zt?.Jt(!0),t.j("Enabled templates!")}}).u().N({id:"bm-e",textContent:"Create"},(t,e)=>{e.onclick=()=>{const e=document.querySelector("#bm-2"),n=document.querySelector("#bm-j");if(!n.checkValidity())return n.reportValidity(),void t.F("Coordinates are malformed! Did you try clicking on the canvas first?");const o=document.querySelector("#bm-k");if(!o.checkValidity())return o.reportValidity(),void t.F("Coordinates are malformed! Did you try clicking on the canvas first?");const i=document.querySelector("#bm-l");if(!i.checkValidity())return i.reportValidity(),void t.F("Coordinates are malformed! Did you try clicking on the canvas first?");const s=document.querySelector("#bm-m");if(!s.checkValidity())return s.reportValidity(),void t.F("Coordinates are malformed! Did you try clicking on the canvas first?");e?.files[0]?($.It(e.files[0],e.files[0]?.name.replace(/\.[^/.]+$/,""),[Number(n.value),Number(o.value),Number(i.value),Number(s.value)]),t.j("Drew to canvas!")):t.F("No file selected!")}}).u().N({id:"bm-9",textContent:"Disable"},(t,e)=>{e.onclick=()=>{t.t?.zt?.Jt(!1),t.j("Disabled templates!")}}).u().u().G({id:w.o,placeholder:`Status: Sleeping...\nVersion: ${p}`,readOnly:!0}).u().$({id:"bm-1"}).$().N({id:"bm-a",className:"bm-q",innerHTML:"🎨",title:"Template Color Converter"},(t,e)=>{e.addEventListener("click",()=>{window.open("https://pepoafonso.github.io/color_converter_wplace/","_blank","noopener noreferrer")})}).u().u().M({textContent:"Made by SwingTheVine",style:"margin-top: auto;"}).u().u().u().p(document.body),window.buildColorFilterList=function(){const t=document.querySelector("#bm-D"),e=$.rt?.[0];if(!t||!e?.V)return void(t&&(t.innerHTML="No template colors to display."));t.innerHTML="";const n=Object.entries(e.V).sort((t,e)=>e[1].count-t[1].count);for(const[e,o]of n){const[n,i,s]=e.split(",").map(Number),a=document.createElement("div");a.style.display="flex",a.style.alignItems="center",a.style.gap="8px",a.style.margin="4px 0";const r=document.createElement("div");r.style.width="14px",r.style.height="14px",r.style.border="1px solid rgba(255,255,255,0.5)",r.style.background=`rgb(${n},${i},${s})`;const c=document.createElement("span");c.style.fontSize="12px";let l=`${o.count.toLocaleString()}`;try{const t=$.rt?.[0]?.K?.get(e);if(t&&"number"==typeof t.id){const e=t?.name||`rgb(${n},${i},${s})`,o=t.R?"★ ":"";l=`#${t.id} ${o}${e} • ${l}`}}catch(t){}c.textContent=l;const m=document.createElement("input");m.type="checkbox",m.checked=!!o.enabled,m.addEventListener("change",()=>{o.enabled=m.checked,w.j(`${m.checked?"Enabled":"Disabled"} ${e}`);try{const t=$.rt?.[0],e=t?.U;t&&e&&$.it?.templates?.[e]&&($.it.templates[e].palette=t.V,GM.setValue("bmTemplates",JSON.stringify($.it)))}catch(t){}}),a.appendChild(m),a.appendChild(r),a.appendChild(c),t.appendChild(a)}},window.addEventListener("message",t=>{if("bm-A"===t?.data?.ct)try{buildColorFilterList()}catch(t){}}),setTimeout(()=>{try{if($.rt?.length>0){const t=document.querySelector("#bm-y");t&&(t.style.display=""),buildColorFilterList()}}catch(t){}},0)}(),w.P("#bm-n","#bm-i"),y.Xt(w),new MutationObserver((t,e)=>{const n=document.querySelector("#color-1");if(!n)return;let o=document.querySelector("#bm-g");if(!o){o=document.createElement("button"),o.id="bm-g",o.textContent="Move ↑",o.className="btn btn-soft",o.onclick=function(){const t=this.parentNode.parentNode.parentNode.parentNode,e="Move ↑"==this.textContent;t.parentNode.className=t.parentNode.className.replace(e?"bottom":"top",e?"top":"bottom"),t.style.borderTopLeftRadius=e?"0px":"var(--radius-box)",t.style.borderTopRightRadius=e?"0px":"var(--radius-box)",t.style.borderBottomLeftRadius=e?"var(--radius-box)":"0px",t.style.borderBottomRightRadius=e?"var(--radius-box)":"0px",this.textContent=e?"Move ↓":"Move ↑"};const t=n.parentNode.parentNode.parentNode.parentNode.querySelector("h2");t.parentNode?.appendChild(o)}}).observe(document.body,{childList:!0,subtree:!0}),function(...t){(0,console.log)(...t)}(`%c${d}%c (${p}) userscript has loaded!`,"color: cornflowerblue;","")})();