Wplace-BlueMarble/dist/BlueMarble.user.js
2026-04-21 10:14:30 +05:00

44 lines
79 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ==UserScript==
// @name Blue Marble
// @name:en Blue Marble
// @namespace https://github.com/SwingTheVine/
// @version 0.94.0
// @description A userscript to enhance the user experience on Wplace.live. This includes, but is not limited to: uploading images to display locally on a canvas, adding a button to move the Wplace color palette menu, and other QoL features.
// @description:en A userscript to enhance the user experience on Wplace.live. This includes, but is not limited to: uploading images to display locally on a canvas, adding a button to move the Wplace color palette menu, and other QoL features.
// @author SwingTheVine
// @license MPL-2.0
// @supportURL https://discord.gg/tpeBPy46hf
// @homepageURL https://bluemarble.lol/
// @icon https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/2cd51bf91944ae2acb253ea5bbd76f79b7a2edd3/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/2cd51bf91944ae2acb253ea5bbd76f79b7a2edd3/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
/*!
This script is not affiliated with Wplace.live in any way, use at your own risk.
This script is not affiliated with any userscript manager.
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 "Blue Marble" image is owned by NASA.
*/
(()=>{var t=t=>{throw TypeError(t)},e=(e,i,s)=>i.has(e)?t("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(e):i.set(e,s),i=(e,i,s)=>(((e,i)=>{i.has(e)||t("Cannot access private method")})(e,i),s);function s(t){return new Promise(e=>setTimeout(e,t))}function n(t){return(new Intl.NumberFormat).format(t)}function o(t){return new Intl.NumberFormat(void 0,{style:"percent",t:2,i:2}).format(t)}function a(t){return t.toLocaleString(void 0,{o:"long",l:"numeric",h:"2-digit",m:"2-digit",u:"2-digit"})}function r(t){const e=document.createElement("div");return e.textContent=t,e.innerHTML}function l(...t){(0,console.log)(...t)}function c(...t){(0,console.error)(...t)}function h(...t){(0,console.warn)(...t)}function m(t,e){if(0===t)return e[0];let i="";const s=e.length;for(;t>0;)i=e[t%s]+i,t=Math.floor(t/s);return i}function d(t,e){let i=0;const s=e.length;for(const n of t){const t=e.indexOf(n);-1==t&&c(`Invalid character '${n}' encountered whilst decoding! Is the decode alphabet/base incorrect?`),i=i*s+t}return i}function u(t){let e="";for(let i=0;i<t.length;i++)e+=String.fromCharCode(t[i]);return btoa(e)}function b(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 p(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]}function f(t,e,i){return Array.isArray(t)&&([t,e,i]=t),(1<<24|t<<16|e<<8|i).toString(16).slice(1)}var g,w,x,y=[{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]}],$='<svg class="bm-1Z bm-1b" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M7 9.5l5 5 5-5" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>',v=class{constructor(t,i){e(this,g),this.name=t,this.version=i,this.p=null,this.$=null,this.v="bm-r",this.M=null,this.C=null,this.T=[]}S(t){this.p=t}k(t){this.$=t}D(){return this.T.length>0&&(this.C=this.T.pop()),this}N(t){t?.appendChild(this.M),this.M=null,this.C=null,this.T=[]}L(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"div",{},t)),this}H(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"p",{},t)),this}O(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"small",{},t)),this}I(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"span",{},t)),this}B(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"details",{},t)),this}P(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"summary",{},t)),this}A(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"img",{},t)),this}W(t,e={},s=()=>{}){return s(this,i(this,g,w).call(this,"h"+t,{},e)),this}F(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"hr",{},t)),this}U(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"br",{},t)),this}V(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"form",{},t)),this}G(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"fieldset",{},t)),this}R(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"legend",{},t)),this}j(t={},e=()=>{}){const s={};t.textContent?(s.textContent=t.textContent,delete t.textContent):t.innerHTML&&(s.innerHTML=t.innerHTML,delete t.textContent);const n=i(this,g,w).call(this,"label",s),o=i(this,g,w).call(this,"input",{type:"checkbox"},t);return n.insertBefore(o,n.firstChild),this.D(),e(this,n,o),this}Y(t={},e=()=>{}){const s=i(this,g,w).call(this,"label",{textContent:t.textContent??"",for:t.id??""});return delete t.textContent,this.D(),e(this,s,i(this,g,w).call(this,"select",{},t)),this}J(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"option",{},t)),this}X(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"ol",{},t)),this}_(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"ul",{},t)),this}q(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"menu",{},t)),this}Z(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"li",{},t)),this}K(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"table",{},t)),this}tt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"caption",{},t)),this}et(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"thead",{},t)),this}it(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"tbody",{},t)),this}st(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"tfoot",{},t)),this}nt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"tr",{},t)),this}ot(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"th",{},t)),this}rt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"td",{},t)),this}lt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"button",{},t)),this}ct(t={},e=()=>{}){const s=t.title??t.textContent??"Help: No info";delete t.textContent,t.title=`Help: ${s}`;const n={textContent:"?",className:"bm-10",onclick:()=>{this.ht(this.v,s)}};return e(this,i(this,g,w).call(this,"button",n,t)),this}dt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"input",{},t)),this}ut(t={},e=()=>{}){const s=t.textContent??"";delete t.textContent;const n=i(this,g,w).call(this,"div"),o=i(this,g,w).call(this,"input",{type:"file",tabindex:"-1","aria-hidden":"true"},t);this.D();const a=i(this,g,w).call(this,"button",{textContent:s});return this.D(),this.D(),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=s}),e(this,n,o,a),this}bt(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"textarea",{},t)),this}ft(t={},e=()=>{}){return e(this,i(this,g,w).call(this,"div",{class:"bm-S"},t)),this}gt(t=Date.now(),e=500,s={},n=()=>{}){const o="bm--",a=s?.id||o+"-"+crypto.randomUUID().slice(0,8),r={class:o},l=i(this,g,w).call(this,"time",r,s);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),s=Math.floor(e%60),n=Math.floor(e%3600/60);l.setAttribute("datetime",`PT${i}H${n}M${s}S`),l.textContent=String(i).padStart(2,"0")+":"+String(n).padStart(2,"0")+":"+String(s).padStart(2,"0")},e),n(this,l),this}ht(t,e,i=!1){const s=document.getElementById(t.replace(/^#/,""));s&&(s instanceof HTMLInputElement?s.value=e:i?s.textContent=e:s.innerHTML=e)}wt(t){if(t.disabled)return;t.disabled=!0,t.style.textDecoration="none";const e=t.closest(".bm-W"),i=t.closest(".bm-S"),s=e?.querySelector("h1"),n=e?.querySelector(".bm-m");if(!e||!i||!n)return t.disabled=!1,void(t.style.textDecoration="");const o=e=>{let i,s=!1;const o=()=>{s||(s=!0,clearTimeout(i),n.removeEventListener("transitionend",a),e(),t.disabled=!1,t.style.textDecoration="")},a=t=>{t.target==n&&"height"==t.propertyName&&o()};n.addEventListener("transitionend",a),i=setTimeout(o,360)};if(e.parentElement.append(e),"expanded"==t.dataset.buttonStatus){e.dataset.widthBeforeMinimize=e.style.width,e.dataset.heightBeforeMinimize=e.style.height,e.dataset.minHeightBeforeMinimize=e.style.minHeight,n.style.height=n.scrollHeight+"px",n.offsetHeight,e.style.width||(e.style.width=e.scrollWidth+"px"),o(()=>{n.style.display="none"}),n.style.height="0",(e.style.height||e.classList.contains("bm-N"))&&(e.style.minHeight="0px",e.style.height=(()=>{const t=getComputedStyle(e),s=t=>parseFloat(t)||0,n="border-box"==t.boxSizing?s(t.paddingTop)+s(t.paddingBottom)+s(t.borderTopWidth)+s(t.borderBottomWidth):0;return Math.ceil(i.getBoundingClientRect().height+n+2)})()+"px");const a=s?.cloneNode(!0)??document.createElement("h1"),r=a.textContent;t.nextElementSibling.appendChild(a),t.innerHTML='<svg class="bm-1Z bm-1b" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M9.5 7l5 5-5 5" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>',t.dataset.buttonStatus="collapsed",t.ariaLabel=`Unminimize window "${r}"`}else{const s=i.querySelector("h1"),a=s.textContent;s.remove(),n.style.display="",n.style.height="0",e.style.width=e.dataset.widthBeforeMinimize??"",e.style.minHeight=e.dataset.minHeightBeforeMinimize??"",e.style.height=e.dataset.heightBeforeMinimize??"",n.offsetHeight,o(()=>{n.style.height="",delete e.dataset.widthBeforeMinimize,delete e.dataset.heightBeforeMinimize,delete e.dataset.minHeightBeforeMinimize}),n.style.height=n.scrollHeight+"px",t.innerHTML=$,t.dataset.buttonStatus="expanded",t.ariaLabel=`Minimize window "${a}"`}}xt(t,e,i={}){const s=document.querySelector(t),n=document.querySelector(e),o=i?.yt??(()=>{});if(!s||!n)return void this.$t(`Can not drag! ${s?"":"moveMe"} ${s||n?"":"and "}${n?"":"iMoveThings "}was not found!`);let a,r=!1,l=0,c=null,h=0,m=0,d=0,u=0,b=null;const p=()=>{if(r){const t=Math.abs(h-d),e=Math.abs(m-u);(t>.5||e>.5)&&(h=d,m=u,s.style.transform=`translate(${h}px, ${m}px)`,s.style.left="0px",s.style.top="0px",s.style.right=""),c=requestAnimationFrame(p)}},f=(t,e)=>{r=!0,b=s.getBoundingClientRect(),a=t-b.left,l=e-b.top;const i=window.getComputedStyle(s).transform;if(i&&"none"!==i){const t=new DOMMatrix(i);h=t.m41,m=t.m42}else h=b.left,m=b.top;d=h,u=m,document.body.style.userSelect="none",n.classList.add("bm-M"),document.addEventListener("mousemove",w),document.addEventListener("touchmove",x,{passive:!1}),document.addEventListener("mouseup",g),document.addEventListener("touchend",g),document.addEventListener("touchcancel",g),c&&cancelAnimationFrame(c),p()},g=()=>{r=!1,c&&(cancelAnimationFrame(c),c=null),document.body.style.userSelect="",n.classList.remove("bm-M"),document.removeEventListener("mousemove",w),document.removeEventListener("touchmove",x),document.removeEventListener("mouseup",g),document.removeEventListener("touchend",g),document.removeEventListener("touchcancel",g),o({element:s,x:h,y:m}),b=null},w=t=>{r&&b&&(d=t.clientX-a,u=t.clientY-l)},x=t=>{if(r&&b){const e=t.touches[0];if(!e)return;d=e.clientX-a,u=e.clientY-l,t.preventDefault()}};n.addEventListener("mousedown",function(t){t.preventDefault(),f(t.clientX,t.clientY)}),n.addEventListener("touchstart",function(t){const e=t?.touches?.[0];e&&(f(e.clientX,e.clientY),t.preventDefault())},{passive:!1})}vt(t,e,i={}){const s=document.querySelector(t),n=document.querySelector(e),o=i?.yt??(()=>{});if(!s||!n)return void this.$t(`Can not resize! ${s?"":"resizeMe"} ${s||n?"":"and "}${n?"":"iResizeThings "}was not found!`);let a=!1,r=0,l=0,c=0,h=0,m=0,d=0,u=0,b=0,p=null;const f=()=>Number.isFinite(i?.maxWidth)?i.maxWidth:window.innerWidth-16,g=()=>Number.isFinite(i?.maxHeight)?i.maxHeight:window.innerHeight-16,w=Number.isFinite(i?.minWidth)?i.minWidth:200,x=Number.isFinite(i?.minHeight)?i.minHeight:160,y=(t,e,i)=>Math.min(Math.max(t,e),Math.max(e,i)),$=()=>{if(a){const t=Math.abs(m-u),e=Math.abs(d-b);(t>.5||e>.5)&&(m=u,d=b,s.style.width=`${m}px`,s.style.height=`${d}px`),p=requestAnimationFrame($)}},v=(t,e)=>{a=!0,r=t,l=e,c=s.offsetWidth,h=s.offsetHeight,m=c,d=h,u=c,b=h,document.body.style.userSelect="none",n.classList.add("bm-2g"),document.addEventListener("mousemove",C),document.addEventListener("touchmove",T,{passive:!1}),document.addEventListener("mouseup",M),document.addEventListener("touchend",M),document.addEventListener("touchcancel",M),p&&cancelAnimationFrame(p),$()},M=()=>{a=!1,p&&(cancelAnimationFrame(p),p=null),document.body.style.userSelect="",n.classList.remove("bm-2g"),document.removeEventListener("mousemove",C),document.removeEventListener("touchmove",T),document.removeEventListener("mouseup",M),document.removeEventListener("touchend",M),document.removeEventListener("touchcancel",M),o({element:s,width:m,height:d})},C=t=>{a&&(u=y(c+(t.clientX-r),w,f()),b=y(h+(t.clientY-l),x,g()))},T=t=>{if(!a)return;const e=t?.touches?.[0];e&&(u=y(c+(e.clientX-r),w,f()),b=y(h+(e.clientY-l),x,g()),t.preventDefault())};n.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation(),v(t.clientX,t.clientY)}),n.addEventListener("touchstart",t=>{const e=t?.touches?.[0];e&&(t.preventDefault(),t.stopPropagation(),v(e.clientX,e.clientY))},{passive:!1})}Mt(t){(0,console.info)(`${this.name}: ${t}`),this.ht(this.v,"Status: "+t,!0)}$t(t){(0,console.error)(`${this.name}: ${t}`),this.ht(this.v,"Error: "+t,!0)}};g=new WeakSet,w=function(t,e={},s={}){const n=document.createElement(t);this.M?(this.C?.appendChild(n),this.T.push(this.C),this.C=n):(this.M=n,this.C=n);for(const[t,s]of Object.entries(e))i(this,g,x).call(this,n,t,s);for(const[t,e]of Object.entries(s))i(this,g,x).call(this,n,t,e);return n},x=function(t,e,i){"class"==e?t.classList.add(...i.split(/\s+/)):"for"==e?t.htmlFor=i:"tabindex"==e?t.tabIndex=Number(i):"readonly"==e?t.readOnly="true"==i||"1"==i:"maxlength"==e?t.maxLength=Number(i):e.startsWith("data")?t.dataset[e.slice(5).split("-").map((t,e)=>0==e?t:t[0].toUpperCase()+t.slice(1)).join("")]=i:e.startsWith("aria")?t.setAttribute(e,i):t[e]=i};var M,C,T,S,k,D,N,L=class extends v{constructor(t,i){super(t,i),e(this,M),this.window=null,this.Ct="bm-l",this.Tt=document.body}St(){document.querySelector(`#${this.Ct}`)?document.querySelector(`#${this.Ct}`).remove():(this.window=this.L({id:this.Ct,class:"bm-W"}).ft().lt({class:"bm-s",innerHTML:$,"aria-label":'Minimize window "Settings"',"data-button-status":"expanded"},(t,e)=>{e.onclick=()=>t.wt(e),e.ontouchend=()=>{e.click()}}).D().L().D().L({class:"bm-D"}).lt({class:"bm-s",innerHTML:'<svg class="bm-1Z" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M7 7l10 10M17 7L7 17" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"/></svg>',"aria-label":'Close window "Settings"'},(t,e)=>{e.onclick=()=>{document.querySelector(`#${this.Ct}`)?.remove()},e.ontouchend=()=>{e.click()}}).D().D().D().L({class:"bm-m"}).L({class:"bm-L bm-h"}).W(1,{textContent:"Settings"}).D().D().F().D().H({textContent:"Settings take 5 seconds to save."}).D().L({class:"bm-L bm-H"},(t,e)=>{this.kt(),this.Dt()}).D().D().D().N(this.Tt),this.xt(`#${this.Ct}.bm-W`,`#${this.Ct} .bm-S`))}kt(){i(this,M,C).call(this,"Pixel Highlight")}Dt(){i(this,M,C).call(this,"Template")}};M=new WeakSet,C=function(t){this.window=this.L({class:"bm-L"}).W(2,{textContent:t}).D().F().D().H({innerHTML:`An error occured loading the ${t} category. <code>SettingsManager</code> failed to override the ${t} function inside <code>WindowSettings</code>.`}).D().D()},T=new WeakSet,S=function(t,e){t.disabled=!0;const i=t.dataset.status,s=this.Nt?.highlight??[[1,0,1],[2,0,0],[1,-1,0],[1,1,0],[1,0,-1]];let n=[2,0,0];const o=s;switch(i){case"Disabled":t.dataset.status="Incorrect",t.ariaLabel="Sub-pixel incorrect",n=[1,...e];break;case"Incorrect":t.dataset.status="Template",t.ariaLabel="Sub-pixel template",n=[2,...e];break;case"Template":t.dataset.status="Disabled",t.ariaLabel="Sub-pixel disabled",n=[0,...e];break}const a=s.findIndex(([,t,e])=>t==n[1]&&e==n[2]);0!=n[0]?-1!=a?o[a]=n:o.push(n):-1!=a&&o.splice(a,1),this.Nt.highlight=o,t.disabled=!1},k=async function(t){const e=document.querySelectorAll(".bm-3 button");for(const t of e)t.disabled=!0;let i=[0,0,0,0,2,0,0,0,0];switch(t){case"Cross":i=[0,1,0,1,2,1,0,1,0];break;case"X":i=[1,0,1,0,2,0,1,0,1];break;case"Full":i=[2,2,2,2,2,2,2,2,2];break}const n=document.querySelector(".bm-n")?.childNodes??[];for(let t=0;t<n.length;t++){const e=n[t];let o=e.dataset.status;o="Disabled"!=o?"Incorrect"!=o?2:1:0;let a=i[t]-o;if(0!=a&&(a+=a<0?3:0,e.click(),2==a)){for(let t=0;t<200&&e.disabled;t+=10)await s(10);e.click()}}for(const t of e)t.disabled=!1};var H=class{constructor({displayName:t="My template",Lt:i=0,Ht:s="",url:n="",file:o=null,coords:a=null,Ot:r=null,It:l={},Bt:c=1e3}={}){e(this,D),this.displayName=t,this.Lt=i,this.Ht=s,this.url=n,this.file=o,this.coords=a,this.Ot=r,this.It=l,this.Bt=c,this.Pt={total:0,colors:new Map},this.At=!0,this.zt=!1}async Wt(t,e,s,n){console.log("Template coordinates:",this.coords),this.At=s,this.zt=n;const o=await createImageBitmap(this.file),a=o.width,r=o.height;this.Bt=t;const l={},c={},h=new OffscreenCanvas(this.Bt,this.Bt),m=h.getContext("2d",{willReadFrequently:!0}),d=new OffscreenCanvas(this.Bt,this.Bt),b=d.getContext("2d",{willReadFrequently:!0});b.globalCompositeOperation="destination-over",h.width=a,h.height=r,m.imageSmoothingEnabled=!1,m.drawImage(o,0,0);let p=Date.now();const f=i(this,D,N).call(this,m.getImageData(0,0,a,r),e);console.log(`Calculating total pixels took ${(Date.now()-p)/1e3} seconds`);let g=0;for(const[t,e]of f)0!=t&&(g+=e);this.Pt={total:g,colors:f},p=Date.now();const w=new OffscreenCanvas(3,3),x=w.getContext("2d");x.clearRect(0,0,3,3),x.fillStyle="white",x.fillRect(1,1,1,1);for(let t=this.coords[3];t<r+this.coords[3];){const e=Math.min(this.Bt-t%this.Bt,r-(t-this.coords[3]));console.log(`Math.min(${this.Bt} - (${t} % ${this.Bt}), ${r} - (${t-this.coords[3]}))`);for(let i=this.coords[2];i<a+this.coords[2];){console.log(`Pixel X: ${i}\nPixel Y: ${t}`);const r=Math.min(this.Bt-i%this.Bt,a-(i-this.coords[2]));if(s){const s=!this.Ft({Ut:o,Vt:[i-this.coords[2],t-this.coords[3],r,e],Gt:d,Rt:b});if(console.log(`Tile contains template: ${!s}`),s){i+=r;continue}}console.log(`Math.min(${this.Bt} - (${i} % ${this.Bt}), ${a} - (${i-this.coords[2]}))`),console.log(`Draw Size X: ${r}\nDraw Size Y: ${e}`);const p=3*r,f=3*e;h.width=p,h.height=f,console.log(`Draw X: ${r}\nDraw Y: ${e}\nCanvas Width: ${p}\nCanvas Height: ${f}`),m.imageSmoothingEnabled=!1,console.log(`Getting X ${i}-${i+r}\nGetting Y ${t}-${t+e}`),m.clearRect(0,0,p,f),m.drawImage(o,i-this.coords[2],t-this.coords[3],r,e,0,0,3*r,3*e),m.save(),m.globalCompositeOperation="destination-in",console.log(`Should Skip: ${s}; Should Agg Skip: ${n}`),m.fillStyle=m.createPattern(w,"repeat"),m.fillRect(0,0,p,f),m.restore();const g=m.getImageData(0,0,p,f);console.log(`Shreaded pixels for ${i}, ${t}`,g);const x=`${(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.It[x]=new Uint32Array(g.data.buffer),l[x]=await createImageBitmap(h);const y=await h.convertToBlob(),$=await y.arrayBuffer(),v=Array.from(new Uint8Array($));c[x]=u(v),console.log(l),i+=r}t+=e}return console.log(`Parsing template took ${(Date.now()-p)/1e3} seconds`),console.log("Template Tiles: ",l),console.log("Template Tiles Buffers: ",c),console.log("Template Tiles Uint32Array: ",this.It),{jt:l,Et:c}}Ft({Ut:t,Vt:e,Gt:i,Rt:s}){console.log("Calculating template tile transparency..."),console.log(`Should Skip: ${this.At}; Should Agg: ${this.zt}`);const n=Date.now(),o=[[0,1],[1,0],[0,-2],[-2,0],[0,4],[4,0],[0,-8],[-8,0],[0,16],[16,0],[0,-32],[-32,0]],a=e[2],r=e[3];if(i.width=a,i.height=r,s.clearRect(0,0,a,r),this.zt)s.drawImage(t,...e,0,0,10,10);else{s.drawImage(t,...e,0,0,a,r);for(const[t,e]of o)s.drawImage(i,0,0,a,r,t,e,a,r);s.drawImage(i,0,0,a,r,0,0,10,10)}const l=s.getImageData(0,0,10,10),c=new Uint32Array(l.data.buffer);console.log(`Calculated canvas transparency in ${(Date.now()-n)/1e3} seconds.`);for(const t of c)if(t)return!0;return!1}Yt(){let t=[1/0,1/0,1/0,1/0];Object.keys(this.Ot).sort().forEach((e,i)=>{const[s,n,o,a]=e.split(",").map(Number);(n<t[1]||n==t[1]&&s<t[0])&&(t=[s,n,o,a])}),this.coords=t}};D=new WeakSet,N=function(t,e){const i=new Uint32Array(t.data.buffer),{palette:s,Jt:n}=e,o=new Map;for(let t=0;t<i.length;t++){const e=i[t];let s=-2;s=e>>>24==0?0:n.get(e)??-2;const a=o.get(s);o.set(s,a?a+1:1)}return console.log(o),o};var O=class{constructor(){this.Xt=Math.ceil(80/1300*window.innerWidth),this._t=y.slice(1)}qt(t){const e=document.createElement("div");for(let t=0;t<this.Xt;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._t[Math.floor(Math.random()*this._t.length)].rgb.join(",")})`,t.onanimationend=()=>{t.parentNode.childElementCount<=1?t.parentNode.remove():t.remove()},e.appendChild(t)}t.appendChild(e)}},I=class extends HTMLElement{};customElements.define("confetti-piece",I);var B,P,A,z,W,F,U,V,G,R,j,E,Y,J,X,_,q,Z,K,Q,tt,et,it,st,nt,ot='<svg class="bm-1Z" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M7 7l10 10M17 7L7 17" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"/></svg>',at='<svg class="bm-1Z" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M4.8 4.8l5.2 5.2M19.2 4.8L14 10M19.2 19.2L14 14M4.8 19.2L10 14" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/><path d="M10 7.5V10H7.5M16.5 10H14V7.5M14 16.5V14h2.5M7.5 14H10v2.5" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/></svg>',rt=class extends v{constructor(t){super(t.name,t.version),e(this,B),this.window=null,this.Ct="bm-t",this.Zt="bm-E",this.Tt=document.body,this.$=t.$??null,this.Kt="ftr-oWin",this.Qt="windowFilter",this.te=null,this.ee=null,this.ie=null,this.se=null,this.ne=1e4,this.oe=360,this.ae=220,this.re=1e3,this.le=1400,this.ce=t.p?.ce,this.he='<svg class="bm-1z" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M3.8 12s3.1-5 8.2-5 8.2 5 8.2 5-3.1 5-8.2 5-8.2-5-8.2-5Z"/><circle cx="12" cy="12" r="2.5"/></svg>',this.me='<svg class="bm-1z" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M4.6 9.8C6.1 8.3 8.6 7 12 7c5.1 0 8.2 5 8.2 5a15.2 15.2 0 0 1-2.2 2.7"/><path d="M14.1 16.7a8.3 8.3 0 0 1-2.1.3c-5.1 0-8.2-5-8.2-5a14.9 14.9 0 0 1 1.8-2.3"/><path d="M5 5l14 14"/><path d="M10.4 10.7a2.5 2.5 0 0 0 2.9 2.9"/></svg>';const{palette:i,Jt:s}=this.ce.de;this.palette=i,this.ue=0,this.be=0,this.pe=new Map,this.fe=new Map,this.ge=0,this.we=0,this.timeRemaining=0,this.xe="",this.sortPrimary="total",this.sortSecondary="descending",this.showUnused=!1}ye(){i(this,B,A).call(this)?this.$e():this.St()}St(){if(document.querySelector(`#${this.Ct}`))return void i(this,B,F).call(this);this.window=this.L({id:this.Ct,class:"bm-W"},(t,e)=>{}).ft().lt({class:"bm-s",innerHTML:$,"aria-label":'Minimize window "Color Filter"',"data-button-status":"expanded"},(t,e)=>{e.onclick=()=>t.wt(e),e.ontouchend=()=>{e.click()}}).D().L().D().L({class:"bm-D"}).lt({class:"bm-s",innerHTML:at,"aria-label":'Switch to windowed mode for "Color Filter"'},(t,e)=>{e.onclick=()=>{i(this,B,z).call(this,!0),i(this,B,F).call(this),this.$e()},e.ontouchend=()=>{e.click()}}).D().lt({class:"bm-s",innerHTML:ot,"aria-label":'Close window "Color Filter"'},(t,e)=>{e.onclick=()=>i(this,B,F).call(this),e.ontouchend=()=>{e.click()}}).D().D().D().L({class:"bm-m"}).L({class:"bm-L bm-h bm-1N"}).W(1,{textContent:"Color Filter"}).D().D().F().D().L({class:"bm-L bm-x bm-h bm-1F",style:"gap: 1.5ch;"}).lt({class:"bm-1u",textContent:"Hide All Colors"},(t,e)=>{e.onclick=()=>i(this,B,Z).call(this,!1)}).D().lt({class:"bm-1u",textContent:"Show All Colors"},(t,e)=>{e.onclick=()=>i(this,B,Z).call(this,!0)}).D().D().F().D().L({class:"bm-L bm-H bm-1r"}).L({class:"bm-L bm-1A",style:"margin-left: 2.5ch; margin-right: 2.5ch;"}).L({class:"bm-L bm-1s"}).I({id:"bm-i",innerHTML:"<b>Tiles Loaded:</b> 0 / ???"}).D().U().D().I({id:"bm-d",innerHTML:"<b>Correct Pixels:</b> ???"}).D().U().D().I({id:"bm-j",innerHTML:"<b>Total Pixels:</b> ???"}).D().U().D().I({id:"bm-7",innerHTML:"<b>Complete:</b> ??? (???)"}).D().U().D().I({id:"bm-8",innerHTML:"??? ???"}).D().D().L({class:"bm-L bm-20"}).H({innerHTML:`Press the ${at.replace("<svg",'<svg aria-label="Switch to windowed mode"')} button to make this window smaller. Colors with the icon ${this.he.replace("<svg",'<svg aria-label="Eye Open"')} will be shown on the canvas. Colors with the icon ${this.me.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.`}).D().D().F().D().V({class:"bm-L bm-1t"}).G().R({textContent:"Sort Options:",style:"font-weight: 700;"}).D().L({class:"bm-L"}).Y({id:"bm-c",name:"sortPrimary",textContent:"I want to view "}).J({value:"id",textContent:"color IDs"}).D().J({value:"name",textContent:"color names"}).D().J({value:"premium",textContent:"premium colors"}).D().J({value:"percent",textContent:"percentage"}).D().J({value:"correct",textContent:"correct pixels"}).D().J({value:"incorrect",textContent:"incorrect pixels"}).D().J({value:"total",textContent:"total pixels"}).D().D().Y({id:"bm-5",name:"sortSecondary",textContent:" in "}).J({value:"ascending",textContent:"ascending"}).D().J({value:"descending",textContent:"descending"}).D().D().I({textContent:" order."}).D().D().L({class:"bm-L"}).j({id:"bm-e",name:"showUnused",textContent:"Show unused colors"}).D().D().D().L({class:"bm-L bm-1l"}).lt({class:"bm-1G",textContent:"Sort Colors",type:"submit"},(t,e)=>{e.onclick=t=>{t.preventDefault();const e=new FormData(document.querySelector(`#${this.Ct} form`)),s={};for(const[t,i]of e)s[t]=i;console.log(`Primary: ${s.sortPrimary}; Secondary: ${s.sortSecondary}; Unused: ${"on"==s.showUnused}`),i(this,B,q).call(this,s.sortPrimary,s.sortSecondary,"on"==s.showUnused)}}).D().D().D().D().D().D().D().N(this.Tt),this.xt(`#${this.Ct}.bm-W`,`#${this.Ct} .bm-S`);const t=document.querySelector(`#${this.Ct} .bm-L.bm-H`);i(this,B,_).call(this,t),i(this,B,W).call(this),i(this,B,q).call(this,this.sortPrimary,this.sortSecondary,this.showUnused),this.ht("#bm-i",`<b>Tiles Loaded:</b> ${n(this.ue)} / ${n(this.be)}`),this.ht("#bm-d",`<b>Correct Pixels:</b> ${n(this.ge)}`),this.ht("#bm-j",`<b>Total Pixels:</b> ${n(this.we)}`),this.ht("#bm-7",`<b>Remaining:</b> ${n((this.we||0)-(this.ge||0))} (${o(((this.we||0)-(this.ge||0))/(this.we||1))})`),this.ht("#bm-8",`<b>Completed at:</b> <time datetime="${this.timeRemaining.toISOString().replace(/\.\d{3}Z$/,"Z")}">${this.xe}</time>`),i(this,B,U).call(this)}$e(){if(document.querySelector(`#${this.Ct}`))return void i(this,B,F).call(this);this.window=this.L({id:this.Ct,class:"bm-W bm-N",style:`width: 360px; height: min(70vh, 32rem); min-width: ${this.oe}px; min-height: ${this.ae}px; max-width: min(${this.re}px, calc(100vw - 16px)); max-height: min(${this.le}px, calc(100vh - 16px));`}).ft().lt({class:"bm-s",innerHTML:$,"aria-label":'Minimize window "Color Filter"',"data-button-status":"expanded"},(t,e)=>{e.onclick=()=>{const i=document.querySelector("#bm-2");i&&(i.style.display="expanded"==e.dataset.buttonStatus?"none":""),t.wt(e)},e.ontouchend=()=>{e.click()}}).D().L().I({id:"bm-2",class:"bm-y",style:"font-weight: 700;"}).D().D().L({class:"bm-D"}).lt({class:"bm-s",innerHTML:'<svg class="bm-1Z" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M8.5 4.5H4.5v4M15.5 4.5h4v4M19.5 15.5v4h-4M8.5 19.5h-4v-4" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/><path d="M4.8 4.8l5.2 5.2M19.2 4.8L14 10M19.2 19.2L14 14M4.8 19.2L10 14" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/></svg>',"aria-label":'Switch to fullscreen mode for "Color Filter"'},(t,e)=>{e.onclick=()=>{i(this,B,z).call(this,!1),i(this,B,F).call(this),this.St()},e.ontouchend=()=>{e.click()}}).D().lt({class:"bm-s",innerHTML:ot,"aria-label":'Close window "Color Filter"'},(t,e)=>{e.onclick=()=>i(this,B,F).call(this),e.ontouchend=()=>{e.click()}}).D().D().D().L({class:"bm-m"}).L({class:"bm-L bm-h bm-1N"}).W(1,{textContent:"Color Filter"}).D().D().F().D().L({class:"bm-L bm-x bm-h bm-1F",style:"gap: 1.5ch;"}).lt({class:"bm-1u",textContent:"None"},(t,e)=>{e.onclick=()=>i(this,B,Z).call(this,!1)}).D().lt({class:"bm-1u",textContent:"All"},(t,e)=>{e.onclick=()=>i(this,B,Z).call(this,!0)}).D().D().F().D().L({class:"bm-L bm-H bm-1r"}).D().D().L({class:"bm-1O",title:"Resize Color Filter window","aria-label":"Resize Color Filter window",role:"presentation",textContent:"◢",style:"position: absolute; right: 0; bottom: 0; width: 28px; height: 28px; display: flex; align-items: flex-end; justify-content: flex-end; padding-right: 4px; padding-bottom: 4px; box-sizing: border-box; z-index: 5; cursor: nwse-resize; pointer-events: auto; touch-action: none; user-select: none; font-size: 8px; line-height: 1; color: rgba(255,255,255,0.95); background: transparent; border: none; box-shadow: none;"}).D().D().N(this.Tt),i(this,B,X).call(this);const t=document.querySelector(`#${this.Ct} .bm-L.bm-H`);i(this,B,_).call(this,t),i(this,B,W).call(this),i(this,B,q).call(this,this.sortPrimary,this.sortSecondary,this.showUnused),i(this,B,U).call(this)}ve(){i(this,B,K).call(this);const t=document.querySelector(`#${this.Zt}`),e={};for(const t of this.palette){const i=this.pe.get(t.id)??0,s=n(i);let a=0,r="0",l=o(1);0!=i&&(a=this.fe.get(t.id)??"???","number"!=typeof a&&this.ue==this.be&&t.id&&(a=0),r="string"==typeof a?a:n(a),l=isNaN(a/i)?"???":o(a/i));const c=parseInt(i)-parseInt(a);e[t.id]={Me:i,Ce:s,Te:a,Se:r,ke:l,De:c}}if(document.querySelector("#bm-2")){const t=this.ge.toString().length>7?this.ge.toString().slice(0,2)+"…"+this.ge.toString().slice(-3):this.ge.toString(),e=this.we.toString().length>7?this.we.toString().slice(0,2)+"…"+this.we.toString().slice(-3):this.we.toString();this.ht("#bm-2",`${t}/${e}`,!0)}if(this.ht("#bm-i",`<b>Tiles Loaded:</b> ${n(this.ue)} / ${n(this.be)}`),this.ht("#bm-d",`<b>Correct Pixels:</b> ${n(this.ge)}`),this.ht("#bm-j",`<b>Total Pixels:</b> ${n(this.we)}`),this.ht("#bm-7",`<b>Remaining:</b> ${n((this.we||0)-(this.ge||0))} (${o(((this.we||0)-(this.ge||0))/(this.we||1))})`),this.ht("#bm-8",`<b>Completed at:</b> <time datetime="${this.timeRemaining.toISOString().replace(/\.\d{3}Z$/,"Z")}">${this.xe}</time>`),!t)return e;const s=Array.from(t.children);for(const t of s){const i=parseInt(t.dataset.id),{Te:s,Se:n,ke:o,Me:a,Ce:r,De:l}=e[i];t.dataset.correct=Number.isNaN(parseInt(s))?"0":s,t.dataset.total=a,t.dataset.percent="%"==o.slice(-1)?o.slice(0,-1):"0",t.dataset.incorrect=l||0;const c=document.querySelector(`#${this.Ct} .bm-z[data-id="${i}"] .bm-9`);c&&(c.textContent=`${n} / ${r}`);const h=document.querySelector(`#${this.Ct} .bm-z[data-id="${i}"] .bm-6`);h&&(h.textContent=`${"number"!=typeof l||isNaN(l)?"???":l} incorrect pixel${1==l?"":"s"}. Completed: ${o}`)}i(this,B,q).call(this,this.sortPrimary,this.sortSecondary,this.showUnused)}};B=new WeakSet,P=function(){var t,e;return this.$?((t=this.$.Nt)[e=this.Qt]??(t[e]={}),this.$.Nt[this.Qt]):null},A=function(){const t=i(this,B,P).call(this);return"windowed"==t?.mode||"fullscreen"!=t?.mode},z=function(t){const e=i(this,B,P).call(this);e&&(e.mode=t?"windowed":"fullscreen"),this.$&&(this.$.Ne(this.Kt,t),this.$.Le())},W=function(){const t=document.querySelector(`#${this.Ct} #bm-c`),e=document.querySelector(`#${this.Ct} #bm-5`),i=document.querySelector(`#${this.Ct} #bm-e`);t instanceof HTMLSelectElement&&(t.value=this.sortPrimary),e instanceof HTMLSelectElement&&(e.value=this.sortSecondary),i instanceof HTMLInputElement&&(i.checked=this.showUnused)},F=function(){const t=document.querySelector(`#${this.Ct}`);t?.classList.contains("bm-N")&&i(this,B,Y).call(this,t),i(this,B,V).call(this),i(this,B,G).call(this),t?.remove()},U=function(){i(this,B,V).call(this),this.se=setInterval(()=>{document.querySelector(`#${this.Ct}`)?this.ve():i(this,B,V).call(this)},this.ne)},V=function(){this.se&&(clearInterval(this.se),this.se=null)},G=function(){this.te&&(this.te.disconnect(),this.te=null),this.ee&&(window.removeEventListener("resize",this.ee),this.ee=null),this.ie&&(clearTimeout(this.ie),this.ie=null)},R=function(t,e,i){const s=Math.max(e,i);return Math.min(Math.max(Math.round(Number(t)||e),e),s)},j=function(t,e,i){const s=Math.max(8,window.innerWidth-t.offsetWidth-8),n=Math.max(8,window.innerHeight-t.offsetHeight-8);return{x:Math.min(Math.max(Math.round(Number(e)||8),8),s),y:Math.min(Math.max(Math.round(Number(i)||8),8),n)}},E=function(t){const e=i(this,B,P).call(this);if(!e||!t)return;const s=Number(e.width),n=Number(e.height),o=Number.isFinite(s),a=Number.isFinite(n);o&&(e.width=i(this,B,R).call(this,s,this.oe,Math.min(this.re,window.innerWidth-16)),t.style.width=`${e.width}px`),a&&(e.height=i(this,B,R).call(this,n,this.ae,Math.min(this.le,window.innerHeight-16)),t.style.height=`${e.height}px`),requestAnimationFrame(()=>{if(!t.isConnected)return;const s=Number(e.x),n=Number(e.y);if(!Number.isFinite(s)||!Number.isFinite(n))return;const o=i(this,B,j).call(this,t,s,n);t.style.left="0px",t.style.top="0px",t.style.right="",t.style.transform=`translate(${o.x}px, ${o.y}px)`,o.x==s&&o.y==n||(e.x=o.x,e.y=o.y,this.$?.Le())})},Y=function(t){const e=i(this,B,P).call(this);if(!e||!t?.isConnected||!t.classList.contains("bm-N"))return;if(t.querySelector('.bm-S button[data-button-status="collapsed"]'))return;const s=t.getBoundingClientRect(),n=i(this,B,R).call(this,s.width,this.oe,Math.min(this.re,window.innerWidth-16)),o=i(this,B,R).call(this,s.height,this.ae,Math.min(this.le,window.innerHeight-16));Math.round(s.width)!=n&&(t.style.width=`${n}px`),Math.round(s.height)!=o&&(t.style.height=`${o}px`);const a=i(this,B,j).call(this,t,s.left,s.top);t.style.left="0px",t.style.top="0px",t.style.right="",t.style.transform=`translate(${a.x}px, ${a.y}px)`,e.x=a.x,e.y=a.y,e.width=n,e.height=o,this.$?.Le()},J=function(t,e=150){this.ie&&clearTimeout(this.ie),this.ie=setTimeout(()=>{this.ie=null,i(this,B,Y).call(this,t)},e)},X=function(){const t=document.querySelector(`#${this.Ct}.bm-W`);t&&(i(this,B,G).call(this),i(this,B,E).call(this,t),this.xt(`#${this.Ct}.bm-W`,`#${this.Ct} .bm-S`,{yt:({element:t})=>i(this,B,Y).call(this,t)}),this.vt(`#${this.Ct}.bm-W`,`#${this.Ct} .bm-1O`,{minWidth:this.oe,minHeight:this.ae,maxWidth:Math.min(this.re,window.innerWidth-16),maxHeight:Math.min(this.le,window.innerHeight-16),yt:({element:t})=>i(this,B,Y).call(this,t)}),"function"==typeof ResizeObserver&&(this.te=new ResizeObserver(()=>i(this,B,J).call(this,t)),this.te.observe(t)),this.ee=()=>i(this,B,J).call(this,t,0),window.addEventListener("resize",this.ee))},_=function(t){const e=t.closest(`#${this.Ct}`)?.classList.contains("bm-N");console.log(`Is Windowed Mode: ${e}`);const i=new v(this.name,this.version);i.L({id:this.Zt});const s=this.ve();for(const t of this.palette){const n="#"+f(t.rgb).toUpperCase(),o=p(t.rgb);let a=1.05/(o+.05)>(o+.05)/.05?"white":"black";t.id||(a="transparent");const r="white"==a?"bm-f":"bm-g",{Te:l,Se:c,ke:h,Me:m,Ce:d,De:u}=s[t.id],b=!!this.ce.He.get(t.id);if(e){const e=`background-size: auto 100%; background-repeat: repeat-x; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><path d='M50,5L79,91L2,39L98,39L21,91' fill='${a}' fill-opacity='.1'/></svg>");`;i.L({class:"bm-L bm-z bm-x","data-id":t.id,"data-name":t.name,"data-premium":+t.premium,"data-correct":Number.isNaN(parseInt(l))?"0":l,"data-total":m,"data-percent":"%"==h.slice(-1)?h.slice(0,-1):"0","data-incorrect":u||0}).L({class:"bm-a",style:`background-color: rgb(${t.rgb?.map(t=>Number(t)||0).join(",")});${t.premium?e:""}`}).lt({class:"bm-A "+r,"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.me:this.he,style:`color: ${a};`},(e,i)=>{i.onclick=()=>{i.style.textDecoration="none",i.disabled=!0,"shown"==i.dataset.state?(i.innerHTML=this.me,i.dataset.state="hidden",i.ariaLabel=`Show the color ${t.name||""} on templates.`,this.ce.Oe(t.id,!0)):(i.innerHTML=this.he,i.dataset.state="shown",i.ariaLabel=`Hide the color ${t.name||""} on templates.`,this.ce.Oe(t.id,!1)),i.disabled=!1,i.style.textDecoration=""},t.id||(i.disabled=!0)}).D().O({textContent:`#${t.id.toString().padStart(2,0)}`,style:`color: ${-1==t.id||0==t.id?"white":a}`}).D().W(2,{textContent:t.name,style:`color: ${-1==t.id||0==t.id?"white":a}`}).D().O({class:"bm-9",textContent:`${c} / ${d}`,style:`color: ${-1==t.id||0==t.id?"white":a}; flex: 1 1 auto; text-align: right;`}).D().D().D()}else i.L({class:"bm-L bm-z bm-x","data-id":t.id,"data-name":t.name,"data-premium":+t.premium,"data-correct":Number.isNaN(parseInt(l))?"0":l,"data-total":m,"data-percent":"%"==h.slice(-1)?h.slice(0,-1):"0","data-incorrect":u||0}).L({class:"bm-D",style:"flex-direction: column;"}).L({class:"bm-a",style:`background-color: rgb(${t.rgb?.map(t=>Number(t)||0).join(",")});`}).lt({class:"bm-A "+r,"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.me:this.he,style:`color: ${a};`},(e,i)=>{i.onclick=()=>{i.style.textDecoration="none",i.disabled=!0,"shown"==i.dataset.state?(i.innerHTML=this.me,i.dataset.state="hidden",i.ariaLabel=`Show the color ${t.name||""} on templates.`,this.ce.Oe(t.id,!0)):(i.innerHTML=this.he,i.dataset.state="shown",i.ariaLabel=`Hide the color ${t.name||""} on templates.`,this.ce.Oe(t.id,!1)),i.disabled=!1,i.style.textDecoration=""},t.id||(i.disabled=!0)}).D().D().O({textContent:-2==t.id?"???????":n}).D().D().L({class:"bm-x"}).W(2,{textContent:(t.premium?"★ ":"")+t.name}).D().L({class:"bm-x",style:"gap: 1.5ch;"}).O({textContent:`#${t.id.toString().padStart(2,0)}`}).D().O({class:"bm-9",textContent:`${c} / ${d}`}).D().D().H({class:"bm-6",textContent:`${"number"!=typeof u||isNaN(u)?"???":u} incorrect pixel${1==u?"":"s"}. Completed: ${h}`}).D().D().D()}i.N(t)},q=function(t,e,i){this.sortPrimary=t,this.sortSecondary=e,this.showUnused=i;const s=document.querySelector(`#${this.Zt}`),n=Array.from(s.children);n.sort((s,n)=>{const o=s.getAttribute("data-"+t),a=n.getAttribute("data-"+t),r=parseFloat(o),l=parseFloat(a),c=!isNaN(r),h=!isNaN(l);if(i?s.classList.remove("bm-I"):Number(s.getAttribute("data-total"))||s.classList.add("bm-I"),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}}),n.forEach(t=>s.appendChild(t))},Z=function(t){const e=document.querySelector(`#${this.Zt}`),i=Array.from(e.children);for(const e of i){if(e.classList?.contains("bm-I"))continue;const i=e.querySelector(".bm-a button");("hidden"!=i.dataset.state||t)&&("shown"==i.dataset.state&&t||i.click())}},K=function(){this.ue=0,this.be=0,this.we=0,this.ge=0,this.fe=new Map,this.pe=new Map;for(const t of this.ce.Ie){const e=t.Pt?.total??0;this.we+=e??0;const i=t.Pt?.colors??new Map;for(const[t,e]of i){const i=Number(e)||0,s=this.pe.get(t)??0;this.pe.set(t,s+i)}const s=t.Pt?.correct??{};this.ue+=Object.keys(s).length,this.be+=Object.keys(t.Ot).length;for(const t of Object.values(s))for(const[e,i]of t){const t=Number(i)||0;this.ge+=t;const s=this.fe.get(e)??0;this.fe.set(e,s+t)}}console.log(`Tiles loaded: ${this.ue} / ${this.be}`),this.ge>=this.we&&this.we&&this.ue==this.be&&(new O).qt(document.querySelector(`#${this.Ct}`)),this.timeRemaining=new Date(30*(this.we-this.ge)*1e3+Date.now()),this.xe=a(this.timeRemaining)},Q=new WeakSet,tt=async function(t,e,i){i.preventDefault();const s=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=>{l("Failed to retrieve clipboard data using navigator! Using fallback methods...")}),0!=e.length||(e=window.clipboardData?.getData("Text"))),e}(i),n=s.split(/[^a-zA-Z0-9]+/).filter(t=>t).map(Number).filter(t=>!isNaN(t));2==n.length&&"bm-O"==e.id?(t.ht("bm-O",n?.[0]||""),t.ht("bm-P",n?.[1]||"")):1==n.length?t.ht(e.id,n?.[0]||""):(t.ht("bm-Q",n?.[0]||""),t.ht("bm-R",n?.[1]||""),t.ht("bm-O",n?.[2]||""),t.ht("bm-P",n?.[3]||""))};var lt=class extends v{constructor(t,i,s,n=void 0){super(t,i),e(this,et),this.window=null,this.Ct="bm-u",this.Tt=document.body,this.Be=JSON.parse(GM_getValue("bmTemplates","{}")),this.scriptVersion=this.Be?.scriptVersion,this.schemaVersion=this.Be?.schemaVersion,this.Pe=void 0,this.Ae=s,this.ce=n}St(){if(document.querySelector(`#${this.Ct}`))return void document.querySelector(`#${this.Ct}`).remove();let t="";document.querySelector("#bm-F")||(t=t.concat("z-index: 9001;").trim()),this.window=this.L({id:this.Ct,class:"bm-W",style:t},(t,e)=>{}).ft().lt({class:"bm-s",innerHTML:$,"aria-label":'Minimize window "Template Wizard"',"data-button-status":"expanded"},(t,e)=>{e.onclick=()=>t.wt(e),e.ontouchend=()=>{e.click()}}).D().L().D().lt({class:"bm-s",textContent:"✖","aria-label":'Close window "Template Wizard"'},(t,e)=>{e.onclick=()=>{document.querySelector(`#${this.Ct}`)?.remove()},e.ontouchend=()=>{e.click()}}).D().D().L({class:"bm-m"}).L({class:"bm-L bm-h"}).W(1,{textContent:"Template Wizard"}).D().D().F().D().L({class:"bm-L"}).W(2,{textContent:"Status"}).D().H({id:"bm-v",textContent:"Loading template storage status..."}).D().D().L({class:"bm-L bm-H"}).W(2,{textContent:"Detected templates:"}).D().D().D().D().N(this.Tt),this.xt(`#${this.Ct}.bm-W`,`#${this.Ct} .bm-S`),i(this,et,it).call(this),i(this,et,st).call(this)}};et=new WeakSet,it=function(){const t=this.schemaVersion.split(/[-\.\+]/),e=this.Ae.split(/[-\.\+]/);let s="";t[0]==e[0]?t[1]==e[1]?(s='Template storage health: <b style="color:#0f0;">Healthy!</b><br>No futher action required. (Reason: Semantic version matches)',this.Pe="Good"):(s='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.Pe="Poor"):t[0]<e[0]?(s='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.Pe="Bad"):(s='Template storage health: <b style="color:#f00">Dead!</b><br>Blue Marble can not load the template storage. (Reason: MAJOR version unknown)',this.Pe="Dead");const n=`<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>${r(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.`,o=function(){const t=[...document.querySelectorAll("body > div > .hidden")].filter(t=>/version:/i.test(t.textContent));if(t[0]){const e=t[0].textContent?.match(/\d+/);return e?new Date(Number(e[0])):void 0}}();let l=o?a(o):"???";this.ht("#bm-v",`${s}<br>Your templates were created during Blue Marble version <b>${r(this.scriptVersion)}</b> with schema version <b>${r(this.schemaVersion)}</b>.<br>The current Blue Marble version is <b>${r(this.version)}</b> and requires schema version <b>${r(this.Ae)}</b>.<br>Wplace was last updated on <b>${l}</b>.${"Good"!=this.Pe?n:""}`);const c=new v(this.name,this.version);"Dead"!=this.Pe&&(c.L({class:"bm-L bm-D bm-h",style:"gap: 1.5ch;"}),c.lt({textContent:"Download all templates"},(t,e)=>{e.onclick=()=>{e.disabled=!0,this.ce.ze().then(()=>{e.disabled=!1})}}).D()),"Poor"!=this.Pe&&"Bad"!=this.Pe||c.lt({textContent:`Update template storage to ${this.Ae}`},(t,e)=>{e.onclick=()=>{e.disabled=!0,i(this,et,nt).call(this,!0)}}).D(),c.D().N(document.querySelector("#bm-v").parentNode)},st=function(){const t=this.Be?.templates;if(Object.keys(t).length>0){const e=document.querySelector(`#${this.Ct} .bm-H`),i=new v(this.name,this.version);i.L({id:"bm-B",class:"bm-L"});for(const e in t){const s=e,o=t[e];if(t.hasOwnProperty(e)){const t=s.split(" "),e=Number(t?.[0]),a=d(t?.[1]||"0",this.ce.We),r=o.name||`Template ${e||""}`,l=o?.coords?.split(",").map(Number),c=o.pixels?.total??void 0,h=void 0,m="number"==typeof e?n(e):"???",u="number"==typeof a?n(a):"???",b="number"==typeof c?n(c):"???";i.L({class:"bm-L bm-D"}).L({class:"bm-D",style:"flex-direction: column; gap: 0;"}).L({class:"bm-1",textContent:h||"🖼"}).D().O({textContent:`#${m}`}).D().D().L({class:"bm-D bm-0"}).W(3,{textContent:r}).D().I({textContent:`Uploaded by user #${u}`}).D().I({textContent:`Coordinates: ${l.join(", ")}`}).D().I({textContent:`Total Pixels: ${b}`}).D().D().D()}}i.D().N(e)}},nt=async function(t){if(t){const t=document.querySelector(`#${this.Ct} .bm-m`);t.innerHTML="",new v(this.name,this.version).L({class:"bm-L"}).L({class:"bm-L bm-h"}).W(1,{textContent:"Template Wizard"}).D().D().F().D().L({class:"bm-L"}).W(2,{textContent:"Status"}).D().H({textContent:"Updating template storage. Please wait..."}).D().D().D().N(t)}GM_deleteValue("bmCoords");const e=this.Be?.templates;if(Object.keys(e).length>0)for(const[t,i]of Object.entries(e))if(e.hasOwnProperty(t)){const t=new H({displayName:i.name,Ot:i.tiles});t.Yt();const e=await this.ce.Fe(t);await this.ce.Ue(e,t.displayName,t.coords)}t&&(console.log("Restarting Template Wizard..."),document.querySelector(`#${this.Ct}`).remove(),new lt(this.name,this.version,this.Ae,this.ce).St())};var ct,ht,mt,dt,ut,bt,pt,ft,gt=lt;ct=new WeakSet,ht=function(){const t=this.$?.Nt?.filter,e=Array.isArray(t)?t:[];this.He.clear();for(const t of e){const e=Number(t);Number.isFinite(e)&&this.He.set(e,!0)}},mt=function(){this.$&&(this.$.Nt.filter=Array.from(this.He.keys()).map(t=>Number(t)).filter(t=>Number.isFinite(t)).sort((t,e)=>t-e),this.$.Le())},dt=async function(){GM.setValue("bmTemplates",JSON.stringify(this.Ve))},ut=async function(t){console.log("Parsing BlueMarble...");const e=t.templates;console.log(`BlueMarble length: ${Object.keys(e).length}`);const i=t?.schemaVersion,s=i.split(/[-\.\+]/),n=this.schemaVersion.split(/[-\.\+]/),o=t?.scriptVersion;console.log(`BlueMarble Template Schema: ${i}; Script Version: ${o}`),s[0]==n[0]?(s[1]!=n[1]&&new gt(this.name,this.version,this.schemaVersion,this).St(),this.Ie=await async function({Bt:t,Ge:i,Ie:s}){if(Object.keys(e).length>0)for(const n in e){const o=n,a=e[n];if(console.log(`Template Key: ${o}`),e.hasOwnProperty(n)){const e=o.split(" "),n=Number(e?.[0]),r=e?.[1]||"0",l=a.name||`Template ${n||""}`,c={total:a.pixels?.total,colors:new Map(Object.entries(a.pixels?.colors||{}).map(([t,e])=>[Number(t),e]))},h=a.tiles,m={},d={},u=t*i;for(const t in h)if(console.log(t),h.hasOwnProperty(t)){const e=b(h[t]),i=new Blob([e],{type:"image/png"}),s=await createImageBitmap(i);m[t]=s;const n=new OffscreenCanvas(u,u).getContext("2d");n.drawImage(s,0,0);const o=n.getImageData(0,0,s.width,s.height);d[t]=new Uint32Array(o.data.buffer)}const p=new H({displayName:l,Lt:n||this.Ie?.length||0,Ht:r||""});p.Pt=c,p.Ot=m,p.It=d,s.push(p),console.log(this.Ie),console.log("^^^ This ^^^")}}return s}({Bt:this.Bt,Ge:this.Ge,Ie:this.Ie})):s[0]<n[0]?new gt(this.name,this.version,this.schemaVersion,this).St():this.Re.$t(`Template version ${i} is unsupported.\nUse Blue Marble version ${o} or load a new template.`)},bt=function({je:t,Ee:e,Ye:i,Je:s,Xe:n}){const o=this.Ge,a=this.Bt*o,r=i[0],l=i[1],c=i[2],h=i[3],m=this._e,d=!this.$?.Nt?.flags?.includes("hl-noTrans"),{palette:u,Jt:b}=this.de,p=new Map;for(let i=1;i<h;i+=o)for(let h=1;h<c;h+=o){const u=l+i+-1,f=r+h+0,g=t[u*a+f],w=e[i*c+h],x=w>>>24&255,y=g>>>24&255,$=b.get(w)??-2,v=b.get(g)??-2;if(this.He.get($)&&(e[i*c+h]=g),-1==$){const t=536870912;this.He.get($)?e[i*c+h]=0:(u/o&1)==(f/o&1)?(e[i*c+h]=t,e[(i-1)*c+(h-1)]=t,e[(i-1)*c+(h+1)]=t,e[(i+1)*c+(h-1)]=t,e[(i+1)*c+(h+1)]=t):(e[i*c+h]=0,e[(i-1)*c+h]=t,e[(i+1)*c+h]=t,e[i*c+(h-1)]=t,e[i*c+(h+1)]=t)}if(!n&&x>m&&v!=$&&(d||y>m)){const t=e[i*c+h];for(const n of s){const[s,o,a]=n,r=0!=s?1!=s?t:4278190335:0;e[(i+a)*c+(h+o)]=r}}if(-1==$&&g<=m){const t=p.get($);p.set($,t?t+1:1);continue}if(x<=m||y<=m)continue;if(v!=$)continue;const M=p.get($);p.set($,M?M+1:1)}return console.log("List of template pixels that match the tile:"),console.log(p),{qe:p,Ze:e}},pt=new WeakSet,ft=function(t){const e=JSON.parse(GM_getValue("bmUserSettings","{}"));e.telemetry=t,GM.setValue("bmUserSettings",JSON.stringify(e))};var wt=GM_info.script.name.toString(),xt=GM_info.script.version.toString();!function(t){const e=document.createElement("script");e.setAttribute("bm-11",wt),e.setAttribute("bm-X","color: cornflowerblue;"),e.textContent=`(${t})();`,document.documentElement?.appendChild(e),e.remove()}(()=>{const t=document.currentScript,e=t?.getAttribute("bm-11")||"Blue Marble",i=t?.getAttribute("bm-X")||"",s=new Map;window.addEventListener("message",t=>{const{source:n,endpoint:o,blobID:a,blobData:r,blink:l}=t.data,c=Date.now()-l;if(console.groupCollapsed(`%c${e}%c: ${s.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(s),console.groupEnd(),"blue-marble"==n&&a&&r&&!o){const t=s.get(a);"function"==typeof t?t(r):h(`%c${e}%c: Attempted to retrieve a blob (%s) from queue, but the blobID was not a function! Skipping...`,i,"",a),s.delete(a)}});const n=window.fetch;window.fetch=async function(...t){const o=await n.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=>{const s=r?.split("?")[0].split("/").filter(t=>t&&isNaN(Number(t))).filter(t=>t&&!t.includes(".")).pop();if("me"==s)try{sessionStorage.setItem("bm-2m",JSON.stringify(t))}catch(t){console.warn(`%c${e}%c: Failed to cache "/me" payload`,i,"",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(),n=await a.blob();return console.log(`%c${e}%c: ${s.size} Sending IMAGE message about endpoint "${r}"`,i,""),new Promise(o=>{const l=crypto.randomUUID();s.set(l,t=>{o(new Response(t,{headers:a.headers,status:a.status,statusText:a.statusText})),console.log(`%c${e}%c: ${s.size} Processed blob "${l}"`,i,"")}),window.postMessage({source:"blue-marble",endpoint:r,blobID:l,blobData:n,blink:t})}).catch(n=>{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 ${s.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:",n),console.groupEnd()})}return o}});var yt=GM_getResourceText("CSS-BM-File");function $t(t){const e=document.createElement("link");e.href=t,e.rel="preload",e.as="style",e.onload=function(){this.onload=null,this.rel="stylesheet"},document.head?.appendChild(e)}GM_addStyle(yt);var vt="robotoMonoInjectionPoint";$t("https://fonts.googleapis.com/css2?family=Michroma&family=Rajdhani:wght@400;500;600;700&display=swap"),vt.indexOf("@font-face")+1?(console.log("Loading Roboto Mono as a file..."),GM_addStyle(vt)):$t("https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap");var Mt=JSON.parse(GM_getValue("bmUserSettings","{}")),Ct=(new class{constructor(){this.Ke=null,this.Qe=null,this.ti="#bm-p"}ei(t){return this.Qe=t,this.Ke=new MutationObserver(t=>{for(const e of t)for(const t of e.addedNodes)t instanceof HTMLElement&&t.matches?.(this.ti)}),this}ii(){return this.Ke}observe(t,e=!1,i=!1){t.observe(this.Qe,{childList:e,subtree:i})}},new class extends v{constructor(t,i){super(t,i),e(this,Q),this.window=null,this.Ct="bm-F",this.Tt=document.body}St(){document.querySelector(`#${this.Ct}`)?this.$t("Main window already exists!"):(this.window=this.L({id:this.Ct,class:"bm-W bm-N",style:"top: 10px; left: unset; right: 75px;"},(t,e)=>{}).ft().lt({class:"bm-s",innerHTML:$,"aria-label":'Minimize window "Blue Marble"',"data-button-status":"expanded"},(t,e)=>{e.onclick=()=>t.wt(e),e.ontouchend=()=>{e.click()}}).D().L().D().L({class:"bm-D"}).lt({class:"bm-s",innerHTML:'<svg class="bm-1Z bm-1g" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M5 7h14M5 12h14M5 17h14"/><circle cx="9" cy="7" r="1.7" fill="currentColor" stroke="none"/><circle cx="15" cy="12" r="1.7" fill="currentColor" stroke="none"/><circle cx="11" cy="17" r="1.7" fill="currentColor" stroke="none"/></g></svg>',title:"Settings","aria-label":"Open settings"},(t,e)=>{e.onclick=()=>{t.$.St()}}).D().D().D().L({class:"bm-m"}).F().D().L({class:"bm-L bm-2d"}).A({class:"bm-T",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 O).qt(document.querySelector(`#${this.Ct}`))})}).D().W(1,{textContent:this.name}).D().D().F().D().L({class:"bm-L bm-28"}).L({class:"bm-1I bm-1h"}).I({class:"bm-1B",textContent:"Droplets"}).D().I({id:"bm-w",class:"bm-1C",textContent:"0"}).D().D().L({class:"bm-1I bm-1h"}).I({class:"bm-1B",textContent:"Next Level"}).D().I({id:"bm-q",class:"bm-1C",textContent:"0 px"}).D().D().L({class:"bm-1I bm-1i"}).I({class:"bm-1B",textContent:"Charges"}).D().gt(Date.now(),1e3,{class:"bm-1C",style:"font-weight: 700;"},(t,e)=>{t.p.si=e.id}).D().D().D().F().D().L({class:"bm-L bm-29"}).L({class:"bm-L bm-22"}).lt({class:"bm-s bm-J",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.p?.ni;e?.[0]?(t.ht("bm-Q",e?.[0]||""),t.ht("bm-R",e?.[1]||""),t.ht("bm-O",e?.[2]||""),t.ht("bm-P",e?.[3]||"")):t.$t("Coordinates are malformed! Did you try clicking on the canvas first?")}}).D().dt({type:"number",id:"bm-Q",class:"bm-C",placeholder:"Tl X",min:0,max:2047,step:1,required:!0},(t,e)=>{e.addEventListener("paste",s=>i(this,Q,tt).call(this,t,e,s))}).D().dt({type:"number",id:"bm-R",class:"bm-C",placeholder:"Tl Y",min:0,max:2047,step:1,required:!0},(t,e)=>{e.addEventListener("paste",s=>i(this,Q,tt).call(this,t,e,s))}).D().dt({type:"number",id:"bm-O",class:"bm-C",placeholder:"Px X",min:0,max:2047,step:1,required:!0},(t,e)=>{e.addEventListener("paste",s=>i(this,Q,tt).call(this,t,e,s))}).D().dt({type:"number",id:"bm-P",class:"bm-C",placeholder:"Px Y",min:0,max:2047,step:1,required:!0},(t,e)=>{e.addEventListener("paste",s=>i(this,Q,tt).call(this,t,e,s))}).D().D().L({class:"bm-L bm-23"}).ut({class:"bm-K",textContent:"Upload Template",accept:"image/png, image/jpeg, image/webp, image/bmp, image/gif"}).D().D().L({class:"bm-L bm-x bm-1Y"}).lt({class:"bm-1u",textContent:"Disable","data-button-status":"shown"},(t,e)=>{e.onclick=()=>{e.disabled=!0,"shown"==e.dataset.buttonStatus?(t.p?.ce?.oi(!1),e.dataset.buttonStatus="hidden",e.textContent="Enable",t.Mt("Disabled templates!")):(t.p?.ce?.oi(!0),e.dataset.buttonStatus="shown",e.textContent="Disable",t.Mt("Enabled templates!")),e.disabled=!1}}).D().lt({class:"bm-1G",textContent:"Create"},(t,e)=>{e.onclick=()=>{const e=document.querySelector(`#${this.Ct} .bm-K`),i=document.querySelector("#bm-Q");if(!i.checkValidity())return i.reportValidity(),void t.$t("Coordinates are malformed! Did you try clicking on the canvas first?");const s=document.querySelector("#bm-R");if(!s.checkValidity())return s.reportValidity(),void t.$t("Coordinates are malformed! Did you try clicking on the canvas first?");const n=document.querySelector("#bm-O");if(!n.checkValidity())return n.reportValidity(),void t.$t("Coordinates are malformed! Did you try clicking on the canvas first?");const o=document.querySelector("#bm-P");if(!o.checkValidity())return o.reportValidity(),void t.$t("Coordinates are malformed! Did you try clicking on the canvas first?");e?.files[0]?(t?.p?.ce.Ue(e.files[0],e.files[0]?.name.replace(/\.[^/.]+$/,""),[Number(i.value),Number(s.value),Number(n.value),Number(o.value)]),t.Mt("Drew to canvas!")):t.$t("No file selected!")}}).D().lt({class:"bm-1u",textContent:"Filter"},(t,e)=>{e.onclick=()=>this.ai()}).D().D().L({class:"bm-L bm-24"}).bt({id:this.v,placeholder:`Status: Sleeping...\nVersion: ${this.version}`,readOnly:!0}).D().D().D().D().D().N(this.Tt),this.xt(`#${this.Ct}.bm-W`,`#${this.Ct} .bm-S`))}ai(){new rt(this).ye()}}(wt,xt)),Tt=new class{constructor(t,i){e(this,ct),this.name=t,this.version=i,this.Re=null,this.$=null,this.schemaVersion="2.0.0",this.ri=null,this.We="!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~",this.Bt=1e3,this.Ge=3,this._e=3,this.de=function(t){const e=y;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 s of e){if(0==s.id||-2==s.id)continue;const e=s.rgb[0],n=s.rgb[1],o=s.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=n+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,s.id)}}return{palette:e,Jt:i}}(this._e),this.Ee=null,this.li="",this.Ie=[],this.Ve=null,this.ci=!0,this.hi=null,this.He=new Map}mi(t){this.Re=t}k(t){this.$=t,i(this,ct,ht).call(this)}Oe(t,e){const s=Number(t);Number.isFinite(s)&&(e?this.He.set(s,!0):this.He.delete(s),i(this,ct,mt).call(this))}async di(){return{whoami:this.name.replace(" ",""),scriptVersion:this.version,schemaVersion:this.schemaVersion,templates:{}}}async Ue(t,e,s){this.Ve||(this.Ve=await this.di(),console.log("Creating JSON...")),this.Re.Mt(`Creating template at ${s.join(", ")}...`);const n=new H({displayName:e,Lt:0,Ht:m(this.ri||0,this.We),file:t,coords:s}),o=!this.$?.Nt?.flags?.includes("hl-noSkip"),a=this.$?.Nt?.flags?.includes("hl-agSkip");console.log(`Should Skip: ${o}; Should Agg Skip: ${a}`);const{jt:r,Et:l}=await n.Wt(this.Bt,this.de,o,a);n.Ot=r;const c={total:n.Pt.total,colors:Object.fromEntries(n.Pt.colors)};this.Ve.templates[`${n.Lt} ${n.Ht}`]={name:n.displayName,coords:s.join(", "),enabled:!0,pixels:c,tiles:l},this.Ie=[],this.Ie.push(n),this.Re.Mt(`Template created at ${s.join(", ")}!`),console.log(Object.keys(this.Ve.templates).length),console.log(this.Ve),console.log(this.Ie),console.log(JSON.stringify(this.Ve)),await i(this,ct,dt).call(this)}ui(){}async bi(){this.Ve||(this.Ve=await this.di(),console.log("Creating JSON..."))}async pi(){l("Downloading all templates..."),console.log(this.Ie);for(const t of this.Ie)await this.fi(t),await s(500)}async ze(){const t=JSON.parse(GM_getValue("bmTemplates","{}"))?.templates;if(console.log(t),Object.keys(t).length>0)for(const[e,i]of Object.entries(t))t.hasOwnProperty(e)&&(await this.fi(new H({displayName:i.name,Lt:e.split(" ")?.[0],Ht:e.split(" ")?.[1],Ot:i.tiles})),await s(500))}async fi(t){t.Yt();const e=`${t.coords.join("-")}_${t.displayName.replaceAll(" ","-")}`,i=await this.Fe(t);await GM.download({url:URL.createObjectURL(i),name:e+".png",gi:"uniquify",onload:()=>{l(`Download of template '${e}' complete!`)},onerror:(t,i)=>{c(`Download of template '${e}' failed because ${t}! Details: ${i}`)},ontimeout:()=>{h(`Download of template '${e}' has timed out!`)}})}async Fe(t){console.log(t);const e=t.Ot,i=Object.keys(e).sort(),s=await Promise.all(i.map(t=>{return i=e[t],new Promise((t,e)=>{const s=new Image;s.onload=()=>t(s),s.onerror=e,s.src="data:image/png;base64,"+i});var i}));let n=1/0,o=1/0,a=0,r=0;i.forEach((t,e)=>{const[i,l,c,h]=t.split(",").map(Number),m=s[e],d=i*this.Bt+c,u=l*this.Bt+h;n=Math.min(n,d),o=Math.min(o,u),a=Math.max(a,d+m.width/this.Ge),r=Math.max(r,u+m.height/this.Ge)}),console.log(`Absolute coordinates: (${n}, ${o}) and (${a}, ${r})`);const l=a-n,c=r-o,h=l*this.Ge,m=c*this.Ge;console.log(`Template Width: ${l}\nTemplate Height: ${c}\nCanvas Width: ${h}\nCanvas Height: ${m}`);const d=new OffscreenCanvas(h,m),u=d.getContext("2d");i.forEach((t,e)=>{const[i,a,r,l]=t.split(",").map(Number),c=s[e],h=i*this.Bt+r,m=a*this.Bt+l;console.log(`Drawing tile (${i}, ${a}, ${r}, ${l}) (${h}, ${m}) at (${h-n}, ${m-o}) on the canvas...`),u.drawImage(c,(h-n)*this.Ge,(m-o)*this.Ge,c.width,c.height)}),u.globalCompositeOperation="destination-over",u.drawImage(d,0,-1),u.drawImage(d,0,1),u.drawImage(d,-1,0),u.drawImage(d,1,0);const b=new OffscreenCanvas(l,c),p=b.getContext("2d");return p.imageSmoothingEnabled=!1,p.drawImage(d,0,0,l*this.Ge,c*this.Ge,0,0,l,c),b.convertToBlob({type:"image/png"})}async wi(t,e){if(!this.ci)return t;const s=this.Bt*this.Ge;e=e[0].toString().padStart(4,"0")+","+e[1].toString().padStart(4,"0"),console.log(`Searching for templates in tile: "${e}"`);const o=this.Ie;console.log(o),o.sort((t,e)=>t.Lt-e.Lt),console.log(o);const a=o.map(t=>{const i=Object.keys(t.Ot).filter(t=>t.startsWith(e));if(0===i.length)return null;const s=i.map(e=>{const i=e.split(",");return{xi:t,Ut:t.Ot[e],It:t.It?.[e],yi:[i[0],i[1]],$i:[i[2],i[3]]}});return s?.[0]}).filter(Boolean);console.log(a);const r=a?.length||0;if(console.log(`templateCount = ${r}`),!(r>0))return this.Re.Mt(`Sleeping\nVersion: ${this.version}`),t;{const t=n(o.filter(t=>Object.keys(t.Ot).filter(t=>t.startsWith(e)).length>0).reduce((t,e)=>t+(e.Pt.total||0),0));this.Re.Mt(`Displaying ${r} template${1==r?"":"s"}.\nTotal pixels: ${t}`)}const l=await createImageBitmap(t),c=new OffscreenCanvas(s,s),h=c.getContext("2d");h.imageSmoothingEnabled=!1,h.beginPath(),h.rect(0,0,s,s),h.clip(),h.clearRect(0,0,s,s),h.drawImage(l,0,0,s,s);const m=h.getImageData(0,0,s,s),d=new Uint32Array(m.data.buffer),u=this.$?.Nt?.highlight||[[2,0,0]],b=u?.[0],p=1==u?.length&&2==b?.[0]&&0==b?.[1]&&0==b?.[2];for(const t of a){console.log("Template:"),console.log(t);const s=!!t.xi.Pt?.colors?.get(-1);let n=t.It.slice();const o=Number(t.$i[0])*this.Ge,a=Number(t.$i[1])*this.Ge;if(0!=this.He.size||s||h.drawImage(t.Ut,o,a),!n){const e=h.getImageData(o,a,t.Ut.width,t.Ut.height);n=new Uint32Array(e.data.buffer)}const r=Date.now(),{qe:l,Ze:c}=i(this,ct,bt).call(this,{je:d,Ee:n,Ye:[o,a,t.Ut.width,t.Ut.height],Je:u,Xe:p});let m=0;const b=0;for(const[t,e]of l)t!=b&&(m+=e);0==this.He.size&&!s&&p||(console.log("Colors to filter: ",this.He),h.drawImage(await createImageBitmap(new ImageData(new Uint8ClampedArray(c.buffer),t.Ut.width,t.Ut.height)),o,a)),console.log(`Finished calculating correct pixels & filtering colors for the tile ${e} in ${(Date.now()-r)/1e3} seconds!\nThere are ${m} correct pixels.`),void 0===t.xi.Pt.correct&&(t.xi.Pt.correct={}),t.xi.Pt.correct[e]=l}return await c.convertToBlob({type:"image/png"})}async Mi(t){console.log("Importing JSON..."),console.log(t),"BlueMarble"==t?.whoami&&await i(this,ct,ut).call(this,t)}oi(t){this.ci=t}}(wt,xt),St=new class{constructor(t){this.ce=t,this.Ci=!1,this.si="",this.ni=[],this.Ti=[]}Si(t){window.addEventListener("message",async e=>{const i=e.data,s=i.jsonData;if(!i||"blue-marble"!==i.source)return;if(!i.endpoint)return;const n=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;","",n),n){case"me":this.ki(t,s);break;case"pixel":const e=i.endpoint.split("?")[0].split("/").filter(t=>t&&!isNaN(Number(t))),n=new URLSearchParams(i.endpoint.split("?")[1]),r=[n.get("x"),n.get("y")];if(this.ni.length&&(!e.length||!r.length))return void t.$t("Coordinates are malformed!\nDid you try clicking the canvas first?");this.ni=[...e,...r];const l=(o=e,a=r,[parseInt(o[0])%4*1e3+parseInt(a[0]),parseInt(o[1])%4*1e3+parseInt(a[1])]),c=document.querySelectorAll("span");for(const t of c){const i=t.textContent.trim();if(i.includes(l[0])&&i.includes(l[1])){let i=document.querySelector("#bm-p");e[0],e[1],r[0],r[1];const s=["Tl X:","Tl Y:","Px X:","Px Y:"],n=["bm-Y","bm-Z","bm-U","bm-V"],o=[...e,...r];if(i)for(const[t,e]of n.entries())document.getElementById(e).textContent=`${s[t]??"??:"} ${o[t]}`;else{i=document.createElement("span"),i.id="bm-p",i.style="display: flex; flex-wrap: wrap; gap: 0 1ch; font-size: small;";for(const[t,e]of o.entries()){const a=document.createElement("span");a.id=n[o.indexOf(e)??""],a.textContent=`${s[t]??"??:"} ${e}`,i.appendChild(a)}t.parentNode.parentNode.parentNode.insertAdjacentElement("afterend",i)}}}break;case"tile":case"tiles":let h=i.endpoint.split("/");h=[parseInt(h[h.length-2]),parseInt(h[h.length-1].replace(".png",""))];const m=i.blobID,d=i.blobData,u=Date.now(),b=await this.ce.wi(d,h);console.log(`Finished loading the tile in ${(Date.now()-u)/1e3} seconds!`),window.postMessage({source:"blue-marble",blobID:m,blobData:b,blink:i.blink});break;case"robots":this.Ci="false"==s.userscript?.toString().toLowerCase();break}var o,a})}ki(t,e){if(e.status&&"2"!=e.status?.toString()[0])return void t.$t("You are not logged in or Wplace is offline!\nCould not fetch userdata.");const i=Math.ceil(Math.pow(Math.floor(e.level)*Math.pow(30,.65),1/.65)-e.pixelsPainted);if(console.log(e.id),(e.id||0===e.id)&&console.log(m(e.id,"!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~")),this.ce.ri=e.id,0!=this.si.length){const t=document.querySelector("#"+this.si);if(t){const i=e.charges;t.dataset.endDate=Date.now()+(i.max-i.count)*i.cooldownMs}}t.ht("bm-w",`<b>${n(e.droplets)}</b>`),t.ht("bm-q",`<b>${n(i)}</b> px`)}async Di(t){try{const e=await fetch(`${window.location.origin}/api/me`,{credentials:"include"});if(!e.ok)return void t.$t(`Could not fetch userdata.\nHTTP ${e.status}`);const i=await e.json();this.ki(t,i)}catch(t){c("Failed to fetch current user data:",t)}}Ni(t){try{const e=sessionStorage.getItem("bm-2m");if(!e)return!1;const i=JSON.parse(e);return this.ki(t,i),!0}catch(t){return c("Failed to apply cached user data:",t),!1}}async Li(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 s=await this.Hi(i),n=this.Oi(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:s,os:n}),onload:t=>{200!==t.status&&c("Failed to send heartbeat:",t.statusText)},onerror:t=>{c("Error sending heartbeat:",t)}})}async Hi(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"}Oi(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"}}(Tt),kt=new class extends L{constructor(t,i,s){var n;super(t,i),e(this,T),this.Nt=s,(n=this.Nt).flags??(n.flags=[]),this.Ii=structuredClone(this.Nt),this.Bi="bmUserSettings",this.Pi=5e3,this.Ai=0,setInterval(this.zi.bind(this),this.Pi)}async zi(){await this.Wi()}async Wi(t=!1){const e=JSON.stringify(this.Nt);e!=JSON.stringify(this.Ii)&&(t||Date.now()-this.Ai>this.Pi)&&(await GM.setValue(this.Bi,e),this.Ii=structuredClone(this.Nt),this.Ai=Date.now(),console.log(e))}async Le(){await this.Wi(!0)}Ne(t,e=void 0){const i=this.Nt?.flags?.indexOf(t)??-1;-1!=i&&!0!==e?this.Nt?.flags?.splice(i,1):-1==i&&!1!==e&&this.Nt?.flags?.push(t)}kt(){const t='<svg viewBox="0 0 3 3"><path d="M0,0H3V3H0ZM0,1H3M0,2H3M1,0V3M2,0V3" fill="#fff"/><path d="M1,1H2V2H1Z" fill="#2f4f4f"/></svg>',e='<svg viewBox="0 0 3 3"><path d="M0,0H3V3H0Z" fill="#fff"/><path d="M1,0H2V1H3V2H2V3H1V2H0V1H1Z" fill="brown"/><path d="M1,1H2V2H1Z" fill="#2f4f4f"/></svg>',s=this.Nt?.highlight??[[1,0,1],[2,0,0],[1,-1,0],[1,1,0],[1,0,-1]];this.window=this.L({class:"bm-L"}).W(2,{textContent:"Pixel Highlight"}).D().F().D().L({class:"bm-L",style:"margin-left: 1.5ch;"}).j({textContent:"Highlight transparent pixels"},(t,e,i)=>{i.checked=!this.Nt?.flags?.includes("hl-noTrans"),i.onchange=t=>this.Ne("hl-noTrans",!t.target.checked)}).D().H({id:"bm-4",textContent:"Choose a preset:",style:"font-weight: 700;"}).D().L({class:"bm-D",role:"group","aria-labelledby":"bm-4"}).L({class:"bm-3"}).I({textContent:"None"}).D().lt({innerHTML:t,"aria-label":'Preset "None"'},(t,e)=>{e.onclick=()=>i(this,T,k).call(this,"None")}).D().D().L({class:"bm-3"}).I({textContent:"Cross"}).D().lt({innerHTML:e,"aria-label":'Preset "Cross Shape"'},(t,e)=>{e.onclick=()=>i(this,T,k).call(this,"Cross")}).D().D().L({class:"bm-3"}).I({textContent:"X"}).D().lt({innerHTML:e.replace('d="M1,0H2V1H3V2H2V3H1V2H0V1H1Z"','d="M0,0V1H3V0H2V3H3V2H0V3H1V0Z"'),"aria-label":'Preset "X Shape"'},(t,e)=>{e.onclick=()=>i(this,T,k).call(this,"X")}).D().D().L({class:"bm-3"}).I({textContent:"Full"}).D().lt({innerHTML:t.replace("#fff","#2f4f4f"),"aria-label":'Preset "Full Template"'},(t,e)=>{e.onclick=()=>i(this,T,k).call(this,"Full")}).D().D().D().H({id:"bm-b",textContent:"Create a custom pattern:",style:"font-weight: 700;"}).D().L({class:"bm-n",role:"group","aria-labelledby":"bm-b"});for(let t=-1;t<=1;t++)for(let e=-1;e<=1;e++){const n=s[s.findIndex(([,i,s])=>i==e&&s==t)]?.[0]??0;let o="Disabled";1==n?o="Incorrect":2==n&&(o="Template"),this.window=this.lt({"data-status":o,"aria-label":`Sub-pixel ${o.toLowerCase()}`},(s,n)=>{n.onclick=()=>i(this,T,S).call(this,n,[e,t])}).D()}this.window=this.D().D().D()}Dt(){this.window=this.L({class:"bm-L"}).W(2,{textContent:"Pixel Highlight"}).D().F().D().L({class:"bm-L",style:"margin-left: 1.5ch;"}).j({textContent:"Template creation should skip transparent tiles"},(t,e,i)=>{i.checked=!this.Nt?.flags?.includes("hl-noSkip"),i.onchange=t=>this.Ne("hl-noSkip",!t.target.checked)}).D().j({innerHTML:"Experimental: Template creation should <em>aggressively</em> skip transparent tiles"},(t,e,i)=>{i.checked=this.Nt?.flags?.includes("hl-agSkip"),i.onchange=t=>this.Ne("hl-agSkip",t.target.checked)}).D().D().D()}}(wt,xt,Mt);Ct.k(kt),Ct.S(St),Tt.mi(Ct),Tt.k(kt);var Dt=JSON.parse(GM_getValue("bmTemplates","{}"));if(console.log(Dt),console.log(Mt),console.log(Object.keys(Mt).length),0==Object.keys(Mt).length){const t=crypto.randomUUID();console.log(t),GM.setValue("bmUserSettings",JSON.stringify({uuid:t}))}setInterval(()=>St.Li(xt),18e5);var Nt=Mt?.telemetry;if(console.log(`Telemetry is ${!(null==Nt)}`),null==Nt||Nt>1){const t=new class extends v{constructor(t,i,s,n){super(t,i),e(this,pt),this.window=null,this.Ct="bm-k",this.Tt=document.body,this.Fi=s,this.uuid=n}async St(){if(document.querySelector(`#${this.Ct}`))return void this.$t("Telemetry window already exists!");const t=await this.p.Hi(navigator.userAgent),e=this.p.Oi(navigator.userAgent);this.window=this.L({id:this.Ct,class:"bm-W",style:"height: 80vh; z-index: 9998;"}).L({class:"bm-m"}).L({class:"bm-L bm-h"}).W(1,{textContent:`${this.name} Telemetry`}).D().D().F().D().L({class:"bm-L bm-D",style:"gap: 1.5ch; flex-wrap: wrap;"}).lt({textContent:"Enable Telemetry"},(t,e)=>{e.onclick=()=>{i(this,pt,ft).call(this,this.Fi);const t=document.getElementById(this.Ct);t?.remove()}}).D().lt({textContent:"Disable Telemetry"},(t,e)=>{e.onclick=()=>{i(this,pt,ft).call(this,0);const t=document.getElementById(this.Ct);t?.remove()}}).D().lt({textContent:"More Information"},(t,e)=>{e.onclick=()=>{window.open("https://github.com/SwingTheVine/Wplace-TelemetryServer#telemetry-data","_blank","noopener noreferrer")}}).D().D().L({class:"bm-L bm-H"}).L({class:"bm-L"}).W(2,{textContent:"Legal"}).D().H({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}!`}).D().D().F().D().L({class:"bm-L"}).W(2,{textContent:"Non-Legal Summary"}).D().H({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:'}).D()._().Z({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>${r(this.uuid)}</b>`}).D().Z({innerHTML:`The version of Blue Marble you are using.<br>Your version is: <b>${r(this.version)}</b>`}).D().Z({innerHTML:`Your browser type, which is used to determine Blue Marble outages and browser popularity.<br>Your browser type is: <b>${r(t)}</b>`}).D().Z({innerHTML:`Your OS type, which is used to determine Blue Marble outages and OS popularity.<br>Your OS type is: <b>${r(e)}</b>`}).D().Z({innerHTML:"The date and time that Blue Marble sent the telemetry information."}).D().D().H({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.'}).D().D().D().D().D().N(this.Tt)}}(wt,xt,1,Mt?.uuid);t.S(St),t.St()}!async function(){await Tt.Mi(Dt),St.Si(Ct),Ct.St(),Ct.ai(),St.Ni(Ct),St.Di(Ct),new MutationObserver((t,e)=>{const i=document.querySelector("#color-1");if(!i)return;let s=document.querySelector("#bm-G");if(!s){s=document.createElement("button"),s.id="bm-G",s.textContent="Move ",s.className="btn btn-soft",s.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(s)}}).observe(document.body,{childList:!0,subtree:!0}),l(`%c${wt}%c (${xt}) userscript has loaded!`,"color: cornflowerblue;","")}()})();
// Build Hash: 835bfa613e8c