// ==UserScript==
// @name            Blue Marble
// @name:en         Blue Marble
// @namespace       https://github.com/SwingTheVine/
// @version         0.88.425
// @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.
// @description:en  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://bluemarble.lol/
// @icon64          data:image/png;base64,[encoded data, 4716 characters]
// @updateURL       https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/dist/BlueMarble-Standalone.user.js
// @downloadURL     https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/dist/BlueMarble-Standalone.user.js
// @match           https://wplace.live/*
// @grant           GM_getResourceText
// @grant           GM_addStyle
// @grant           GM.setValue
// @grant           GM_getValue
// @grant           GM_xmlhttpRequest
// @connect         telemetry.thebluecorner.net
// @antifeature     tracking Anonymous opt-in telemetry data
// @noframes
// ==/UserScript==

// Wplace  --> https://wplace.live
// License --> https://www.mozilla.org/en-US/MPL/2.0/
// Donate  --> https://ko-fi.com/swingthevine

(()=>{var t=t=>{throw TypeError(t)},e=(e,i,n)=>i.has(e)?t("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(e):i.set(e,n),i=(e,i,n)=>(((e,i)=>{i.has(e)||t("Cannot access private method")})(e,i),n);function n(t){const e=document.createElement("div");return e.textContent=t,e.innerHTML}function s(...t){(0,console.error)(...t)}function o(t,e){if(0===t)return e[0];let i="";const n=e.length;for(;t>0;)i=e[t%n]+i,t=Math.floor(t/n);return i}function a(t){let e="";for(let i=0;i<t.length;i++)e+=String.fromCharCode(t[i]);return btoa(e)}function r(t){const e=atob(t),i=new Uint8Array(e.length);for(let t=0;t<e.length;t++)i[t]=e.charCodeAt(t);return i}function l(t){const e=t.map(t=>(t/=255)<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4));return.2126*e[0]+.7152*e[1]+.0722*e[2]}var c,h,m,d,u,b,p=[{id:0,premium:!1,name:"Transparent",rgb:[0,0,0]},{id:1,premium:!1,name:"Black",rgb:[0,0,0]},{id:2,premium:!1,name:"Dark Gray",rgb:[60,60,60]},{id:3,premium:!1,name:"Gray",rgb:[120,120,120]},{id:4,premium:!1,name:"Light Gray",rgb:[210,210,210]},{id:5,premium:!1,name:"White",rgb:[255,255,255]},{id:6,premium:!1,name:"Deep Red",rgb:[96,0,24]},{id:7,premium:!1,name:"Red",rgb:[237,28,36]},{id:8,premium:!1,name:"Orange",rgb:[255,127,39]},{id:9,premium:!1,name:"Gold",rgb:[246,170,9]},{id:10,premium:!1,name:"Yellow",rgb:[249,221,59]},{id:11,premium:!1,name:"Light Yellow",rgb:[255,250,188]},{id:12,premium:!1,name:"Dark Green",rgb:[14,185,104]},{id:13,premium:!1,name:"Green",rgb:[19,230,123]},{id:14,premium:!1,name:"Light Green",rgb:[135,255,94]},{id:15,premium:!1,name:"Dark Teal",rgb:[12,129,110]},{id:16,premium:!1,name:"Teal",rgb:[16,174,166]},{id:17,premium:!1,name:"Light Teal",rgb:[19,225,190]},{id:18,premium:!1,name:"Dark Blue",rgb:[40,80,158]},{id:19,premium:!1,name:"Blue",rgb:[64,147,228]},{id:20,premium:!1,name:"Cyan",rgb:[96,247,242]},{id:21,premium:!1,name:"Indigo",rgb:[107,80,246]},{id:22,premium:!1,name:"Light Indigo",rgb:[153,177,251]},{id:23,premium:!1,name:"Dark Purple",rgb:[120,12,153]},{id:24,premium:!1,name:"Purple",rgb:[170,56,185]},{id:25,premium:!1,name:"Light Purple",rgb:[224,159,249]},{id:26,premium:!1,name:"Dark Pink",rgb:[203,0,122]},{id:27,premium:!1,name:"Pink",rgb:[236,31,128]},{id:28,premium:!1,name:"Light Pink",rgb:[243,141,169]},{id:29,premium:!1,name:"Dark Brown",rgb:[104,70,52]},{id:30,premium:!1,name:"Brown",rgb:[149,104,42]},{id:31,premium:!1,name:"Beige",rgb:[248,178,119]},{id:32,premium:!0,name:"Medium Gray",rgb:[170,170,170]},{id:33,premium:!0,name:"Dark Red",rgb:[165,14,30]},{id:34,premium:!0,name:"Light Red",rgb:[250,128,114]},{id:35,premium:!0,name:"Dark Orange",rgb:[228,92,26]},{id:36,premium:!0,name:"Light Tan",rgb:[214,181,148]},{id:37,premium:!0,name:"Dark Goldenrod",rgb:[156,132,49]},{id:38,premium:!0,name:"Goldenrod",rgb:[197,173,49]},{id:39,premium:!0,name:"Light Goldenrod",rgb:[232,212,95]},{id:40,premium:!0,name:"Dark Olive",rgb:[74,107,58]},{id:41,premium:!0,name:"Olive",rgb:[90,148,74]},{id:42,premium:!0,name:"Light Olive",rgb:[132,197,115]},{id:43,premium:!0,name:"Dark Cyan",rgb:[15,121,159]},{id:44,premium:!0,name:"Light Cyan",rgb:[187,250,242]},{id:45,premium:!0,name:"Light Blue",rgb:[125,199,255]},{id:46,premium:!0,name:"Dark Indigo",rgb:[77,49,184]},{id:47,premium:!0,name:"Dark Slate Blue",rgb:[74,66,132]},{id:48,premium:!0,name:"Slate Blue",rgb:[122,113,196]},{id:49,premium:!0,name:"Light Slate Blue",rgb:[181,174,241]},{id:50,premium:!0,name:"Light Brown",rgb:[219,164,99]},{id:51,premium:!0,name:"Dark Beige",rgb:[209,128,81]},{id:52,premium:!0,name:"Light Beige",rgb:[255,197,165]},{id:53,premium:!0,name:"Dark Peach",rgb:[155,82,73]},{id:54,premium:!0,name:"Peach",rgb:[209,128,120]},{id:55,premium:!0,name:"Light Peach",rgb:[250,182,164]},{id:56,premium:!0,name:"Dark Tan",rgb:[123,99,82]},{id:57,premium:!0,name:"Tan",rgb:[156,132,107]},{id:58,premium:!0,name:"Dark Slate",rgb:[51,57,65]},{id:59,premium:!0,name:"Slate",rgb:[109,117,141]},{id:60,premium:!0,name:"Light Slate",rgb:[179,185,209]},{id:61,premium:!0,name:"Dark Stone",rgb:[109,100,63]},{id:62,premium:!0,name:"Stone",rgb:[148,140,107]},{id:63,premium:!0,name:"Light Stone",rgb:[205,197,158]}],f=class{constructor({displayName:t="My template",t:i=0,i:n="",url:s="",file:o=null,coords:a=null,o:r=null,l:l={},h:h=1e3}={}){e(this,c),this.displayName=t,this.t=i,this.i=n,this.url=s,this.file=o,this.coords=a,this.o=r,this.l=l,this.h=h,this.m={total:0,colors:new Map}}async u(t,e){console.log("Template coordinates:",this.coords);const n=await createImageBitmap(this.file),s=n.width,o=n.height;this.h=t;const r={},l={},m=new OffscreenCanvas(this.h,this.h),d=m.getContext("2d",{p:!0});m.width=s,m.height=o,d.imageSmoothingEnabled=!1,d.drawImage(n,0,0);let u=Date.now();const b=i(this,c,h).call(this,d.getImageData(0,0,s,o),e);console.log(`Calculating total pixels took ${(Date.now()-u)/1e3} seconds`);let p=0;for(const[t,e]of b)0!=t&&(p+=e);this.m={total:p,colors:b},u=Date.now();const f=new OffscreenCanvas(3,3),g=f.getContext("2d");g.clearRect(0,0,3,3),g.fillStyle="white",g.fillRect(1,1,1,1);for(let t=this.coords[3];t<o+this.coords[3];){const e=Math.min(this.h-t%this.h,o-(t-this.coords[3]));console.log(`Math.min(${this.h} - (${t} % ${this.h}), ${o} - (${t-this.coords[3]}))`);for(let i=this.coords[2];i<s+this.coords[2];){console.log(`Pixel X: ${i}\nPixel Y: ${t}`);const o=Math.min(this.h-i%this.h,s-(i-this.coords[2]));console.log(`Math.min(${this.h} - (${i} % ${this.h}), ${s} - (${i-this.coords[2]}))`),console.log(`Draw Size X: ${o}\nDraw Size Y: ${e}`);const c=3*o,h=3*e;m.width=c,m.height=h,console.log(`Draw X: ${o}\nDraw Y: ${e}\nCanvas Width: ${c}\nCanvas Height: ${h}`),d.imageSmoothingEnabled=!1,console.log(`Getting X ${i}-${i+o}\nGetting Y ${t}-${t+e}`),d.clearRect(0,0,c,h),d.drawImage(n,i-this.coords[2],t-this.coords[3],o,e,0,0,3*o,3*e),d.save(),d.globalCompositeOperation="destination-in",d.fillStyle=d.createPattern(f,"repeat"),d.fillRect(0,0,c,h),d.restore();const u=d.getImageData(0,0,c,h);console.log(`Shreaded pixels for ${i}, ${t}`,u);const b=`${(this.coords[0]+Math.floor(i/1e3)).toString().padStart(4,"0")},${(this.coords[1]+Math.floor(t/1e3)).toString().padStart(4,"0")},${(i%1e3).toString().padStart(3,"0")},${(t%1e3).toString().padStart(3,"0")}`;this.l[b]=new Uint32Array(u.data.buffer),r[b]=await createImageBitmap(m);const p=await m.convertToBlob(),g=await p.arrayBuffer(),w=Array.from(new Uint8Array(g));l[b]=a(w),console.log(r),i+=o}t+=e}return console.log(`Parsing template took ${(Date.now()-u)/1e3} seconds`),console.log("Template Tiles: ",r),console.log("Template Tiles Buffers: ",l),console.log("Template Tiles Uint32Array: ",this.l),{v:r,$:l}}};c=new WeakSet,h=function(t,e){const i=new Uint32Array(t.data.buffer),{palette:n,M:s}=e,o=new Map;for(let t=0;t<i.length;t++){const e=i[t];let n=-2;n=e>>>24==0?0:s.get(e)??-2;const a=o.get(n);o.set(n,a?a+1:1)}return console.log(o),o},m=new WeakSet,d=async function(){GM.setValue("bmTemplates",JSON.stringify(this.S))},u=async function(t){console.log("Parsing BlueMarble...");const e=t.templates;if(console.log(`BlueMarble length: ${Object.keys(e).length}`),Object.keys(e).length>0)for(const t in e){const i=t,n=e[t];if(console.log(`Template Key: ${i}`),e.hasOwnProperty(t)){const t=i.split(" "),e=Number(t?.[0]),s=t?.[1]||"0",o=n.name||`Template ${e||""}`,a={total:n.pixels.total,colors:new Map(Object.entries(n.pixels.colors).map(([t,e])=>[Number(t),e]))},l=n.tiles,c={},h={},m=this.h*this.T;for(const t in l)if(console.log(t),l.hasOwnProperty(t)){const e=r(l[t]),i=new Blob([e],{type:"image/png"}),n=await createImageBitmap(i);c[t]=n;const s=new OffscreenCanvas(m,m).getContext("2d");s.drawImage(n,0,0);const o=s.getImageData(0,0,n.width,n.height);h[t]=new Uint32Array(o.data.buffer)}const d=new f({displayName:o,t:e||this.C?.length||0,i:s||""});d.m=a,d.o=c,d.l=h,this.C.push(d),console.log(this.C),console.log("^^^ This ^^^")}}},b=function({D:t,O:e,k:i}){const n=this.T,s=this.h*n,o=i[0],a=i[1],r=i[2],l=i[3],c=this.L,{palette:h,M:m}=this.N,d=new Map;for(let i=1;i<l;i+=n)for(let l=1;l<r;l+=n){const h=a+i+-1,u=o+l+0,b=t[h*s+u],p=e[i*r+l],f=p>>>24&255,g=b>>>24&255,w=m.get(p)??-2;if(this.B.get(w)&&(e[i*r+l]=b),-1==w){const t=536870912;this.B.get(w)?e[i*r+l]=0:(h/n&1)==(u/n&1)?(e[i*r+l]=t,e[(i-1)*r+(l-1)]=t,e[(i-1)*r+(l+1)]=t,e[(i+1)*r+(l-1)]=t,e[(i+1)*r+(l+1)]=t):(e[i*r+l]=0,e[(i-1)*r+l]=t,e[(i+1)*r+l]=t,e[i*r+(l-1)]=t,e[i*r+(l+1)]=t)}if(-1==w&&b<=c){const t=d.get(w);d.set(w,t?t+1:1);continue}if(f<=c||g<=c)continue;if((m.get(b)??-2)!=w)continue;const y=d.get(w);d.set(w,y?y+1:1)}return console.log("List of template pixels that match the tile:"),console.log(d),{I:d,P:e}};var g,w,y,v=class{constructor(){this.A=Math.ceil(80/1300*window.innerWidth),this.H=p.slice(1)}U(t){const e=document.createElement("div");for(let t=0;t<this.A;t++){const t=document.createElement("confetti-piece");t.style.setProperty("--x",100*Math.random()+"vw"),t.style.setProperty("--delay",2*Math.random()+"s"),t.style.setProperty("--duration",3+3*Math.random()+"s"),t.style.setProperty("--rot",360*Math.random()+"deg"),t.style.setProperty("--size",6+6*Math.random()+"px"),t.style.backgroundColor=`rgb(${this.H[Math.floor(Math.random()*this.H.length)].rgb.join(",")})`,t.onanimationend=()=>{t.parentNode.childElementCount<=1?t.parentNode.remove():t.remove()},e.appendChild(t)}t.appendChild(e)}},x=class extends HTMLElement{};customElements.define("confetti-piece",x);var $,M,S,T,C=class{constructor(t,i){e(this,g),this.name=t,this.version=i,this.W=null,this.G="bm-o",this.F=null,this.Y=null,this._=[]}j(t){this.W=t}X(){return this._.length>0&&(this.Y=this._.pop()),this}R(t){t?.appendChild(this.F),this.F=null,this.Y=null,this._=[]}J(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"div",{},t)),this}V(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"p",{},t)),this}q(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"small",{},t)),this}K(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"span",{},t)),this}Z(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"details",{},t)),this}tt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"summary",{},t)),this}et(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"img",{},t)),this}it(t,e={},n=()=>{}){return n(this,i(this,g,w).call(this,"h"+t,{},e)),this}nt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"hr",{},t)),this}st(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"br",{},t)),this}ot(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"form",{},t)),this}rt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"fieldset",{},t)),this}lt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"legend",{},t)),this}ct(t={},e=()=>{}){const n=i(this,g,w).call(this,"label",{textContent:t.textContent??""});delete t.textContent;const s=i(this,g,w).call(this,"input",{type:"checkbox"},t);return n.insertBefore(s,n.firstChild),this.X(),e(this,n,s),this}ht(t={},e=()=>{}){const n=i(this,g,w).call(this,"label",{textContent:t.textContent??"",for:t.id??""});return delete t.textContent,this.X(),e(this,n,i(this,g,w).call(this,"select",{},t)),this}dt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"option",{},t)),this}ut(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"ol",{},t)),this}bt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"ul",{},t)),this}ft(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"menu",{},t)),this}gt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"li",{},t)),this}wt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"table",{},t)),this}yt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"caption",{},t)),this}vt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"thead",{},t)),this}xt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"tbody",{},t)),this}$t(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"tfoot",{},t)),this}Mt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"tr",{},t)),this}St(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"th",{},t)),this}Tt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"td",{},t)),this}Ct(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"button",{},t)),this}Dt(t={},e=()=>{}){const n=t.title??t.textContent??"Help: No info";delete t.textContent,t.title=`Help: ${n}`;const s={textContent:"?",className:"bm-D",onclick:()=>{this.Ot(this.G,n)}};return e(this,i(this,g,w).call(this,"button",s,t)),this}kt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"input",{},t)),this}Lt(t={},e=()=>{}){const n=t.textContent??"";delete t.textContent;const s=i(this,g,w).call(this,"div"),o=i(this,g,w).call(this,"input",{type:"file",tabindex:"-1","aria-hidden":"true"},t);this.X();const a=i(this,g,w).call(this,"button",{textContent:n});return this.X(),this.X(),a.addEventListener("click",()=>{o.click()}),o.addEventListener("change",()=>{a.style.maxWidth=`${a.offsetWidth}px`,o.files.length>0?a.textContent=o.files[0].name:a.textContent=n}),e(this,s,o,a),this}Nt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"textarea",{},t)),this}Bt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"div",{class:"bm-1h"},t)),this}It(t=Date.now(),e=500,n={},s=()=>{}){const o="bm-1l",a=n?.id||o+"-"+crypto.randomUUID().slice(0,8),r={class:o},l=i(this,g,w).call(this,"time",r,n);return l.id=a,l.dataset.endDate=t,setInterval(()=>{if(!l.isConnected)return;const t=Math.max(l.dataset.endDate-Date.now(),0),e=Math.floor(t/1e3),i=Math.floor(e/3600),n=Math.floor(e%60),s=Math.floor(e%3600/60);l.setAttribute("datetime",`PT${i}H${s}M${n}S`),l.textContent=String(i).padStart(2,"0")+":"+String(s).padStart(2,"0")+":"+String(n).padStart(2,"0")},e),s(this,l),this}Ot(t,e,i=!1){const n=document.getElementById(t.replace(/^#/,""));n&&(n instanceof HTMLInputElement?n.value=e:i?n.textContent=e:n.innerHTML=e)}Pt(t){if(t.disabled)return;t.disabled=!0,t.style.textDecoration="none";const e=t.closest(".bm-1j"),i=t.closest(".bm-1h"),n=e.querySelector("h1"),s=e.querySelector(".bm-U");if("expanded"==t.dataset.buttonStatus){s.style.height=s.scrollHeight+"px",e.style.width=e.scrollWidth+"px",s.style.height="0",s.addEventListener("transitionend",function e(){s.style.display="none",t.disabled=!1,t.style.textDecoration="",s.removeEventListener("transitionend",e)});const i=n.cloneNode(!0),o=i.textContent;t.nextElementSibling.appendChild(i),t.textContent="▶",t.dataset.buttonStatus="collapsed",t.ariaLabel=`Unminimize window "${o}"`}else{const n=i.querySelector("h1"),o=n.textContent;n.remove(),s.style.display="",s.style.height="0",e.style.width="",s.style.height=s.scrollHeight+"px",s.addEventListener("transitionend",function e(){s.style.height="",t.disabled=!1,t.style.textDecoration="",s.removeEventListener("transitionend",e)}),t.textContent="▼",t.dataset.buttonStatus="expanded",t.ariaLabel=`Minimize window "${o}"`}}At(t,e){if(t=document.querySelector(t),e=document.querySelector(e),!t||!e)return void this.Ht(`Can not drag! ${t?"":"moveMe"} ${t||e?"":"and "}${e?"":"iMoveThings "}was not found!`);let i,n=!1,s=0,o=null,a=0,r=0,l=0,c=0,h=null;const m=()=>{if(n){const e=Math.abs(a-l),i=Math.abs(r-c);(e>.5||i>.5)&&(a=l,r=c,t.style.transform=`translate(${a}px, ${r}px)`,t.style.left="0px",t.style.top="0px",t.style.right=""),o=requestAnimationFrame(m)}},d=(d,f)=>{n=!0,h=t.getBoundingClientRect(),i=d-h.left,s=f-h.top;const g=window.getComputedStyle(t).transform;if(g&&"none"!==g){const t=new DOMMatrix(g);a=t.m41,r=t.m42}else a=h.left,r=h.top;l=a,c=r,document.body.style.userSelect="none",e.classList.add("bm-1c"),document.addEventListener("mousemove",b),document.addEventListener("touchmove",p,{passive:!1}),document.addEventListener("mouseup",u),document.addEventListener("touchend",u),document.addEventListener("touchcancel",u),o&&cancelAnimationFrame(o),m()},u=()=>{n=!1,o&&(cancelAnimationFrame(o),o=null),document.body.style.userSelect="",e.classList.remove("bm-1c"),document.removeEventListener("mousemove",b),document.removeEventListener("touchmove",p),document.removeEventListener("mouseup",u),document.removeEventListener("touchend",u),document.removeEventListener("touchcancel",u)},b=t=>{n&&h&&(l=t.clientX-i,c=t.clientY-s)},p=t=>{if(n&&h){const e=t.touches[0];if(!e)return;l=e.clientX-i,c=e.clientY-s,t.preventDefault()}};e.addEventListener("mousedown",function(t){t.preventDefault(),d(t.clientX,t.clientY)}),e.addEventListener("touchstart",function(t){const e=t?.touches?.[0];e&&(d(e.clientX,e.clientY),t.preventDefault())},{passive:!1})}Ut(t){(0,console.info)(`${this.name}: ${t}`),this.Ot(this.G,"Status: "+t,!0)}Ht(t){(0,console.error)(`${this.name}: ${t}`),this.Ot(this.G,"Error: "+t,!0)}};g=new WeakSet,w=function(t,e={},n={}){const s=document.createElement(t);this.F?(this.Y?.appendChild(s),this._.push(this.Y),this.Y=s):(this.F=s,this.Y=s);for(const[t,n]of Object.entries(e))i(this,g,y).call(this,s,t,n);for(const[t,e]of Object.entries(n))i(this,g,y).call(this,s,t,e);return s},y=function(t,e,i){if("class"==e)t.classList.add(...i.split(/\s+/));else if("for"==e)t.htmlFor=i;else if("tabindex"==e)t.tabIndex=Number(i);else if("readonly"==e)t.readOnly="true"==i||"1"==i;else if("maxlength"==e)t.maxLength=Number(i);else if(e.startsWith("data"))t.dataset[e.slice(5).split("-").map((t,e)=>0==e?t:t[0].toUpperCase()+t.slice(1)).join("")]=i;else if(e.startsWith("aria")){const n=e.slice(5).split("-").map((t,e)=>0==e?t:t[0].toUpperCase()+t.slice(1)).join("");t["aria"+n[0].toUpperCase()+n.slice(1)]=i}else t[e]=i};var D,O,k,L,N=class extends C{constructor(t){super(t.name,t.version),e(this,$),this.window=null,this.Wt="bm-Y",this.Gt=document.body,this.Ft=t.W?.Ft,this.Et='<svg viewBox="0 .5 6 3"><path d="M0,2Q3-1 6,2Q3,5 0,2H2A1,1 0 1 0 3,1Q3,2 2,2"/></svg>',this.Yt='<svg viewBox="0 1 12 6"><mask id="a"><path d="M0,0H12V8L0,2" fill="#fff"/></mask><path d="M0,4Q6-2 12,4Q6,10 0,4H4A2,2 0 1 0 6,2Q6,4 4,4ZM1,2L10,6.5L9.5,7L.5,2.5" mask="url(#a)"/></svg>',this._t=new Intl.NumberFormat,this.jt=new Intl.NumberFormat(void 0,{style:"percent",Xt:2,Rt:2}),this.Jt={Vt:"long",zt:"numeric",qt:"2-digit",Qt:"2-digit",Kt:"2-digit"};const{palette:i,M:n}=this.Ft.N;this.palette=i,this.Zt=0,this.te=0}ee(){if(document.querySelector(`#${this.Wt}`))return void this.Ht("Color Filter window already exists!");this.window=this.J({id:this.Wt,class:"bm-1j"}).Bt().Ct({class:"bm-Z",textContent:"▼","aria-label":'Minimize window "Color Filter"',"data-button-status":"expanded"},(t,e)=>{e.onclick=()=>t.Pt(e),e.ontouchend=()=>{e.click()}}).X().J().X().Ct({class:"bm-Z",textContent:"🞪","aria-label":'Close window "Color Filter"'},(t,e)=>{e.onclick=()=>{document.querySelector(`#${this.Wt}`)?.remove()},e.ontouchend=()=>{e.click()}}).X().X().J({class:"bm-U"}).J({class:"bm-1b bm-Q"}).it(1,{textContent:"Color Filter"}).X().X().nt().X().J({class:"bm-1b bm-_ bm-Q",style:"gap: 1.5ch;"}).Ct({textContent:"Select All"},(t,e)=>{e.onclick=()=>i(this,$,T).call(this,!1)}).X().Ct({textContent:"Unselect All"},(t,e)=>{e.onclick=()=>i(this,$,T).call(this,!0)}).X().X().J({class:"bm-1b bm-17"}).J({class:"bm-1b",style:"margin-left: 2.5ch; margin-right: 2.5ch;"}).J({class:"bm-1b"}).K({id:"bm-R",innerHTML:"<b>Tiles Loaded:</b> 0 / ???"}).X().st().X().K({id:"bm-M",innerHTML:"<b>Correct Pixels:</b> ???"}).X().st().X().K({id:"bm-S",innerHTML:"<b>Total Pixels:</b> ???"}).X().st().X().K({id:"bm-I",innerHTML:"<b>Complete:</b> ??? (???)"}).X().st().X().K({id:"bm-J",innerHTML:"??? ???"}).X().X().J({class:"bm-1b"}).V({innerHTML:`Colors with the icon ${this.Et.replace("<svg",'<svg aria-label="Eye Open"')} will be shown on the canvas. Colors with the icon ${this.Yt.replace("<svg",'<svg aria-label="Eye Closed"')} will not be shown on the canvas. The "Select All" and "Unselect All" buttons only apply to colors that display in the list below. The amount of correct pixels is dependent on how many tiles of the template you have loaded since you last opened Wplace.live. If all tiles have been loaded, then the "correct pixel" count is accurate.`}).X().X().nt().X().ot({class:"bm-1b"}).rt().lt({textContent:"Sort Options:",style:"font-weight: 700;"}).X().J({class:"bm-1b"}).ht({id:"bm-L",name:"sortPrimary",textContent:"I want to view "}).dt({value:"id",textContent:"color IDs"}).X().dt({value:"name",textContent:"color names"}).X().dt({value:"premium",textContent:"premium colors"}).X().dt({value:"percent",textContent:"percentage"}).X().dt({value:"correct",textContent:"correct pixels"}).X().dt({value:"incorrect",textContent:"incorrect pixels"}).X().dt({value:"total",textContent:"total pixels"}).X().X().ht({id:"bm-H",name:"sortSecondary",textContent:" in "}).dt({value:"ascending",textContent:"ascending"}).X().dt({value:"descending",textContent:"descending"}).X().X().K({textContent:" order."}).X().X().J({class:"bm-1b"}).ct({id:"bm-N",name:"showUnused",textContent:"Show unused colors"}).X().X().X().J({class:"bm-1b"}).Ct({textContent:"Sort Colors",type:"submit"},(t,e)=>{e.onclick=t=>{t.preventDefault();const e=new FormData(document.querySelector(`#${this.Wt} form`)),n={};for(const[t,i]of e)n[t]=i;console.log(`Primary: ${n.sortPrimary}; Secondary: ${n.sortSecondary}; Unused: ${"on"==n.showUnused}`),i(this,$,S).call(this,n.sortPrimary,n.sortSecondary,"on"==n.showUnused)}}).X().X().X().X().X().X().X().R(this.Gt),this.At(`#${this.Wt}.bm-1j`,`#${this.Wt} .bm-1h`);const t=document.querySelector(`#${this.Wt} .bm-1b.bm-17`);let e=0,n=0;const s=new Map,o=new Map;for(const t of this.Ft.C){e+=t.m?.total??0??0;const i=t.m?.colors??new Map;for(const[t,e]of i){const i=Number(e)||0,n=o.get(t)??0;o.set(t,n+i)}const a=t.m?.correct??{};this.Zt+=Object.keys(a).length,this.te+=Object.keys(t.o).length;for(const t of Object.values(a))for(const[e,i]of t){const t=Number(i)||0;n+=t;const o=s.get(e)??0;s.set(e,o+t)}}console.log(`Tiles loaded: ${this.Zt} / ${this.te}`),n>=e&&e&&this.Zt==this.te&&(new v).U(document.querySelector(`#${this.Wt}`));const a=new Date(30*(e-n)*1e3+Date.now()),r=a.toLocaleString(void 0,this.Jt);this.Ot("#bm-R",`<b>Tiles Loaded:</b> ${this._t.format(this.Zt)} / ${this._t.format(this.te)}`),this.Ot("#bm-M",`<b>Correct Pixels:</b> ${this._t.format(n)}`),this.Ot("#bm-S",`<b>Total Pixels:</b> ${this._t.format(e)}`),this.Ot("#bm-I",`<b>Remaining:</b> ${this._t.format((e||0)-(n||0))} (${this.jt.format(((e||0)-(n||0))/(e||1))})`),this.Ot("#bm-J",`<b>Completed at:</b> <time datetime="${a.toISOString().replace(/\.\d{3}Z$/,"Z")}">${r}</time>`),i(this,$,M).call(this,t,s,o),i(this,$,S).call(this,"id","ascending",!1)}};$=new WeakSet,M=function(t,e,i){const n=new C(this.name,this.version);n.J({class:"bm-13"});for(const t of this.palette){const s=l(t.rgb);let o=1.05/(s+.05)>(s+.05)/.05?"white":"black";t.id||(o="transparent");const a="white"==o?"bm-O":"bm-P",r=i.get(t.id)??0,c=this._t.format(r);let h=0,m="0",d=this.jt.format(1);0!=r&&(h=e.get(t.id)??"???","number"!=typeof h&&this.Zt==this.te&&t.id&&(h=0),m="string"==typeof h?h:this._t.format(h),d=isNaN(h/r)?"???":this.jt.format(h/r));const u=parseInt(r)-parseInt(h),b=!!this.Ft.B.get(t.id);n.J({class:"bm-1b bm-10 bm-_","data-id":t.id,"data-name":t.name,"data-premium":+t.premium,"data-correct":Number.isNaN(parseInt(h))?"0":h,"data-total":r,"data-percent":"%"==d.slice(-1)?d.slice(0,-1):"0","data-incorrect":u||0}).J({class:"bm-K",style:`background-color: rgb(${t.rgb?.map(t=>Number(t)||0).join(",")});`}).Ct({class:"bm-11 "+a,"data-state":b?"hidden":"shown","aria-label":b?`Show the color ${t.name||""} on templates.`:`Hide the color ${t.name||""} on templates.`,innerHTML:b?this.Yt.replace("<svg",`<svg fill="${o}"`):this.Et.replace("<svg",`<svg fill="${o}"`)},(e,i)=>{i.onclick=()=>{i.style.textDecoration="none",i.disabled=!0,"shown"==i.dataset.state?(i.innerHTML=this.Yt.replace("<svg",`<svg fill="${o}"`),i.dataset.state="hidden",i.ariaLabel=`Show the color ${t.name||""} on templates.`,this.Ft.B.set(t.id,!0)):(i.innerHTML=this.Et.replace("<svg",`<svg fill="${o}"`),i.dataset.state="shown",i.ariaLabel=`Hide the color ${t.name||""} on templates.`,this.Ft.B.delete(t.id)),i.disabled=!1,i.style.textDecoration=""},t.id||(i.disabled=!0)}).X().X().J({class:"bm-_"}).it(2,{textContent:(t.premium?"★ ":"")+t.name}).X().J({class:"bm-_",style:"gap: 1.5ch;"}).q({textContent:`#${t.id}`}).X().q({textContent:`${m} / ${c}`}).X().X().V({textContent:`${"number"!=typeof u||isNaN(u)?"???":u} incorrect pixels. Completed: ${d}`}).X().X().X()}n.R(t)},S=function(t,e,i){const n=document.querySelector(".bm-13"),s=Array.from(n.children);s.sort((n,s)=>{const o=n.getAttribute("data-"+t),a=s.getAttribute("data-"+t),r=parseFloat(o),l=parseFloat(a),c=!isNaN(r),h=!isNaN(l);if(i?n.classList.remove("bm-18"):Number(n.getAttribute("data-total"))||n.classList.add("bm-18"),c&&h)return"ascending"===e?r-l:l-r;{const t=o.toLowerCase(),i=a.toLowerCase();return t<i?"ascending"===e?-1:1:t>i?"ascending"===e?1:-1:0}}),s.forEach(t=>n.appendChild(t))},T=function(t){const e=document.querySelector(".bm-13"),i=Array.from(e.children);for(const e of i){if(e.classList?.contains("bm-18"))continue;const i=e.querySelector(".bm-K button");("hidden"!=i.dataset.state||t)&&("shown"==i.dataset.state&&t||i.click())}},D=new WeakSet,O=function(){new N(this).ee()},k=new WeakSet,L=function(t){const e=JSON.parse(GM_getValue("bmUserSettings","{}"));e.telemetry=t,GM.setValue("bmUserSettings",JSON.stringify(e))};var B=GM_info.script.name.toString(),I=GM_info.script.version.toString();!function(t){const e=document.createElement("script");e.setAttribute("bm-E",B),e.setAttribute("bm-B","color: cornflowerblue;"),e.textContent=`(${t})();`,document.documentElement?.appendChild(e),e.remove()}(()=>{const t=document.currentScript,e=t?.getAttribute("bm-E")||"Blue Marble",i=t?.getAttribute("bm-B")||"",n=new Map;window.addEventListener("message",t=>{const{source:s,endpoint:o,blobID:a,blobData:r,blink:l}=t.data,c=Date.now()-l;if(console.groupCollapsed(`%c${e}%c: ${n.size} Recieved IMAGE message about blob "${a}"`,i,""),console.log(`Blob fetch took %c${String(Math.floor(c/6e4)).padStart(2,"0")}:${String(Math.floor(c/1e3)%60).padStart(2,"0")}.${String(c%1e3).padStart(3,"0")}%c MM:SS.mmm`,i,""),console.log(n),console.groupEnd(),"blue-marble"==s&&a&&r&&!o){const t=n.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...`,i,"",a),n.delete(a)}});const s=window.fetch;window.fetch=async function(...t){const o=await s.apply(this,t),a=o.clone(),r=(t[0]instanceof Request?t[0]?.url:t[0])||"ignore",l=a.headers.get("content-type")||"";if(l.includes("application/json"))console.log(`%c${e}%c: Sending JSON message about endpoint "${r}"`,i,""),a.json().then(t=>{window.postMessage({source:"blue-marble",endpoint:r,jsonData:t},"*")}).catch(t=>{console.error(`%c${e}%c: Failed to parse JSON: `,i,"",t)});else if(l.includes("image/")&&!r.includes("openfreemap")&&!r.includes("maps")){const t=Date.now(),s=await a.blob();return console.log(`%c${e}%c: ${n.size} Sending IMAGE message about endpoint "${r}"`,i,""),new Promise(o=>{const l=crypto.randomUUID();n.set(l,t=>{o(new Response(t,{headers:a.headers,status:a.status,statusText:a.statusText})),console.log(`%c${e}%c: ${n.size} Processed blob "${l}"`,i,"")}),window.postMessage({source:"blue-marble",endpoint:r,blobID:l,blobData:s,blink:t})}).catch(s=>{const o=Date.now();console.error(`%c${e}%c: Failed to Promise blob!`,i,""),console.groupCollapsed(`%c${e}%c: Details of failed blob Promise:`,i,""),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:",s),console.groupEnd()})}return o}});var P=`div:has(>confetti-piece){position:absolute;inset:0;overflow:hidden;pointer-events:none}confetti-piece{position:absolute;top:-10px;width:var(--size);height:var(--size);background:currentColor;transform:translate3d(var(--x),-10vh,0) rotate(var(--rot));animation:fall var(--duration) linear var(--delay);will-change:transform;pointer-events:none}@keyframes fall{to{transform:translate3d(var(--x),110vh,0) rotate(calc(var(--rot) + 720deg))}}.bm-screenreader{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}.bm-1j{position:fixed;background-color:#153063e6;color:#fff;padding:10px;border-radius:8px;z-index:9000;transition:all .3s ease,transform 0s;top:75px;left:60px;width:auto;max-height:fit-content;max-width:calc(100% - 135px);font-family:Roboto Mono,Courier New,Monaco,DejaVu Sans Mono,monospace,Arial;letter-spacing:.05em}#bm-14{max-width:300px}.bm-1h{display:grid;grid-template-columns:auto 1fr auto;align-items:center;gap:.5ch;background:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="5" height="5"><circle cx="3" cy="3" r="1.5" fill="CornflowerBlue"/></svg>') repeat;cursor:grab;width:100%;height:fit-content}.bm-1h.bm-1c{cursor:grabbing}.bm-1j:has(.bm-1h.bm-1c){pointer-events:none;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none}.bm-1h.bm-1c{pointer-events:auto}.bm-1i{display:inline-block;height:2.5em;margin-right:1ch;vertical-align:middle}.bm-1j h1{display:inline-block;font-size:x-large;font-weight:700;vertical-align:middle}.bm-1h h1{font-size:1.2em;user-select:none;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;text-shadow:3px 0px rgba(21,48,99,.5),-3px 0px rgba(21,48,99,.5),0px 3px rgba(21,48,99,.5),0px -3px rgba(21,48,99,.5),3px 3px rgba(21,48,99,.5),-3px 3px rgba(21,48,99,.5),3px -3px rgba(21,48,99,.5),-3px -3px rgba(21,48,99,.5)}.bm-1h div:has(h1){display:contents}.bm-1j h2{display:inline-block;font-size:larger;font-weight:700;vertical-align:middle}.bm-1b.bm-Q{width:fit-content;margin-left:auto;margin-right:auto}.bm-1b{margin:.5em 0}.bm-1j button{background-color:#144eb9;border-radius:1em;padding:0 .75ch}.bm-1j button:hover,.bm-1j button:focus-visible{background-color:#1061e5}.bm-1j button:active,.bm-1j button:disabled{background-color:#2e97ff}.bm-1j button:disabled{text-decoration:line-through}.bm-Z{border:white 1px solid;height:1.5em;width:1.5em;margin-top:2px;text-align:center;line-height:1em;padding:0!important}.bm-19{vertical-align:middle}.bm-19 svg{width:50%;margin:0 auto;fill:#111}.bm-1j button.bm-11{background-color:unset}.bm-11.bm-O:hover,.bm-11.bm-O:focus{background-color:#ffffff2b}.bm-11.bm-O:active{background-color:#ffffff38}.bm-11.bm-P:hover,.bm-11.bm-P:focus{background-color:#0000002b}.bm-11.bm-P:active{background-color:#00000038}input[type=number].bm-12{appearance:auto;-moz-appearance:textfield;width:5.5ch;margin-left:1ch;background-color:#0003;padding:0 .5ch;font-size:small}input[type=number].bm-12::-webkit-outer-spin-button,input[type=number].bm-12::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}div:has(>.bm-1a)>button{width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.bm-1a,input[type=file]{display:none!important;visibility:hidden!important;position:absolute!important;left:-9999px!important;top:-9999px!important;width:0!important;height:0!important;opacity:0!important;z-index:-9999!important;pointer-events:none!important}.bm-1j select{color:#fff;background-color:#144eb9;border-radius:1em;padding:0 .5ch}.bm-1j label:has(input[type=checkbox]){display:flex;width:fit-content;gap:1ch}.bm-1j input[type=checkbox]{width:1em}.bm-U{overflow:hidden;transition:height .3s cubic-bezier(.4,0,.2,1)}.bm-1j textarea{font-size:small;background-color:#0003;padding:0 .5ch;height:5.25em;width:100%}.bm-1j small{font-size:x-small;color:#d3d3d3}.bm-1j ul li{list-style:disc;margin-left:5ch}.bm-1j .bm-1b.bm-17{max-height:calc(80vh - 150px);overflow:auto}.bm-_{display:flex;align-content:center;justify-content:space-between;align-items:center;gap:.5ch}.bm-15{display:flex;align-content:center;justify-content:center;align-items:center;gap:.5ch}#bm-Y p svg{display:inline;height:1em;fill:#fff}.bm-13{display:flex;flex-direction:row;flex-wrap:wrap;justify-content:center;gap:1em 3ch}.bm-10{width:fit-content;max-width:35ch;background-color:#153063e6;border-radius:1em;padding:.5em;gap:1ch;transition:background-color .3s ease}.bm-10:hover,.bm-10:focus-within{background-color:#112855e6}.bm-K{display:block;border:thick double darkslategray;width:fit-content;height:fit-content;padding:1ch}.bm-10[data-id="-2"] .bm-K{background:conic-gradient(#a00,#aa0 16.6%,#0a0,#0aa 50%,#00a 66.6%,#a0a,#a00)}.bm-10[data-id="-1"] .bm-K{background:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 8 8" width="1em" height="1em"><path d="M0,0V8H16V16H8V0" fill="rgba(0,0,0,0.5)"/></svg>') repeat;background-color:transparent!important}.bm-10[data-id="-1"] .bm-K svg{fill:#fff!important}.bm-10[data-id="0"] .bm-K{background-color:transparent!important}.bm-K button{padding:.75em .5ch}.bm-K svg{width:4ch}.bm-10>.bm-_{flex-direction:column;align-items:flex-start;gap:0}.bm-10 small{font-size:.75em}#bm-Y .bm-10.bm-18{display:none}`;GM_addStyle(P);var A,H="@font-face{font-family:'Roboto Mono';font-style:normal;font-weight:400;src:url(data:font/woff2;base64,[encoded data, 16908 characters])format('woff2');}";H.indexOf("@font-face")+1?(console.log("Loading Roboto Mono as a file..."),GM_addStyle(H)):((A=document.createElement("link")).href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap",A.rel="preload",A.as="style",A.onload=function(){this.onload=null,this.rel="stylesheet"},document.head?.appendChild(A)),new class{constructor(){this.ie=null,this.ne=null,this.se="#bm-h"}oe(t){return this.ne=t,this.ie=new MutationObserver(t=>{for(const e of t)for(const t of e.addedNodes)t instanceof HTMLElement&&t.matches?.(this.se)}),this}ae(){return this.ie}observe(t,e=!1,i=!1){t.observe(this.ne,{childList:e,subtree:i})}};var U=new class extends C{constructor(t,i){super(t,i),e(this,D),this.window=null,this.Wt="bm-14",this.Gt=document.body}ee(){document.querySelector(`#${this.Wt}`)?this.Ht("Main window already exists!"):(this.window=this.J({id:this.Wt,class:"bm-1j",style:"top: 10px; left: unset; right: 75px;"}).Bt().Ct({class:"bm-Z",textContent:"▼","aria-label":'Minimize window "Blue Marble"',"data-button-status":"expanded"},(t,e)=>{e.onclick=()=>t.Pt(e),e.ontouchend=()=>{e.click()}}).X().J().X().X().J({class:"bm-U"}).J({class:"bm-1b"}).et({class:"bm-1i",src:"data:image/png;base64,[encoded data, 4716 characters]"},(t,e)=>{const i=new Date;204==Math.floor((i.getTime()-new Date(i.getFullYear(),0,1))/864e5)+1&&(e.parentNode.style.position="relative",e.parentNode.innerHTML=e.parentNode.innerHTML+'<svg viewBox="0 0 9 7" width="2em" height="2em" style="position: absolute; top: -.75em; left: 3.25ch;"><path d="M0,3L9,0L2,7" fill="#0af"/><path d="M0,3A.4,.4 0 1 1 1,5" fill="#a00"/><path d="M1.5,6A1,1 0 0 1 3,6L2,7" fill="#a0f"/><path d="M4,5A.6,.6 0 1 1 5,4" fill="#0a0"/><path d="M6,3A.8,.8 0 1 1 7,2" fill="#fa0"/><path d="M4.5,1.5A1,1 0 0 1 3,2" fill="#aa0"/></svg>',e.onload=()=>{(new v).U(document.querySelector(`#${this.Wt}`))})}).X().it(1,{textContent:this.name}).X().X().nt().X().J({class:"bm-1b"}).K({id:"bm-p",textContent:"Droplets:"}).X().st().X().K({id:"bm-i",textContent:"Next level in..."}).X().st().X().K({textContent:"Charges: "}).It(Date.now(),1e3,{style:"font-weight: 700;"},(t,e)=>{t.W.re=e.id}).X().X().X().nt().X().J({class:"bm-1b"}).J({class:"bm-1b"}).Ct({class:"bm-Z bm-19",style:"margin-top: 0;",innerHTML:'<svg viewBox="0 0 4 6"><path d="M.5,3.4A2,2 0 1 1 3.5,3.4L2,6"/><circle cx="2" cy="2" r=".7" fill="#fff"/></svg>'},(t,e)=>{e.onclick=()=>{const e=t.W?.le;e?.[0]?(t.Ot("bm-v",e?.[0]||""),t.Ot("bm-w",e?.[1]||""),t.Ot("bm-x",e?.[2]||""),t.Ot("bm-y",e?.[3]||"")):t.Ht("Coordinates are malformed! Did you try clicking on the canvas first?")}}).X().kt({type:"number",id:"bm-v",class:"bm-12",placeholder:"Tl X",min:0,max:2047,step:1,required:!0},(t,e)=>{e.addEventListener("paste",t=>{let e=(t.clipboardData||window.clipboardData).getData("text").split(" ").filter(t=>t).map(Number).filter(t=>!isNaN(t));if(4!==e.length)return;let i=selectAllCoordinateInputs(document);for(let t=0;t<i.length;t++)i[t].value=e[t];t.preventDefault()})}).X().kt({type:"number",id:"bm-w",class:"bm-12",placeholder:"Tl Y",min:0,max:2047,step:1,required:!0}).X().kt({type:"number",id:"bm-x",class:"bm-12",placeholder:"Px X",min:0,max:2047,step:1,required:!0}).X().kt({type:"number",id:"bm-y",class:"bm-12",placeholder:"Px Y",min:0,max:2047,step:1,required:!0}).X().X().J({class:"bm-1b"}).Lt({class:"bm-1a",textContent:"Upload Template",accept:"image/png, image/jpeg, image/webp, image/bmp, image/gif"}).X().X().J({class:"bm-1b bm-_"}).Ct({textContent:"Disable","data-button-status":"shown"},(t,e)=>{e.onclick=()=>{e.disabled=!0,"shown"==e.dataset.buttonStatus?(t.W?.Ft?.ce(!1),e.dataset.buttonStatus="hidden",e.textContent="Enable",t.Ut("Disabled templates!")):(t.W?.Ft?.ce(!0),e.dataset.buttonStatus="shown",e.textContent="Disable",t.Ut("Enabled templates!")),e.disabled=!1}}).X().Ct({textContent:"Create"},(t,e)=>{e.onclick=()=>{const e=document.querySelector(`#${this.Wt} .bm-1a`),i=document.querySelector("#bm-v");if(!i.checkValidity())return i.reportValidity(),void t.Ht("Coordinates are malformed! Did you try clicking on the canvas first?");const n=document.querySelector("#bm-w");if(!n.checkValidity())return n.reportValidity(),void t.Ht("Coordinates are malformed! Did you try clicking on the canvas first?");const s=document.querySelector("#bm-x");if(!s.checkValidity())return s.reportValidity(),void t.Ht("Coordinates are malformed! Did you try clicking on the canvas first?");const o=document.querySelector("#bm-y");if(!o.checkValidity())return o.reportValidity(),void t.Ht("Coordinates are malformed! Did you try clicking on the canvas first?");e?.files[0]?(t?.W?.Ft.he(e.files[0],e.files[0]?.name.replace(/\.[^/.]+$/,""),[Number(i.value),Number(n.value),Number(s.value),Number(o.value)]),t.Ut("Drew to canvas!")):t.Ht("No file selected!")}}).X().Ct({textContent:"Filter"},(t,e)=>{e.onclick=()=>i(this,D,O).call(this)}).X().X().J({class:"bm-1b"}).Nt({id:this.G,placeholder:`Status: Sleeping...\nVersion: ${this.version}`,readOnly:!0}).X().X().J({class:"bm-1b bm-_",style:"margin-bottom: 0;"}).J({class:"bm-_"}).Ct({class:"bm-Z",innerHTML:"🎨",title:"Template Color Converter"},(t,e)=>{e.onclick=()=>{window.open("https://pepoafonso.github.io/color_converter_wplace/","_blank","noopener noreferrer")}}).X().Ct({class:"bm-Z",innerHTML:"🌐",title:"Official Blue Marble Website"},(t,e)=>{e.onclick=()=>{window.open("https://bluemarble.lol/","_blank","noopener noreferrer")}}).X().X().q({textContent:"Made by SwingTheVine",style:"margin-top: auto;"}).X().X().X().X().X().R(this.Gt),this.At(`#${this.Wt}.bm-1j`,`#${this.Wt} .bm-1h`))}}(B,I),W=new class{constructor(t,i,n){e(this,m),this.name=t,this.version=i,this.F=n,this.me="1.0.0",this.de=null,this.ue="!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~",this.h=1e3,this.T=3,this.L=3,this.N=function(t){const e=p;e.unshift({id:-1,premium:!1,name:"Erased",rgb:[222,250,206]}),e.unshift({id:-2,premium:!1,name:"Other",rgb:[0,0,0]});const i=new Map;for(const n of e){if(0==n.id||-2==n.id)continue;const e=n.rgb[0],s=n.rgb[1],o=n.rgb[2];for(let a=-t;a<=t;a++)for(let r=-t;r<=t;r++)for(let l=-t;l<=t;l++){const t=e+a,c=s+r,h=o+l;if(t<0||t>255||c<0||c>255||h<0||h>255)continue;const m=(255<<24|h<<16|c<<8|t)>>>0;i.has(m)||i.set(m,n.id)}}return{palette:e,M:i}}(this.L),this.O=null,this.be="",this.C=[],this.S=null,this.pe=!0,this.fe=null,this.B=new Map}async ge(){return{whoami:this.name.replace(" ",""),scriptVersion:this.version,schemaVersion:this.me,templates:{}}}async he(t,e,n){this.S||(this.S=await this.ge(),console.log("Creating JSON...")),this.F.Ut(`Creating template at ${n.join(", ")}...`);const s=new f({displayName:e,t:0,i:o(this.de||0,this.ue),file:t,coords:n}),{v:a,$:r}=await s.u(this.h,this.N);s.o=a;const l={total:s.m.total,colors:Object.fromEntries(s.m.colors)};this.S.templates[`${s.t} ${s.i}`]={name:s.displayName,coords:n.join(", "),enabled:!0,pixels:l,tiles:r},this.C=[],this.C.push(s),this.F.Ut(`Template created at ${n.join(", ")}!`),console.log(Object.keys(this.S.templates).length),console.log(this.S),console.log(this.C),console.log(JSON.stringify(this.S)),await i(this,m,d).call(this)}we(){}async ye(){this.S||(this.S=await this.ge(),console.log("Creating JSON..."))}async ve(t,e){if(!this.pe)return t;const n=this.h*this.T;e=e[0].toString().padStart(4,"0")+","+e[1].toString().padStart(4,"0"),console.log(`Searching for templates in tile: "${e}"`);const s=this.C;console.log(s),s.sort((t,e)=>t.t-e.t),console.log(s);const o=s.map(t=>{const i=Object.keys(t.o).filter(t=>t.startsWith(e));if(0===i.length)return null;const n=i.map(e=>{const i=e.split(",");return{xe:t,$e:t.o[e],l:t.l?.[e],Me:[i[0],i[1]],Se:[i[2],i[3]]}});return n?.[0]}).filter(Boolean);console.log(o);const a=o?.length||0;if(console.log(`templateCount = ${a}`),!(a>0))return this.F.Ut(`Sleeping\nVersion: ${this.version}`),t;{const t=s.filter(t=>Object.keys(t.o).filter(t=>t.startsWith(e)).length>0).reduce((t,e)=>t+(e.m.total||0),0),i=(new Intl.NumberFormat).format(t);this.F.Ut(`Displaying ${a} template${1==a?"":"s"}.\nTotal pixels: ${i}`)}const r=await createImageBitmap(t),l=new OffscreenCanvas(n,n),c=l.getContext("2d");c.imageSmoothingEnabled=!1,c.beginPath(),c.rect(0,0,n,n),c.clip(),c.clearRect(0,0,n,n),c.drawImage(r,0,0,n,n);const h=c.getImageData(0,0,n,n),d=new Uint32Array(h.data.buffer);for(const t of o){console.log("Template:"),console.log(t);const n=!!t.xe.m?.colors?.get(-1);let s=t.l.slice();const o=Number(t.Se[0])*this.T,a=Number(t.Se[1])*this.T;if(0!=this.B.size||n||c.drawImage(t.$e,o,a),!s){const e=c.getImageData(o,a,t.$e.width,t.$e.height);s=new Uint32Array(e.data.buffer)}const r=Date.now(),{I:l,P:h}=i(this,m,b).call(this,{D:d,O:s,k:[o,a,t.$e.width,t.$e.height]});let u=0;const p=0;for(const[t,e]of l)t!=p&&(u+=e);(0!=this.B.size||n)&&(console.log("Colors to filter: ",this.B),c.drawImage(await createImageBitmap(new ImageData(new Uint8ClampedArray(h.buffer),t.$e.width,t.$e.height)),o,a)),console.log(`Finished calculating correct pixels & filtering colors for the tile ${e} in ${(Date.now()-r)/1e3} seconds!\nThere are ${u} correct pixels.`),void 0===t.xe.m.correct&&(t.xe.m.correct={}),t.xe.m.correct[e]=l}return await l.convertToBlob({type:"image/png"})}Te(t){console.log("Importing JSON..."),console.log(t),"BlueMarble"==t?.whoami&&i(this,m,u).call(this,t)}ce(t){this.pe=t}}(B,I,U),G=new class{constructor(t){this.Ft=t,this.Ce=!1,this.re="",this.le=[],this.De=[]}Oe(t){window.addEventListener("message",async e=>{const i=e.data,n=i.jsonData;if(!i||"blue-marble"!==i.source)return;if(!i.endpoint)return;const s=i.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;","",s),s){case"me":if(n.status&&"2"!=n.status?.toString()[0])return void t.Ht("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);if(console.log(n.id),(n.id||0===n.id)&&console.log(o(n.id,"!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~")),this.Ft.de=n.id,0!=this.re.length){const t=document.querySelector("#"+this.re);if(t){const e=n.charges;t.dataset.endDate=Date.now()+(e.max-e.count)*e.cooldownMs}}t.Ot("bm-p",`Droplets: <b>${(new Intl.NumberFormat).format(n.droplets)}</b>`),t.Ot("bm-i",`Next level in <b>${(new Intl.NumberFormat).format(e)}</b> pixel${1==e?"":"s"}`);break;case"pixel":const s=i.endpoint.split("?")[0].split("/").filter(t=>t&&!isNaN(Number(t))),l=new URLSearchParams(i.endpoint.split("?")[1]),c=[l.get("x"),l.get("y")];if(this.le.length&&(!s.length||!c.length))return void t.Ht("Coordinates are malformed!\nDid you try clicking the canvas first?");this.le=[...s,...c];const h=(a=s,r=c,[parseInt(a[0])%4*1e3+parseInt(r[0]),parseInt(a[1])%4*1e3+parseInt(r[1])]),m=document.querySelectorAll("span");for(const t of m)if(t.textContent.trim().includes(`${h[0]}, ${h[1]}`)){let e=document.querySelector("#bm-h");const i=`(Tl X: ${s[0]}, Tl Y: ${s[1]}, Px X: ${c[0]}, Px Y: ${c[1]})`;e?e.textContent=i:(e=document.createElement("span"),e.id="bm-h",e.textContent=i,e.style="margin-left: calc(var(--spacing)*3); font-size: small;",t.parentNode.parentNode.insertAdjacentElement("afterend",e))}break;case"tiles":let d=i.endpoint.split("/");d=[parseInt(d[d.length-2]),parseInt(d[d.length-1].replace(".png",""))];const u=i.blobID,b=i.blobData,p=Date.now(),f=await this.Ft.ve(b,d);console.log(`Finished loading the tile in ${(Date.now()-p)/1e3} seconds!`),window.postMessage({source:"blue-marble",blobID:u,blobData:f,blink:i.blink});break;case"robots":this.Ce="false"==n.userscript?.toString().toLowerCase();break}var a,r})}async ke(t){console.log("Sending heartbeat to telemetry server...");let e=GM_getValue("bmUserSettings","{}");if(e=JSON.parse(e),!e||!e.telemetry||!e.uuid)return void console.log("Telemetry is disabled, not sending heartbeat.");const i=navigator.userAgent;let n=await this.Le(i),o=this.Ne(i);GM_xmlhttpRequest({method:"POST",url:"https://telemetry.thebluecorner.net/heartbeat",headers:{"Content-Type":"application/json"},data:JSON.stringify({uuid:e.uuid,version:t,browser:n,os:o}),onload:t=>{200!==t.status&&s("Failed to send heartbeat:",t.statusText)},onerror:t=>{s("Error sending heartbeat:",t)}})}async Le(t=navigator.userAgent){return(t=t||"").includes("OPR/")||t.includes("Opera")?"Opera":t.includes("Edg/")?"Edge":t.includes("Vivaldi")?"Vivaldi":t.includes("YaBrowser")?"Yandex":t.includes("Kiwi")?"Kiwi":t.includes("Brave")?"Brave":t.includes("Firefox/")?"Firefox":t.includes("Chrome/")?"Chrome":t.includes("Safari/")?"Safari":navigator.brave&&"function"==typeof navigator.brave.isBrave&&await navigator.brave.isBrave()?"Brave":"Unknown"}Ne(t=navigator.userAgent){return/Windows NT 11/i.test(t=t||"")?"Windows 11":/Windows NT 10/i.test(t)?"Windows 10":/Windows NT 6\.3/i.test(t)?"Windows 8.1":/Windows NT 6\.2/i.test(t)?"Windows 8":/Windows NT 6\.1/i.test(t)?"Windows 7":/Windows NT 6\.0/i.test(t)?"Windows Vista":/Windows NT 5\.1|Windows XP/i.test(t)?"Windows XP":/Mac OS X 10[_\.]15/i.test(t)?"macOS Catalina":/Mac OS X 10[_\.]14/i.test(t)?"macOS Mojave":/Mac OS X 10[_\.]13/i.test(t)?"macOS High Sierra":/Mac OS X 10[_\.]12/i.test(t)?"macOS Sierra":/Mac OS X 10[_\.]11/i.test(t)?"OS X El Capitan":/Mac OS X 10[_\.]10/i.test(t)?"OS X Yosemite":/Mac OS X 10[_\.]/i.test(t)?"macOS":/Android/i.test(t)?"Android":/iPhone|iPad|iPod/i.test(t)?"iOS":/Linux/i.test(t)?"Linux":"Unknown"}}(W);U.j(G);var F=JSON.parse(GM_getValue("bmTemplates","{}"));console.log(F),W.Te(F);var E=JSON.parse(GM_getValue("bmUserSettings","{}"));if(console.log(E),console.log(Object.keys(E).length),0==Object.keys(E).length){const t=crypto.randomUUID();console.log(t),GM.setValue("bmUserSettings",JSON.stringify({uuid:t}))}setInterval(()=>G.ke(I),18e5);var Y=E?.telemetry;if(console.log(`Telemetry is ${!(null==Y)}`),null==Y||Y>1){const t=new class extends C{constructor(t,i,n,s){super(t,i),e(this,k),this.window=null,this.Wt="bm-T",this.Gt=document.body,this.Be=n,this.uuid=s}async ee(){if(document.querySelector(`#${this.Wt}`))return void this.Ht("Telemetry window already exists!");const t=await this.W.Le(navigator.userAgent),e=this.W.Ne(navigator.userAgent);this.window=this.J({id:this.Wt,class:"bm-1j",style:"height: 80vh; z-index: 9998;"}).J({class:"bm-U"}).J({class:"bm-1b bm-Q"}).it(1,{textContent:`${this.name} Telemetry`}).X().X().nt().X().J({class:"bm-1b bm-15",style:"gap: 1.5ch; flex-wrap: wrap;"}).Ct({textContent:"Enable Telemetry"},(t,e)=>{e.onclick=()=>{i(this,k,L).call(this,this.Be);const t=document.getElementById(this.Wt);t?.remove()}}).X().Ct({textContent:"Disable Telemetry"},(t,e)=>{e.onclick=()=>{i(this,k,L).call(this,0);const t=document.getElementById(this.Wt);t?.remove()}}).X().Ct({textContent:"More Information"},(t,e)=>{e.onclick=()=>{window.open("https://github.com/SwingTheVine/Wplace-TelemetryServer#telemetry-data","_blank","noopener noreferrer")}}).X().X().J({class:"bm-1b bm-17"}).J({class:"bm-1b"}).it(2,{textContent:"Legal"}).X().V({textContent:`We collect anonymous telemetry data such as your browser, OS, and script version to make the experience better for everyone. The data is never shared personally. The data is never sold. You can turn this off by pressing the "Disable" button, but keeping it on helps us improve features and reliability faster. Thank you for supporting ${this.name}!`}).X().X().nt().X().J({class:"bm-1b"}).it(2,{textContent:"Non-Legal Summary"}).X().V({innerHTML:'You can disable telemetry by pressing the "Disable" button. If you would like to read more about what information we collect, press the "More Information" button.<br>This is the data <em>stored</em> on our servers:'}).X().bt().gt({innerHTML:`A unique identifier (UUIDv4) generated by Blue Marble. This enables our telemetry to function without tracking your actual user ID.<br>Your UUID is: <b>${n(this.uuid)}</b>`}).X().gt({innerHTML:`The version of Blue Marble you are using.<br>Your version is: <b>${n(this.version)}</b>`}).X().gt({innerHTML:`Your browser type, which is used to determine Blue Marble outages and browser popularity.<br>Your browser type is: <b>${n(t)}</b>`}).X().gt({innerHTML:`Your OS type, which is used to determine Blue Marble outages and OS popularity.<br>Your OS type is: <b>${n(e)}</b>`}).X().gt({innerHTML:"The date and time that Blue Marble sent the telemetry information."}).X().X().V({innerHTML:'All of the data mentioned above is <b>aggregated every hour</b>. This means every hour, anything that could even remotly be considered "personal data" is deleted from our server. Here, "aggregated" data means things like "42 people used Blue Marble on Google Chrome this hour", which can\'t be used to identify anyone in particular.'}).X().X().X().X().X().R(this.Gt)}}(B,I,1,E?.uuid);t.j(G),t.ee()}U.ee(),G.Oe(U),new MutationObserver((t,e)=>{const i=document.querySelector("#color-1");if(!i)return;let n=document.querySelector("#bm-t");if(!n){n=document.createElement("button"),n.id="bm-t",n.textContent="Move ↑",n.className="btn btn-soft",n.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=i.parentNode.parentNode.parentNode.parentNode.querySelector("h2");t.parentNode?.appendChild(n)}}).observe(document.body,{childList:!0,subtree:!0}),function(...t){(0,console.log)(...t)}(`%c${B}%c (${I}) userscript has loaded!`,"color: cornflowerblue;","")})();