Wplace-BlueMarble/dist/BlueMarble.user.js
github-actions[bot] 5a557d3641
Some checks failed
Bump, Build, Release / update-auto (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Bump, Build, Release / build (push) Has been cancelled
Bump, Build, Release / update-requirements (push) Has been cancelled
Bump, Build, Release / update-wiki (push) Has been cancelled
v0.90.0; Attempting to open a window that already exists will close the window
2026-02-27 13:40:15 +00:00

33 lines
No EOL
53 KiB
JavaScript

// ==UserScript==
// @name Blue Marble
// @name:en Blue Marble
// @namespace https://github.com/SwingTheVine/
// @version 0.90.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.
// @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/
// @icon https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/ffa17bc9a7c2db10efc201437dbf1637e11a6f61/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
// @match https://wplace.live/*
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant GM.setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_xmlhttpRequest
// @grant GM.download
// @connect telemetry.thebluecorner.net
// @resource CSS-BM-File https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/ffa17bc9a7c2db10efc201437dbf1637e11a6f61/dist/BlueMarble.user.css
// @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){return new Promise(e=>setTimeout(e,t))}function s(t){return(new Intl.NumberFormat).format(t)}function a(t){return new Intl.NumberFormat(void 0,{style:"percent",t:2,i:2}).format(t)}function o(t){const e=document.createElement("div");return e.textContent=t,e.innerHTML}function r(...t){(0,console.log)(...t)}function l(...t){(0,console.error)(...t)}function c(...t){(0,console.warn)(...t)}function h(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 m(t,e){let i=0;const n=e.length;for(const s of t){const t=e.indexOf(s);-1==t&&l(`Invalid character '${s}' encountered whilst decoding! Is the decode alphabet/base incorrect?`),i=i*n+t}return i}function d(t){let e="";for(let i=0;i<t.length;i++)e+=String.fromCharCode(t[i]);return btoa(e)}function u(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 b(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 p,f,w,g,y,v=[{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]}],x=class{constructor({displayName:t="My template",o:i=0,l:n="",url:s="",file:a=null,coords:o=null,h:r=null,m:l={},u:c=1e3}={}){e(this,p),this.displayName=t,this.o=i,this.l=n,this.url=s,this.file=a,this.coords=o,this.h=r,this.m=l,this.u=c,this.p={total:0,colors:new Map}}async v(t,e){const n=await createImageBitmap(this.file),s=n.width,a=n.height;this.u=t;const o={},r={},l=new OffscreenCanvas(this.u,this.u),c=l.getContext("2d",{M:!0});l.width=s,l.height=a,c.imageSmoothingEnabled=!1,c.drawImage(n,0,0);let h=Date.now();const m=i(this,p,f).call(this,c.getImageData(0,0,s,a),e);let u=0;for(const[t,e]of m)0!=t&&(u+=e);this.p={total:u,colors:m},h=Date.now();const b=new OffscreenCanvas(3,3),w=b.getContext("2d");w.clearRect(0,0,3,3),w.fillStyle="white",w.fillRect(1,1,1,1);for(let t=this.coords[3];t<a+this.coords[3];){const e=Math.min(this.u-t%this.u,a-(t-this.coords[3]));for(let i=this.coords[2];i<s+this.coords[2];){const a=Math.min(this.u-i%this.u,s-(i-this.coords[2])),h=3*a,m=3*e;l.width=h,l.height=m,c.imageSmoothingEnabled=!1,c.clearRect(0,0,h,m),c.drawImage(n,i-this.coords[2],t-this.coords[3],a,e,0,0,3*a,3*e),c.save(),c.globalCompositeOperation="destination-in",c.fillStyle=c.createPattern(b,"repeat"),c.fillRect(0,0,h,m),c.restore();const u=c.getImageData(0,0,h,m),p=`${(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.m[p]=new Uint32Array(u.data.buffer),o[p]=await createImageBitmap(l);const f=await l.convertToBlob(),w=await f.arrayBuffer(),g=Array.from(new Uint8Array(w));r[p]=d(g),i+=a}t+=e}return{T:o,$:r}}C(){let t=[1/0,1/0,1/0,1/0];Object.keys(this.h).sort().forEach((e,i)=>{const[n,s,a,o]=e.split(",").map(Number);(s<t[1]||s==t[1]&&n<t[0])&&(t=[n,s,a,o])}),this.coords=t}};p=new WeakSet,f=function(t,e){const i=new Uint32Array(t.data.buffer),{palette:n,S:s}=e,a=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 o=a.get(n);a.set(n,o?o+1:1)}return a};var M,T,$,C,S=class{constructor(t,i){e(this,w),this.name=t,this.version=i,this.D=null,this.O="bm-i",this.k=null,this.L=null,this.N=[]}B(t){this.D=t}I(){return this.N.length>0&&(this.L=this.N.pop()),this}A(t){t?.appendChild(this.k),this.k=null,this.L=null,this.N=[]}H(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"div",{},t)),this}P(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"p",{},t)),this}W(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"small",{},t)),this}U(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"span",{},t)),this}G(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"details",{},t)),this}_(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"summary",{},t)),this}F(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"img",{},t)),this}j(t,e={},n=()=>{}){return n(this,i(this,w,g).call(this,"h"+t,{},e)),this}R(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"hr",{},t)),this}Y(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"br",{},t)),this}V(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"form",{},t)),this}X(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"fieldset",{},t)),this}J(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"legend",{},t)),this}q(t={},e=()=>{}){const n=i(this,w,g).call(this,"label",{textContent:t.textContent??""});delete t.textContent;const s=i(this,w,g).call(this,"input",{type:"checkbox"},t);return n.insertBefore(s,n.firstChild),this.I(),e(this,n,s),this}Z(t={},e=()=>{}){const n=i(this,w,g).call(this,"label",{textContent:t.textContent??"",for:t.id??""});return delete t.textContent,this.I(),e(this,n,i(this,w,g).call(this,"select",{},t)),this}K(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"option",{},t)),this}tt(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"ol",{},t)),this}et(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"ul",{},t)),this}it(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"menu",{},t)),this}nt(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"li",{},t)),this}st(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"table",{},t)),this}ot(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"caption",{},t)),this}rt(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"thead",{},t)),this}lt(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"tbody",{},t)),this}ct(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"tfoot",{},t)),this}ht(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"tr",{},t)),this}dt(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"th",{},t)),this}ut(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"td",{},t)),this}bt(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"button",{},t)),this}ft(t={},e=()=>{}){const n=t.title??t.textContent??"Help: No info";delete t.textContent,t.title=`Help: ${n}`;const s={textContent:"?",className:"bm-M",onclick:()=>{this.wt(this.O,n)}};return e(this,i(this,w,g).call(this,"button",s,t)),this}gt(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"input",{},t)),this}yt(t={},e=()=>{}){const n=t.textContent??"";delete t.textContent;const s=i(this,w,g).call(this,"div"),a=i(this,w,g).call(this,"input",{type:"file",tabindex:"-1","aria-hidden":"true"},t);this.I();const o=i(this,w,g).call(this,"button",{textContent:n});return this.I(),this.I(),o.addEventListener("click",()=>{a.click()}),a.addEventListener("change",()=>{o.style.maxWidth=`${o.offsetWidth}px`,a.files.length>0?o.textContent=a.files[0].name:o.textContent=n}),e(this,s,a,o),this}vt(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"textarea",{},t)),this}xt(t={},e=()=>{}){return e(this,i(this,w,g).call(this,"div",{class:"bm-H"},t)),this}Mt(t=Date.now(),e=500,n={},s=()=>{}){const a="bm-L",o=n?.id||a+"-"+crypto.randomUUID().slice(0,8),r={class:a},l=i(this,w,g).call(this,"time",r,n);return l.id=o,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}wt(t,e,i=!1){const n=document.getElementById(t.replace(/^#/,""));n&&(n instanceof HTMLInputElement?n.value=e:i?n.textContent=e:n.innerHTML=e)}Tt(t){if(t.disabled)return;t.disabled=!0,t.style.textDecoration="none";const e=t.closest(".bm-J"),i=t.closest(".bm-H"),n=e.querySelector("h1"),s=e.querySelector(".bm-f");if(e.parentElement.append(e),"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),a=i.textContent;t.nextElementSibling.appendChild(i),t.textContent="▶",t.dataset.buttonStatus="collapsed",t.ariaLabel=`Unminimize window "${a}"`}else{const n=i.querySelector("h1"),a=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 "${a}"`}}$t(t,e){const i=document.querySelector(t),n=document.querySelector(e);if(!i||!n)return void this.Ct(`Can not drag! ${i?"":"moveMe"} ${i||n?"":"and "}${n?"":"iMoveThings "}was not found!`);let s,a=!1,o=0,r=null,l=0,c=0,h=0,m=0,d=null;const u=()=>{if(a){const t=Math.abs(l-h),e=Math.abs(c-m);(t>.5||e>.5)&&(l=h,c=m,i.style.transform=`translate(${l}px, ${c}px)`,i.style.left="0px",i.style.top="0px",i.style.right=""),r=requestAnimationFrame(u)}},b=(t,e)=>{a=!0,d=i.getBoundingClientRect(),s=t-d.left,o=e-d.top;const b=window.getComputedStyle(i).transform;if(b&&"none"!==b){const t=new DOMMatrix(b);l=t.m41,c=t.m42}else l=d.left,c=d.top;h=l,m=c,document.body.style.userSelect="none",n.classList.add("bm-C"),document.addEventListener("mousemove",f),document.addEventListener("touchmove",w,{passive:!1}),document.addEventListener("mouseup",p),document.addEventListener("touchend",p),document.addEventListener("touchcancel",p),r&&cancelAnimationFrame(r),u()},p=()=>{a=!1,r&&(cancelAnimationFrame(r),r=null),document.body.style.userSelect="",n.classList.remove("bm-C"),document.removeEventListener("mousemove",f),document.removeEventListener("touchmove",w),document.removeEventListener("mouseup",p),document.removeEventListener("touchend",p),document.removeEventListener("touchcancel",p)},f=t=>{a&&d&&(h=t.clientX-s,m=t.clientY-o)},w=t=>{if(a&&d){const e=t.touches[0];if(!e)return;h=e.clientX-s,m=e.clientY-o,t.preventDefault()}};n.addEventListener("mousedown",function(t){t.preventDefault(),b(t.clientX,t.clientY)}),n.addEventListener("touchstart",function(t){const e=t?.touches?.[0];e&&(b(e.clientX,e.clientY),t.preventDefault())},{passive:!1})}St(t){(0,console.info)(`${this.name}: ${t}`),this.wt(this.O,"Status: "+t,!0)}Ct(t){(0,console.error)(`${this.name}: ${t}`),this.wt(this.O,"Error: "+t,!0)}};w=new WeakSet,g=function(t,e={},n={}){const s=document.createElement(t);this.k?(this.L?.appendChild(s),this.N.push(this.L),this.L=s):(this.k=s,this.L=s);for(const[t,n]of Object.entries(e))i(this,w,y).call(this,s,t,n);for(const[t,e]of Object.entries(n))i(this,w,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=class extends S{constructor(t,i,n,s=void 0){super(t,i),e(this,M),this.window=null,this.Dt="bm-j",this.Ot=document.body,this.kt=JSON.parse(GM_getValue("bmTemplates","{}")),this.scriptVersion=this.kt?.scriptVersion,this.schemaVersion=this.kt?.schemaVersion,this.Lt=void 0,this.Nt=n,this.Bt=s}It(){if(document.querySelector(`#${this.Dt}`))return void document.querySelector(`#${this.Dt}`).remove();let t="";document.querySelector("#bm-t")||(t=t.concat("z-index: 9001;").trim()),this.window=this.H({id:this.Dt,class:"bm-J",style:t},(t,e)=>{}).xt().bt({class:"bm-k",textContent:"▼","aria-label":'Minimize window "Template Wizard"',"data-button-status":"expanded"},(t,e)=>{e.onclick=()=>t.Tt(e),e.ontouchend=()=>{e.click()}}).I().H().I().bt({class:"bm-k",textContent:"🞪","aria-label":'Close window "Template Wizard"'},(t,e)=>{e.onclick=()=>{document.querySelector(`#${this.Dt}`)?.remove()},e.ontouchend=()=>{e.click()}}).I().I().H({class:"bm-f"}).H({class:"bm-B bm-b"}).j(1,{textContent:"Template Wizard"}).I().I().R().I().H({class:"bm-B"}).j(2,{textContent:"Status"}).I().P({id:"bm-l",textContent:"Loading template storage status..."}).I().I().H({class:"bm-B bm-x"}).j(2,{textContent:"Detected templates:"}).I().I().I().I().A(this.Ot),this.$t(`#${this.Dt}.bm-J`,`#${this.Dt} .bm-H`),i(this,M,T).call(this),i(this,M,$).call(this)}};M=new WeakSet,T=function(){const t=this.schemaVersion.split(/[-\.\+]/),e=this.Nt.split(/[-\.\+]/);let n="";t[0]==e[0]?t[1]==e[1]?(n='Template storage health: <b style="color:#0f0;">Healthy!</b><br>No futher action required. (Reason: Semantic version matches)',this.Lt="Good"):(n='Template storage health: <b style="color:#ff0;">Poor!</b><br>You can still use your template, but some features may not work. It is recommended that you update Blue Marble\'s template storage. (Reason: MINOR version mismatch)',this.Lt="Poor"):t[0]<e[0]?(n='Template storage health: <b style="color:#f00;">Bad!</b><br>It is guaranteed that some features are broken. You <em>might</em> still be able to use the template. It is HIGHLY recommended that you download all templates and update Blue Marble\'s template storage before continuing. (Reason: MAJOR version mismatch)',this.Lt="Bad"):(n='Template storage health: <b style="color:#f00">Dead!</b><br>Blue Marble can not load the template storage. (Reason: MAJOR version unknown)',this.Lt="Dead");const s=`<hr style="margin:.5ch">If you want to continue using your current templates, then make sure the template storage (schema) is up-to-date.<br>If you don't want to update the template storage, then downgrade Blue Marble to version <b>${o(this.scriptVersion)}</b> to continue using your templates.<br>Alternatively, if you don't care about corrupting the templates listed below, you can fix any issues with the template storage by uploading a new template.`;this.wt("#bm-l",`${n}<br>Your templates were created during Blue Marble version <b>${o(this.scriptVersion)}</b> with schema version <b>${o(this.schemaVersion)}</b>.<br>The current Blue Marble version is <b>${o(this.version)}</b> and requires schema version <b>${o(this.Nt)}</b>.${"Good"!=this.Lt?s:""}`);const a=new S(this.name,this.version);"Dead"!=this.Lt&&(a.H({class:"bm-B bm-u bm-b",style:"gap: 1.5ch;"}),a.bt({textContent:"Download all templates"},(t,e)=>{e.onclick=()=>{e.disabled=!0,this.Bt.At().then(()=>{e.disabled=!1})}}).I()),"Poor"!=this.Lt&&"Bad"!=this.Lt||a.bt({textContent:`Update template storage to ${this.Nt}`},(t,e)=>{e.onclick=()=>{e.disabled=!0,i(this,M,C).call(this,!0)}}).I(),a.I().A(document.querySelector("#bm-l").parentNode)},$=function(){const t=this.kt?.templates;if(Object.keys(t).length>0){const e=document.querySelector(`#${this.Dt} .bm-x`),i=new S(this.name,this.version);i.H({id:"bm-o",class:"bm-B"});for(const e in t){const n=e,a=t[e];if(t.hasOwnProperty(e)){const t=n.split(" "),e=Number(t?.[0]),o=m(t?.[1]||"0",this.Bt.Ht),r=a.name||`Template ${e||""}`,l=a?.coords?.split(",").map(Number),c=a.pixels?.total??void 0,h=void 0,d="number"==typeof e?s(e):"???",u="number"==typeof o?s(o):"???",b="number"==typeof c?s(c):"???";i.H({class:"bm-B bm-u"}).H({class:"bm-u",style:"flex-direction: column; gap: 0;"}).H({class:"bm-1",textContent:h||"🖼️"}).I().W({textContent:`#${d}`}).I().I().H({class:"bm-u bm-0"}).j(3,{textContent:r}).I().U({textContent:`Uploaded by user #${u}`}).I().U({textContent:`Coordinates: ${l.join(", ")}`}).I().U({textContent:`Total Pixels: ${b}`}).I().I().I()}}i.I().A(e)}},C=async function(t){if(t){const t=document.querySelector(`#${this.Dt} .bm-f`);t.innerHTML="",new S(this.name,this.version).H({class:"bm-B"}).H({class:"bm-B bm-b"}).j(1,{textContent:"Template Wizard"}).I().I().R().I().H({class:"bm-B"}).j(2,{textContent:"Status"}).I().P({textContent:"Updating template storage. Please wait..."}).I().I().I().A(t)}GM_deleteValue("bmCoords");const e=this.kt?.templates;if(Object.keys(e).length>0)for(const[t,i]of Object.entries(e))if(e.hasOwnProperty(t)){const t=new x({displayName:i.name,h:i.tiles});t.C();const e=await this.Bt.Pt(t);await this.Bt.Wt(e,t.displayName,t.coords)}t&&(document.querySelector(`#${this.Dt}`).remove(),new D(this.name,this.version,this.Nt,this.Bt).It())};var O,k,L,N,B=D;O=new WeakSet,k=async function(){GM.setValue("bmTemplates",JSON.stringify(this.Ut))},L=async function(t){const e=t.templates,i=t?.schemaVersion,n=i.split(/[-\.\+]/),s=this.schemaVersion.split(/[-\.\+]/),a=t?.scriptVersion;n[0]==s[0]?(n[1]!=s[1]&&new B(this.name,this.version,this.schemaVersion,this).It(),this.Gt=await async function({u:t,zt:i,Gt:n}){if(Object.keys(e).length>0)for(const s in e){const a=s,o=e[s];if(e.hasOwnProperty(s)){const e=a.split(" "),s=Number(e?.[0]),r=e?.[1]||"0",l=o.name||`Template ${s||""}`,c={total:o.pixels?.total,colors:new Map(Object.entries(o.pixels?.colors||{}).map(([t,e])=>[Number(t),e]))},h=o.tiles,m={},d={},b=t*i;for(const t in h)if(h.hasOwnProperty(t)){const e=u(h[t]),i=new Blob([e],{type:"image/png"}),n=await createImageBitmap(i);m[t]=n;const s=new OffscreenCanvas(b,b).getContext("2d");s.drawImage(n,0,0);const a=s.getImageData(0,0,n.width,n.height);d[t]=new Uint32Array(a.data.buffer)}const p=new x({displayName:l,o:s||this.Gt?.length||0,l:r||""});p.p=c,p.h=m,p.m=d,n.push(p)}}return n}({u:this.u,zt:this.zt,Gt:this.Gt})):n[0]<s[0]?new B(this.name,this.version,this.schemaVersion,this).It():this.k.Ct(`Template version ${i} is unsupported.\nUse Blue Marble version ${a} or load a new template.`)},N=function({_t:t,Ft:e,jt:i}){const n=this.zt,s=this.u*n,a=i[0],o=i[1],r=i[2],l=i[3],c=this.Rt,{palette:h,S:m}=this.Yt,d=new Map;for(let i=1;i<l;i+=n)for(let l=1;l<r;l+=n){const h=o+i+-1,u=a+l+0,b=t[h*s+u],p=e[i*r+l],f=p>>>24&255,w=b>>>24&255,g=m.get(p)??-2;if(this.Vt.get(g)&&(e[i*r+l]=b),-1==g){const t=536870912;this.Vt.get(g)?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==g&&b<=c){const t=d.get(g);d.set(g,t?t+1:1);continue}if(f<=c||w<=c)continue;if((m.get(b)??-2)!=g)continue;const y=d.get(g);d.set(g,y?y+1:1)}return{Et:d,Xt:e}};var I,A,H,P,W=class{constructor(){this.Jt=Math.ceil(80/1300*window.innerWidth),this.qt=v.slice(1)}Qt(t){const e=document.createElement("div");for(let t=0;t<this.Jt;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.qt[Math.floor(Math.random()*this.qt.length)].rgb.join(",")})`,t.onanimationend=()=>{t.parentNode.childElementCount<=1?t.parentNode.remove():t.remove()},e.appendChild(t)}t.appendChild(e)}},U=class extends HTMLElement{};customElements.define("confetti-piece",U);var G,z,_,F,j,R=class extends S{constructor(t){super(t.name,t.version),e(this,I),this.window=null,this.Dt="bm-m",this.Ot=document.body,this.Bt=t.D?.Bt,this.Zt='<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.Kt='<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>';const{palette:i,S:n}=this.Bt.Yt;this.palette=i,this.te=0,this.ee=0}It(){if(document.querySelector(`#${this.Dt}`))return void document.querySelector(`#${this.Dt}`).remove();this.window=this.H({id:this.Dt,class:"bm-J"},(t,e)=>{}).xt().bt({class:"bm-k",textContent:"▼","aria-label":'Minimize window "Color Filter"',"data-button-status":"expanded"},(t,e)=>{e.onclick=()=>t.Tt(e),e.ontouchend=()=>{e.click()}}).I().H().I().bt({class:"bm-k",textContent:"🞪","aria-label":'Close window "Color Filter"'},(t,e)=>{e.onclick=()=>{document.querySelector(`#${this.Dt}`)?.remove()},e.ontouchend=()=>{e.click()}}).I().I().H({class:"bm-f"}).H({class:"bm-B bm-b"}).j(1,{textContent:"Color Filter"}).I().I().R().I().H({class:"bm-B bm-p bm-b",style:"gap: 1.5ch;"}).bt({textContent:"Hide All Colors"},(t,e)=>{e.onclick=()=>i(this,I,P).call(this,!1)}).I().bt({textContent:"Show All Colors"},(t,e)=>{e.onclick=()=>i(this,I,P).call(this,!0)}).I().I().H({class:"bm-B bm-x"}).H({class:"bm-B",style:"margin-left: 2.5ch; margin-right: 2.5ch;"}).H({class:"bm-B"}).U({id:"bm-c",innerHTML:"<b>Tiles Loaded:</b> 0 / ???"}).I().Y().I().U({id:"bm-7",innerHTML:"<b>Correct Pixels:</b> ???"}).I().Y().I().U({id:"bm-d",innerHTML:"<b>Total Pixels:</b> ???"}).I().Y().I().U({id:"bm-3",innerHTML:"<b>Complete:</b> ??? (???)"}).I().Y().I().U({id:"bm-4",innerHTML:"??? ???"}).I().I().H({class:"bm-B"}).P({innerHTML:`Colors with the icon ${this.Zt.replace("<svg",'<svg aria-label="Eye Open"')} will be shown on the canvas. Colors with the icon ${this.Kt.replace("<svg",'<svg aria-label="Eye Closed"')} will not be shown on the canvas. The "Hide All Colors" and "Show All Colors" 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.`}).I().I().R().I().V({class:"bm-B"}).X().J({textContent:"Sort Options:",style:"font-weight: 700;"}).I().H({class:"bm-B"}).Z({id:"bm-6",name:"sortPrimary",textContent:"I want to view "}).K({value:"id",textContent:"color IDs"}).I().K({value:"name",textContent:"color names"}).I().K({value:"premium",textContent:"premium colors"}).I().K({value:"percent",textContent:"percentage"}).I().K({value:"correct",textContent:"correct pixels"}).I().K({value:"incorrect",textContent:"incorrect pixels"}).I().K({value:"total",textContent:"total pixels"}).I().I().Z({id:"bm-2",name:"sortSecondary",textContent:" in "}).K({value:"ascending",textContent:"ascending"}).I().K({value:"descending",textContent:"descending"}).I().I().U({textContent:" order."}).I().I().H({class:"bm-B"}).q({id:"bm-8",name:"showUnused",textContent:"Show unused colors"}).I().I().I().H({class:"bm-B"}).bt({textContent:"Sort Colors",type:"submit"},(t,e)=>{e.onclick=t=>{t.preventDefault();const e=new FormData(document.querySelector(`#${this.Dt} form`)),n={};for(const[t,i]of e)n[t]=i;i(this,I,H).call(this,n.sortPrimary,n.sortSecondary,"on"==n.showUnused)}}).I().I().I().I().I().I().I().A(this.Ot),this.$t(`#${this.Dt}.bm-J`,`#${this.Dt} .bm-H`);const t=document.querySelector(`#${this.Dt} .bm-B.bm-x`);let e=0,n=0;const o=new Map,r=new Map;for(const t of this.Bt.Gt){e+=t.p?.total??0??0;const i=t.p?.colors??new Map;for(const[t,e]of i){const i=Number(e)||0,n=r.get(t)??0;r.set(t,n+i)}const s=t.p?.correct??{};this.te+=Object.keys(s).length,this.ee+=Object.keys(t.h).length;for(const t of Object.values(s))for(const[e,i]of t){const t=Number(i)||0;n+=t;const s=o.get(e)??0;o.set(e,s+t)}}n>=e&&e&&this.te==this.ee&&(new W).Qt(document.querySelector(`#${this.Dt}`));const l=new Date(30*(e-n)*1e3+Date.now()),c=l.toLocaleString(void 0,{ie:"long",ne:"numeric",se:"2-digit",ae:"2-digit",oe:"2-digit"});this.wt("#bm-c",`<b>Tiles Loaded:</b> ${s(this.te)} / ${s(this.ee)}`),this.wt("#bm-7",`<b>Correct Pixels:</b> ${s(n)}`),this.wt("#bm-d",`<b>Total Pixels:</b> ${s(e)}`),this.wt("#bm-3",`<b>Remaining:</b> ${s((e||0)-(n||0))} (${a(((e||0)-(n||0))/(e||1))})`),this.wt("#bm-4",`<b>Completed at:</b> <time datetime="${l.toISOString().replace(/\.\d{3}Z$/,"Z")}">${c}</time>`),i(this,I,A).call(this,t,o,r),i(this,I,H).call(this,"id","ascending",!1)}};I=new WeakSet,A=function(t,e,i){const n=new S(this.name,this.version);n.H({class:"bm-v"});for(const t of this.palette){const o=b(t.rgb);let r=1.05/(o+.05)>(o+.05)/.05?"white":"black";t.id||(r="transparent");const l="white"==r?"bm-9":"bm-a",c=i.get(t.id)??0,h=s(c);let m=0,d="0",u=a(1);0!=c&&(m=e.get(t.id)??"???","number"!=typeof m&&this.te==this.ee&&t.id&&(m=0),d="string"==typeof m?m:s(m),u=isNaN(m/c)?"???":a(m/c));const p=parseInt(c)-parseInt(m),f=!!this.Bt.Vt.get(t.id);n.H({class:"bm-B bm-q bm-p","data-id":t.id,"data-name":t.name,"data-premium":+t.premium,"data-correct":Number.isNaN(parseInt(m))?"0":m,"data-total":c,"data-percent":"%"==u.slice(-1)?u.slice(0,-1):"0","data-incorrect":p||0}).H({class:"bm-5",style:`background-color: rgb(${t.rgb?.map(t=>Number(t)||0).join(",")});`}).bt({class:"bm-r "+l,"data-state":f?"hidden":"shown","aria-label":f?`Show the color ${t.name||""} on templates.`:`Hide the color ${t.name||""} on templates.`,innerHTML:f?this.Kt.replace("<svg",`<svg fill="${r}"`):this.Zt.replace("<svg",`<svg fill="${r}"`)},(e,i)=>{i.onclick=()=>{i.style.textDecoration="none",i.disabled=!0,"shown"==i.dataset.state?(i.innerHTML=this.Kt.replace("<svg",`<svg fill="${r}"`),i.dataset.state="hidden",i.ariaLabel=`Show the color ${t.name||""} on templates.`,this.Bt.Vt.set(t.id,!0)):(i.innerHTML=this.Zt.replace("<svg",`<svg fill="${r}"`),i.dataset.state="shown",i.ariaLabel=`Hide the color ${t.name||""} on templates.`,this.Bt.Vt.delete(t.id)),i.disabled=!1,i.style.textDecoration=""},t.id||(i.disabled=!0)}).I().I().H({class:"bm-p"}).j(2,{textContent:(t.premium?"★ ":"")+t.name}).I().H({class:"bm-p",style:"gap: 1.5ch;"}).W({textContent:`#${t.id}`}).I().W({textContent:`${d} / ${h}`}).I().I().P({textContent:`${"number"!=typeof p||isNaN(p)?"???":p} incorrect pixels. Completed: ${u}`}).I().I().I()}n.A(t)},H=function(t,e,i){const n=document.querySelector(".bm-v"),s=Array.from(n.children);s.sort((n,s)=>{const a=n.getAttribute("data-"+t),o=s.getAttribute("data-"+t),r=parseFloat(a),l=parseFloat(o),c=!isNaN(r),h=!isNaN(l);if(i?n.classList.remove("bm-y"):Number(n.getAttribute("data-total"))||n.classList.add("bm-y"),c&&h)return"ascending"===e?r-l:l-r;{const t=a.toLowerCase(),i=o.toLowerCase();return t<i?"ascending"===e?-1:1:t>i?"ascending"===e?1:-1:0}}),s.forEach(t=>n.appendChild(t))},P=function(t){const e=document.querySelector(".bm-v"),i=Array.from(e.children);for(const e of i){if(e.classList?.contains("bm-y"))continue;const i=e.querySelector(".bm-5 button");("hidden"!=i.dataset.state||t)&&("shown"==i.dataset.state&&t||i.click())}},G=new WeakSet,z=function(){new R(this).It()},_=async function(t,e,i){i.preventDefault();const n=await async function(t){let e="";return t&&(e=t.clipboardData.getData("text/plain")),0!=e.length||(await navigator.clipboard.readText().then(t=>{e=t}).catch(t=>{r("Failed to retrieve clipboard data using navigator! Using fallback methods...")}),0!=e.length||(e=window.clipboardData?.getData("Text"))),e}(i),s=n.split(/[^a-zA-Z0-9]+/).filter(t=>t).map(Number).filter(t=>!isNaN(t));2==s.length&&"bm-D"==e.id?(t.wt("bm-D",s?.[0]||""),t.wt("bm-E",s?.[1]||"")):1==s.length?t.wt(e.id,s?.[0]||""):(t.wt("bm-F",s?.[0]||""),t.wt("bm-G",s?.[1]||""),t.wt("bm-D",s?.[2]||""),t.wt("bm-E",s?.[3]||""))},F=new WeakSet,j=function(t){const e=JSON.parse(GM_getValue("bmUserSettings","{}"));e.telemetry=t,GM.setValue("bmUserSettings",JSON.stringify(e))};var Y=GM_info.script.name.toString(),V=GM_info.script.version.toString();!function(t){const e=document.createElement("script");e.setAttribute("bm-N",Y),e.setAttribute("bm-K","color: cornflowerblue;"),e.textContent=`(${t})();`,document.documentElement?.appendChild(e),e.remove()}(()=>{const t=document.currentScript,e=t?.getAttribute("bm-N")||"Blue Marble",i=t?.getAttribute("bm-K")||"",n=new Map;window.addEventListener("message",t=>{const{source:s,endpoint:a,blobID:o,blobData:r,blink:l}=t.data;if(Date.now(),"blue-marble"==s&&o&&r&&!a){const t=n.get(o);"function"==typeof t?t(r):c(`%c${e}%c: Attempted to retrieve a blob (%s) from queue, but the blobID was not a function! Skipping...`,i,"",o),n.delete(o)}});const s=window.fetch;window.fetch=async function(...t){const e=await s.apply(this,t),i=e.clone(),a=(t[0]instanceof Request?t[0]?.url:t[0])||"ignore",o=i.headers.get("content-type")||"";if(o.includes("application/json"))i.json().then(t=>{window.postMessage({source:"blue-marble",endpoint:a,jsonData:t},"*")}).catch(t=>{});else if(o.includes("image/")&&!a.includes("openfreemap")&&!a.includes("maps")){const t=Date.now(),e=await i.blob();return new Promise(s=>{const o=crypto.randomUUID();n.set(o,t=>{s(new Response(t,{headers:i.headers,status:i.status,statusText:i.statusText}))}),window.postMessage({source:"blue-marble",endpoint:a,blobID:o,blobData:e,blink:t})}).catch(t=>{Date.now()})}return e}});var E=GM_getResourceText("CSS-BM-File");GM_addStyle(E);var X,J="robotoMonoInjectionPoint";J.indexOf("@font-face")+1?GM_addStyle(J):((X=document.createElement("link")).href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap",X.rel="preload",X.as="style",X.onload=function(){this.onload=null,this.rel="stylesheet"},document.head?.appendChild(X)),new class{constructor(){this.re=null,this.le=null,this.ce="#bm-g"}he(t){return this.le=t,this.re=new MutationObserver(t=>{for(const e of t)for(const t of e.addedNodes)t instanceof HTMLElement&&t.matches?.(this.ce)}),this}me(){return this.re}observe(t,e=!1,i=!1){t.observe(this.le,{childList:e,subtree:i})}};var q=new class extends S{constructor(t,i){super(t,i),e(this,G),this.window=null,this.Dt="bm-t",this.Ot=document.body}It(){document.querySelector(`#${this.Dt}`)?this.Ct("Main window already exists!"):(this.window=this.H({id:this.Dt,class:"bm-J",style:"top: 10px; left: unset; right: 75px;"},(t,e)=>{}).xt().bt({class:"bm-k",textContent:"▼","aria-label":'Minimize window "Blue Marble"',"data-button-status":"expanded"},(t,e)=>{e.onclick=()=>t.Tt(e),e.ontouchend=()=>{e.click()}}).I().H().I().I().H({class:"bm-f"}).H({class:"bm-B"}).F({class:"bm-I",src:"https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/dist/assets/Favicon.png"},(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 W).Qt(document.querySelector(`#${this.Dt}`))})}).I().j(1,{textContent:this.name}).I().I().R().I().H({class:"bm-B"}).U({id:"bm-n",textContent:"Droplets:"}).I().Y().I().U({id:"bm-h",textContent:"Next level in..."}).I().Y().I().U({textContent:"Charges: "}).Mt(Date.now(),1e3,{style:"font-weight: 700;"},(t,e)=>{t.D.de=e.id}).I().I().I().R().I().H({class:"bm-B"}).H({class:"bm-B"}).bt({class:"bm-k bm-z",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.D?.ue;e?.[0]?(t.wt("bm-F",e?.[0]||""),t.wt("bm-G",e?.[1]||""),t.wt("bm-D",e?.[2]||""),t.wt("bm-E",e?.[3]||"")):t.Ct("Coordinates are malformed! Did you try clicking on the canvas first?")}}).I().gt({type:"number",id:"bm-F",class:"bm-s",placeholder:"Tl X",min:0,max:2047,step:1,required:!0},(t,e)=>{e.addEventListener("paste",n=>i(this,G,_).call(this,t,e,n))}).I().gt({type:"number",id:"bm-G",class:"bm-s",placeholder:"Tl Y",min:0,max:2047,step:1,required:!0},(t,e)=>{e.addEventListener("paste",n=>i(this,G,_).call(this,t,e,n))}).I().gt({type:"number",id:"bm-D",class:"bm-s",placeholder:"Px X",min:0,max:2047,step:1,required:!0},(t,e)=>{e.addEventListener("paste",n=>i(this,G,_).call(this,t,e,n))}).I().gt({type:"number",id:"bm-E",class:"bm-s",placeholder:"Px Y",min:0,max:2047,step:1,required:!0},(t,e)=>{e.addEventListener("paste",n=>i(this,G,_).call(this,t,e,n))}).I().I().H({class:"bm-B"}).yt({class:"bm-A",textContent:"Upload Template",accept:"image/png, image/jpeg, image/webp, image/bmp, image/gif"}).I().I().H({class:"bm-B bm-p"}).bt({textContent:"Disable","data-button-status":"shown"},(t,e)=>{e.onclick=()=>{e.disabled=!0,"shown"==e.dataset.buttonStatus?(t.D?.Bt?.be(!1),e.dataset.buttonStatus="hidden",e.textContent="Enable",t.St("Disabled templates!")):(t.D?.Bt?.be(!0),e.dataset.buttonStatus="shown",e.textContent="Disable",t.St("Enabled templates!")),e.disabled=!1}}).I().bt({textContent:"Create"},(t,e)=>{e.onclick=()=>{const e=document.querySelector(`#${this.Dt} .bm-A`),i=document.querySelector("#bm-F");if(!i.checkValidity())return i.reportValidity(),void t.Ct("Coordinates are malformed! Did you try clicking on the canvas first?");const n=document.querySelector("#bm-G");if(!n.checkValidity())return n.reportValidity(),void t.Ct("Coordinates are malformed! Did you try clicking on the canvas first?");const s=document.querySelector("#bm-D");if(!s.checkValidity())return s.reportValidity(),void t.Ct("Coordinates are malformed! Did you try clicking on the canvas first?");const a=document.querySelector("#bm-E");if(!a.checkValidity())return a.reportValidity(),void t.Ct("Coordinates are malformed! Did you try clicking on the canvas first?");e?.files[0]?(t?.D?.Bt.Wt(e.files[0],e.files[0]?.name.replace(/\.[^/.]+$/,""),[Number(i.value),Number(n.value),Number(s.value),Number(a.value)]),t.St("Drew to canvas!")):t.Ct("No file selected!")}}).I().bt({textContent:"Filter"},(t,e)=>{e.onclick=()=>i(this,G,z).call(this)}).I().I().H({class:"bm-B"}).vt({id:this.O,placeholder:`Status: Sleeping...\nVersion: ${this.version}`,readOnly:!0}).I().I().H({class:"bm-B bm-p",style:"margin-bottom: 0;"}).H({class:"bm-p"}).bt({class:"bm-k",innerHTML:"🧙",title:"Template Wizard"},(t,e)=>{e.onclick=()=>{const e=t.D?.Bt;new B(this.name,this.version,e?.schemaVersion,e).It()}}).I().bt({class:"bm-k",innerHTML:"🎨",title:"Template Color Converter"},(t,e)=>{e.onclick=()=>{window.open("https://pepoafonso.github.io/color_converter_wplace/","_blank","noopener noreferrer")}}).I().bt({class:"bm-k",innerHTML:"🌐",title:"Official Blue Marble Website"},(t,e)=>{e.onclick=()=>{window.open("https://bluemarble.lol/","_blank","noopener noreferrer")}}).I().bt({class:"bm-k",title:"Donate to SwingTheVine",innerHTML:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="#fff" style="width:80%; margin:auto;"><path d="M249.8 75c89.8 0 113 1.1 146.3 4.4 78.1 7.8 123.6 56 123.6 125.2l0 8.9c0 64.3-47.1 116.9-110.8 122.4-5 16.6-12.8 33.2-23.3 49.9-24.4 37.7-73.1 85.3-162.9 85.3l-17.7 0c-73.1 0-129.7-31.6-163.5-89.2-29.9-50.4-33.8-106.4-33.8-181.2 0-73.7 44.4-113.6 96.4-120.2 39.3-5 88.1-5.5 145.7-5.5zm0 41.6c-60.4 0-103.6 .5-136.3 5.5-46 6.7-64.3 32.7-64.3 79.2l.2 25.7c1.2 57.3 7.1 97.1 27.5 134.5 26.6 49.3 74.8 68.2 129.7 68.2l17.2 0c72 0 107-34.9 126.3-65.4 9.4-15.5 17.7-32.7 22.2-54.3l3.3-13.8 19.9 0c44.3 0 82.6-36 82.6-82l0-8.3c0-51.5-32.2-78.7-88.1-85.3-31.6-2.8-50.4-3.9-140.2-3.9zM267 169.2c38.2 0 64.8 31.6 64.8 67 0 32.7-18.3 61-42.1 83.1-15 15-39.3 30.5-55.9 40.5-4.4 2.8-10 4.4-16.7 4.4-5.5 0-10.5-1.7-15.5-4.4-16.6-10-41-25.5-56.5-40.5-21.8-20.8-39.2-46.9-41.3-77l-.2-6.1c0-35.5 25.5-67 64.3-67 22.7 0 38.8 11.6 49.3 27.7 11.6-16.1 27.2-27.7 49.9-27.7zm122.5-3.9c28.3 0 43.8 16.6 43.8 43.2s-15.5 42.7-43.8 42.7c-8.9 0-13.8-5-13.8-11.7l0-62.6c0-6.7 5-11.6 13.8-11.6z"/></svg>'},(t,e)=>{e.onclick=()=>{window.open("https://ko-fi.com/swingthevine","_blank","noopener noreferrer")}}).I().W({textContent:"Made by SwingTheVine",style:"margin-top: auto;"}).I().I().I().I().I().A(this.Ot),this.$t(`#${this.Dt}.bm-J`,`#${this.Dt} .bm-H`))}}(Y,V),Q=new class{constructor(t,i,n){e(this,O),this.name=t,this.version=i,this.k=n,this.schemaVersion="2.0.0",this.pe=null,this.Ht="!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~",this.u=1e3,this.zt=3,this.Rt=3,this.Yt=function(t){const e=v;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],a=n.rgb[2];for(let o=-t;o<=t;o++)for(let r=-t;r<=t;r++)for(let l=-t;l<=t;l++){const t=e+o,c=s+r,h=a+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,S:i}}(this.Rt),this.Ft=null,this.fe="",this.Gt=[],this.Ut=null,this.we=!0,this.ge=null,this.Vt=new Map}async ye(){return{whoami:this.name.replace(" ",""),scriptVersion:this.version,schemaVersion:this.schemaVersion,templates:{}}}async Wt(t,e,n){this.Ut||(this.Ut=await this.ye()),this.k.St(`Creating template at ${n.join(", ")}...`);const s=new x({displayName:e,o:0,l:h(this.pe||0,this.Ht),file:t,coords:n}),{T:a,$:o}=await s.v(this.u,this.Yt);s.h=a;const r={total:s.p.total,colors:Object.fromEntries(s.p.colors)};this.Ut.templates[`${s.o} ${s.l}`]={name:s.displayName,coords:n.join(", "),enabled:!0,pixels:r,tiles:o},this.Gt=[],this.Gt.push(s),this.k.St(`Template created at ${n.join(", ")}!`),await i(this,O,k).call(this)}ve(){}async xe(){this.Ut||(this.Ut=await this.ye())}async Me(){r("Downloading all templates...");for(const t of this.Gt)await this.Te(t),await n(500)}async At(){const t=JSON.parse(GM_getValue("bmTemplates","{}"))?.templates;if(Object.keys(t).length>0)for(const[e,i]of Object.entries(t))t.hasOwnProperty(e)&&(await this.Te(new x({displayName:i.name,o:e.split(" ")?.[0],l:e.split(" ")?.[1],h:i.tiles})),await n(500))}async Te(t){t.C();const e=`${t.coords.join("-")}_${t.displayName.replaceAll(" ","-")}`,i=await this.Pt(t);await GM.download({url:URL.createObjectURL(i),name:e+".png",$e:"uniquify",onload:()=>{r(`Download of template '${e}' complete!`)},onerror:(t,i)=>{l(`Download of template '${e}' failed because ${t}! Details: ${i}`)},ontimeout:()=>{c(`Download of template '${e}' has timed out!`)}})}async Pt(t){const e=t.h,i=Object.keys(e).sort(),n=await Promise.all(i.map(t=>{return i=e[t],new Promise((t,e)=>{const n=new Image;n.onload=()=>t(n),n.onerror=e,n.src="data:image/png;base64,"+i});var i}));let s=1/0,a=1/0,o=0,r=0;i.forEach((t,e)=>{const[i,l,c,h]=t.split(",").map(Number),m=n[e],d=i*this.u+c,u=l*this.u+h;s=Math.min(s,d),a=Math.min(a,u),o=Math.max(o,d+m.width/this.zt),r=Math.max(r,u+m.height/this.zt)});const l=new OffscreenCanvas(o-s,r-a),c=l.getContext("2d");return c.imageSmoothingEnabled=!1,i.forEach((t,e)=>{const[i,o,r,l]=t.split(",").map(Number),h=n[e],m=i*this.u+r,d=o*this.u+l;c.drawImage(h,m-s,d-a,h.width/this.zt,h.height/this.zt)}),l.convertToBlob({type:"image/png"})}async Ce(t,e){if(!this.we)return t;const n=this.u*this.zt;e=e[0].toString().padStart(4,"0")+","+e[1].toString().padStart(4,"0");const a=this.Gt;a.sort((t,e)=>t.o-e.o);const o=a.map(t=>{const i=Object.keys(t.h).filter(t=>t.startsWith(e));if(0===i.length)return null;const n=i.map(e=>{const i=e.split(",");return{Se:t,De:t.h[e],m:t.m?.[e],Oe:[i[0],i[1]],ke:[i[2],i[3]]}});return n?.[0]}).filter(Boolean),r=o?.length||0;if(!(r>0))return this.k.St(`Sleeping\nVersion: ${this.version}`),t;{const t=s(a.filter(t=>Object.keys(t.h).filter(t=>t.startsWith(e)).length>0).reduce((t,e)=>t+(e.p.total||0),0));this.k.St(`Displaying ${r} template${1==r?"":"s"}.\nTotal pixels: ${t}`)}const l=await createImageBitmap(t),c=new OffscreenCanvas(n,n),h=c.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);const m=h.getImageData(0,0,n,n),d=new Uint32Array(m.data.buffer);for(const t of o){const n=!!t.Se.p?.colors?.get(-1);let s=t.m.slice();const a=Number(t.ke[0])*this.zt,o=Number(t.ke[1])*this.zt;if(0!=this.Vt.size||n||h.drawImage(t.De,a,o),!s){const e=h.getImageData(a,o,t.De.width,t.De.height);s=new Uint32Array(e.data.buffer)}Date.now();const{Et:r,Xt:l}=i(this,O,N).call(this,{_t:d,Ft:s,jt:[a,o,t.De.width,t.De.height]});let c=0;const m=0;for(const[t,e]of r)t!=m&&(c+=e);(0!=this.Vt.size||n)&&h.drawImage(await createImageBitmap(new ImageData(new Uint8ClampedArray(l.buffer),t.De.width,t.De.height)),a,o),void 0===t.Se.p.correct&&(t.Se.p.correct={}),t.Se.p.correct[e]=r}return await c.convertToBlob({type:"image/png"})}Le(t){"BlueMarble"==t?.whoami&&i(this,O,L).call(this,t)}be(t){this.we=t}}(Y,V,q),Z=new class{constructor(t){this.Bt=t,this.Ne=!1,this.de="",this.ue=[],this.Be=[]}Ie(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 a=i.endpoint?.split("?")[0].split("/").filter(t=>t&&isNaN(Number(t))).filter(t=>t&&!t.includes(".")).pop();switch(a){case"me":if(n.status&&"2"!=n.status?.toString()[0])return void t.Ct("You are not logged in or Wplace is offline!\nCould not fetch userdata.");const e=Math.ceil(Math.pow(Math.floor(n.level)*Math.pow(30,.65),1/.65)-n.pixelsPainted);if(n.id||n.id,this.Bt.pe=n.id,0!=this.de.length){const t=document.querySelector("#"+this.de);if(t){const e=n.charges;t.dataset.endDate=Date.now()+(e.max-e.count)*e.cooldownMs}}t.wt("bm-n",`Droplets: <b>${s(n.droplets)}</b>`),t.wt("bm-h",`Next level in <b>${s(e)}</b> pixel${1==e?"":"s"}`);break;case"pixel":const a=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.ue.length&&(!a.length||!c.length))return void t.Ct("Coordinates are malformed!\nDid you try clicking the canvas first?");this.ue=[...a,...c];const h=(o=a,r=c,[parseInt(o[0])%4*1e3+parseInt(r[0]),parseInt(o[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-g");const i=`(Tl X: ${a[0]}, Tl Y: ${a[1]}, Px X: ${c[0]}, Px Y: ${c[1]})`;e?e.textContent=i:(e=document.createElement("span"),e.id="bm-g",e.textContent=i,e.style="margin-left: calc(var(--spacing)*3); font-size: small;",t.parentNode.parentNode.insertAdjacentElement("afterend",e))}break;case"tile":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(),await this.Bt.Ce(b,d));window.postMessage({source:"blue-marble",blobID:u,blobData:p,blink:i.blink});break;case"robots":this.Ne="false"==n.userscript?.toString().toLowerCase()}var o,r})}async Ae(t){let e=GM_getValue("bmUserSettings","{}");if(e=JSON.parse(e),!e||!e.telemetry||!e.uuid)return;const i=navigator.userAgent;let n=await this.He(i),s=this.Pe(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:s}),onload:t=>{200!==t.status&&l("Failed to send heartbeat:",t.statusText)},onerror:t=>{l("Error sending heartbeat:",t)}})}async He(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"}Pe(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"}}(Q);q.B(Z);var K=JSON.parse(GM_getValue("bmTemplates","{}"));Q.Le(K);var tt=JSON.parse(GM_getValue("bmUserSettings","{}"));if(0==Object.keys(tt).length){const t=crypto.randomUUID();GM.setValue("bmUserSettings",JSON.stringify({uuid:t}))}setInterval(()=>Z.Ae(V),18e5);var et=tt?.telemetry;if(null==et||et>1){const t=new class extends S{constructor(t,i,n,s){super(t,i),e(this,F),this.window=null,this.Dt="bm-e",this.Ot=document.body,this.We=n,this.uuid=s}async It(){if(document.querySelector(`#${this.Dt}`))return void this.Ct("Telemetry window already exists!");const t=await this.D.He(navigator.userAgent),e=this.D.Pe(navigator.userAgent);this.window=this.H({id:this.Dt,class:"bm-J",style:"height: 80vh; z-index: 9998;"}).H({class:"bm-f"}).H({class:"bm-B bm-b"}).j(1,{textContent:`${this.name} Telemetry`}).I().I().R().I().H({class:"bm-B bm-u",style:"gap: 1.5ch; flex-wrap: wrap;"}).bt({textContent:"Enable Telemetry"},(t,e)=>{e.onclick=()=>{i(this,F,j).call(this,this.We);const t=document.getElementById(this.Dt);t?.remove()}}).I().bt({textContent:"Disable Telemetry"},(t,e)=>{e.onclick=()=>{i(this,F,j).call(this,0);const t=document.getElementById(this.Dt);t?.remove()}}).I().bt({textContent:"More Information"},(t,e)=>{e.onclick=()=>{window.open("https://github.com/SwingTheVine/Wplace-TelemetryServer#telemetry-data","_blank","noopener noreferrer")}}).I().I().H({class:"bm-B bm-x"}).H({class:"bm-B"}).j(2,{textContent:"Legal"}).I().P({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}!`}).I().I().R().I().H({class:"bm-B"}).j(2,{textContent:"Non-Legal Summary"}).I().P({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:'}).I().et().nt({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>${o(this.uuid)}</b>`}).I().nt({innerHTML:`The version of Blue Marble you are using.<br>Your version is: <b>${o(this.version)}</b>`}).I().nt({innerHTML:`Your browser type, which is used to determine Blue Marble outages and browser popularity.<br>Your browser type is: <b>${o(t)}</b>`}).I().nt({innerHTML:`Your OS type, which is used to determine Blue Marble outages and OS popularity.<br>Your OS type is: <b>${o(e)}</b>`}).I().nt({innerHTML:"The date and time that Blue Marble sent the telemetry information."}).I().I().P({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.'}).I().I().I().I().I().A(this.Ot)}}(Y,V,1,tt?.uuid);t.B(Z),t.It()}q.It(),Z.Ie(q),new MutationObserver((t,e)=>{const i=document.querySelector("#color-1");if(!i)return;let n=document.querySelector("#bm-w");if(!n){n=document.createElement("button"),n.id="bm-w",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}),r(`%c${Y}%c (${V}) userscript has loaded!`,"color: cornflowerblue;","")})();