// ==UserScript== // @name Blue Marble // @namespace https://github.com/SwingTheVine/ // @version 0.87.4 // @description A userscript to automate and/or enhance the user experience on Wplace.live. Make sure to comply with the site's Terms of Service, and rules! This script is not affiliated with Wplace.live in any way, use at your own risk. This script is not affiliated with TamperMonkey. The author of this userscript is not responsible for any damages, issues, loss of data, or punishment that may occur as a result of using this script. This script is provided "as is" under the MPL-2.0 license. The "Blue Marble" icon is licensed under CC0 1.0 Universal (CC0 1.0) Public Domain Dedication. The image is owned by NASA. // @author SwingTheVine // @author TWY // @license MPL-2.0 // @supportURL https://discord.gg/tpeBPy46hf // @homepageURL https://bluemarble.lol/ // @icon https://raw.githubusercontent.com/t-wy/Wplace-BlueMarble-Userscripts/41913f9a7dcb41fa81cedffc59171d18a0c35007/dist/assets/Favicon.png // @updateURL https://raw.githubusercontent.com/t-wy/Wplace-BlueMarble-Userscripts/custom-improve/dist/BlueMarble.user.js // @downloadURL https://raw.githubusercontent.com/t-wy/Wplace-BlueMarble-Userscripts/custom-improve/dist/BlueMarble.user.js // @match https://wplace.live/* // @run-at document-start // @grant GM.addStyle // @grant GM.setValue // @grant GM.getValue // @noframes // ==/UserScript== // Wplace --> https://wplace.live // License --> https://www.mozilla.org/en-US/MPL/2.0/ (()=>{var t,e,n=t=>{throw TypeError(t)},i=(t,e,i)=>e.has(t)?n("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,i),o=(t,e,i)=>(((t,e)=>{e.has(t)||n("Cannot access private method")})(t,e),i);function s(...t){(0,console.log)(...t)}function r(t){let e="";for(let n=0;n{n.toBlob(t=>{t?i(t):o(new Error("toBlob() returned null"))},t,e)})},n}),Array.prototype.extend||(Array.prototype.extend=function(t){t.forEach(t=>this.push(t))}),t=new WeakSet,e=function(t,e={},n={}){const i=document.createElement(t);this.o?(this.u?.appendChild(i),this.h.push(this.u),this.u=i):(this.o=i,this.u=i);for(const[t,n]of Object.entries(e))i[t]=n;for(const[t,e]of Object.entries(n))i[t]=e;return i};var c=[{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]}],l=new Map(c.filter(t=>Array.isArray(t?.rgb)).map(t=>[`${t.rgb[0]},${t.rgb[1]},${t.rgb[2]}`,{id:t.id,premium:!!t.premium,name:t.name}]));try{const t=c.find(t=>"transparent"===(t?.name||"").toLowerCase());t&&Array.isArray(t.rgb)&&l.set("222,250,206",{id:t.id,premium:!!t.premium,name:t.name})}catch(t){}try{l.set("other",{id:"other",premium:!1,name:"Other"})}catch(t){}function d(t){t.width=0,t.height=0,t.constructor===HTMLCanvasElement&&t.remove(),t=null}function m(){return[[document.querySelector("#bm-1c")?.value||"",document.querySelector("#bm-1d")?.value||""],[document.querySelector("#bm-1e")?.value||"",document.querySelector("#bm-1f")?.value||""]]}function u(){const t=m();return[[Number(t[0][0]),Number(t[0][1])],[Number(t[1][0]),Number(t[1][1])]]}function h(){const t=m(),e=u();return!(t.some(t=>t.some(t=>""===t))||e.some(t=>t.some(t=>isNaN(t)||t<0))||e[0][0]>2048||e[0][1]>2048||e[1][0]>1e3||e[1][1]>1e3)}var p={total:([t,e,n])=>n,painted:([t,e,n])=>e,remaining:([t,e,n])=>n-e,"painted%":([t,e,n])=>e/(0===n?1:n),hue:([t,e,n])=>{if("other"===t)return 361;if("#deface"===t)return-1;const[i,o,s]=t.split(",").map(Number),r=Math.max(i,o,s),a=r-Math.min(i,o,s);return 0===a?361+i:r===i?((o-s)/a+6)%6*60:r===o?60*((s-i)/a+2):60*((i-o)/a+4)},luminance:([t,e,n])=>{if("other"===t)return 2;if("#deface"===t)return 0;const[i,o,s]=t.split(",").map(Number);return(.2126*i+.7152*o+.0722*s)/255}};function b(t,e){const n=[t[0][0]%2048*1e3+t[1][0]%1e3,e[0][0]%2048*1e3+e[1][0]%1e3],i=[t[0][1]%2048*1e3+t[1][1]%1e3,e[0][1]%2048*1e3+e[1][1]%1e3],o=Math.min(i[0],i[1]),s=Math.abs(i[0]-i[1])+1,r=Math.abs(n[0]-n[1])+1,a=2*r>2048e3;return[[a?Math.max(n[0],n[1]):Math.min(n[0],n[1]),o],[a?2048e3-r+2:r,s]]}function f(t,e){let n=new OffscreenCanvas(t,e);const i=n.getContext("2d");i.fillRect(t-1,e-1,1,1);const o=0!==i.getImageData(t-1,e-1,1,1).data[3];return d(n),n=null,o}function g(t,e){const n="https://backend.wplace.live/files/s0/tiles/"+t%2048+"/"+e+".png";return new Promise((t,e)=>{const i=new Image;i.crossOrigin="anonymous",i.onload=function(){t(i)},i.onerror=function(t){e(t)},i.src=n})}function w(){const t=Number(localStorage.getItem("selected-color"))??0;return isNaN(t)||!isFinite(t)||t<0||t>=64?0:t}function y([t,e],[n,i],[o,s,r]){2*Math.abs(n-t)>2048e3&&(n>t?t+=2048e3:n+=2048e3);const a=Math.min(t,n),c=Math.min(e,i),l=Math.max(t,n)-a+1,d=Math.max(e,i)-c+1,m=new Uint8ClampedArray(l*d*4),u=new ImageData(m,l,d);for(const[d,u]of function*([t,e],[n,i]){const o=Math.abs(n-t),s=Math.abs(i-e),r=t-s&&(c-=s,t+=r),n=0&&(--a,c-=8*a),{d:c,y:a}}var x=class{constructor({displayName:t="My template",M:e=0,C:n="",url:i="",file:o=null,coords:s=null,$:r=null,k:a=null,tileSize:c=1e3}={}){this.displayName=t,this.M=e,this.C=n,this.url=i,this.file=o,this.coords=s,this.$=r,this.k=a,this.tileSize=c,this.enabled=!0,this.S=0,this.T=0,this.D=0,this.O={},this.L=new Set,this.A=null,this.B=Date.now().toString(),this.shreadSize=null}I(t,e,n){const i=n-1>>1;return(t%n==i||e%n==i)&&t%n>=i-1&&t%n<=i+1&&e%n>=i-1&&e%n<=i+1}N(t){const e=[];for(let n=0;nbutton");if(null===t)return!1;if(void 0!==t.__click)q="object"==typeof t.__click&&void 0!==t.__click[3]&&void 0!==t.__click[3].v&&void 0!==t.__click[3].v.addSource||void 0!==document.head.__bmmap;else{const t=()=>{const t=document.currentScript;if(document.head.__bmmap)t.setAttribute("bm-1j","true");else try{void 0!==document.querySelector(".right-3>button").__click[3].v.addSource?t.setAttribute("bm-1j","true"):t.setAttribute("bm-1j","false")}catch(e){e instanceof TypeError&&t.setAttribute("bm-1j","false")}},e=document.createElement("script");e.textContent=`(${t})();`,document.documentElement?.appendChild(e);const n="true"===e.getAttribute("bm-1j");e.remove(),q=n}return q&&G.forEach(t=>t()),q}function C(t,...e){if(!M())return void Y(()=>C(t,...e));const n=document.querySelector(".right-3>button");if(document.head.__bmmap){const n=document.head.__bmmap;return t(n,...e)}if(null!==n){if(n.__click){const i=n.__click[3].v;return t(i,...e)}{const n=()=>document.head.__bmmap||document.querySelector(".right-3>button").__click[3].v,i=t=>{document.currentScript.setAttribute("bm-1j",JSON.stringify(t??null))},o=e.map(t=>JSON.stringify(t)).join(","),s=document.createElement("script");s.textContent=`(${i})((${t})((${n})(), ${o}));`,document.documentElement?.appendChild(s);const r=JSON.parse(s.getAttribute("bm-1j"));return s.remove(),r}}throw new Error('Could not find the "My location" button.')}var $={};function k(t,e,n,i,o){const s=e.split(",").map(Number),[r,a]=n,c=B([s[0],s[1]],[s[2],s[3]],!1),l=B([s[0],s[1]],[s[2]+r,s[3]+a],!1);$[o]||($[o]={});const d=`BM-${o}-${e}-${t}`;return $[o][d]=[c,l],C(async(t,e,n,i,o,s,r,a,c)=>{document.head.__bmCanvas=c;const l=document.createElement("img");l.src=o,await new Promise(t=>l.addEventListener("load",()=>t(l)));const d=document.getElementById(e);d&&(d.width=0,d.height=0,d.remove());const m=document.createElement("canvas");m.id=e,m.style.display="none",document.body.appendChild(m),m.width=l.naturalWidth,m.height=l.naturalHeight,m.getContext("2d").drawImage(l,0,0),URL.revokeObjectURL(o),t.getLayer(e)&&t.removeLayer(e),t.getSource(e)&&t.removeSource(e),t.addSource(e,{type:"canvas",canvas:e,coordinates:[[s[1],s[0]],[r[1],s[0]],[r[1],r[0]],[s[1],r[0]]]}),t.addLayer({id:e,source:e,type:"raster",paint:{"raster-resampling":"nearest","raster-opacity":1}});const u=t.getLayersOrder(),h="pixel-hover",p=u.find(t=>"overlay"===a&&t.startsWith("bm-1k")||t===h+"-ghost");if(t.moveLayer(e,p),t.getLayer(h+"-ghost")){const e=t.getLayersOrder();e&&e.length&&e[e.length-1]!==h+"-ghost"&&t.moveLayer(h+"-ghost")}else t.addLayer({id:h+"-ghost",type:"raster",source:h,paint:{"raster-resampling":"nearest","raster-opacity":.4}})},d,e,n,URL.createObjectURL(i),c,l,o,$)}function S(t=null,e=null){const n=e?"-"+e:"",i=[];return(t?[t]:["overlay","error"]).forEach(t=>{Object.keys($[t]??{}).forEach(e=>{e.endsWith(n)&&(delete $[t][e],i.push(e))})}),C((t,e,n)=>{document.head.__bmCanvas=n,e.forEach(e=>{t.getLayer(e)&&t.removeLayer(e),t.getSource(e)&&t.removeSource(e);const n=document.getElementById(e);n&&(n.width=0,n.height=0,n.remove())})},i,$)}function T(){try{return C(t=>t.refreshTiles("pixel-art-layer"))}catch(t){}}var D={liberty:["Liberty (Default)",""],bright:["Bright",""],positron:["Positron",""],dark:["Dark","dark"],fiord:["Fiord (Dark)","dark"],halloween:["Fiord (Halloween)","halloween"]};function O(t){if(!D[t])return;const e=D[t][1];return document.documentElement.dataset.theme=e,C((t,e,n)=>{document.head.__bmCanvas=n;const i="pixel-art-layer",o="pixel-hover";let s=t.getSource(o);const r=async()=>{if(t.getSource(i)||t.addSource(i,{type:"raster",tiles:["https://backend.wplace.live/files/s0/tiles/{x}/{y}.png"],minzoom:11,maxzoom:11,tileSize:window.innerWidth>640?550:400}),t.getLayer(i)||t.addLayer({id:i,type:"raster",source:i,paint:{"raster-resampling":"nearest","raster-opacity":1}}),!t.getSource(o))if(s)t.addSource(o,{type:"canvas",canvas:s.canvas,coordinates:s.coordinates});else{const e=document.createElement("canvas"),n=document.createElement("img");n.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAAAAACoWZBhAAAAAXNSR0IArs4c6QAAACpJREFUeNpj+AsEZ86ASIa/DAwMZ84ACRDzDBigMs/AARITq1oUwxBWAADaREUdDMswKwAAAABJRU5ErkJggg==",await new Promise(t=>n.addEventListener("load",()=>t(n))),e.width=n.naturalWidth,e.height=n.naturalHeight,e.getContext("2d").drawImage(n,0,0);const i=1e-5;s={type:"canvas",canvas:e,coordinates:[[0,0],[i,0],[i,-i],[0,-i]]},t.addSource(o,s)}if(t.getLayer(o)){let e="BM";const n=t.getLayersOrder(),i=n.find(t=>t.startsWith(e+"-overlay-")||t.startsWith(e+"-error-")||t===o+"-ghost");n.indexOf(o)+1!==(void 0===i?n.length:n.indexOf(i))&&t.moveLayer(o,i)}else t.addLayer({id:o,type:"raster",source:o,paint:{"raster-resampling":"nearest","raster-opacity":.4}});if(t.getLayer(o+"-ghost")){const e=t.getLayersOrder();e&&e.length&&e[e.length-1]!==o+"-ghost"&&t.moveLayer(o+"-ghost")}else t.addLayer({id:o+"-ghost",type:"raster",source:o,paint:{"raster-resampling":"nearest","raster-opacity":.4}});const e=document.head.__bmCanvas;e&&["overlay","error"].forEach(n=>{if(e[n]){let i="BM";const s=t.getLayersOrder(),r=s.find(t=>"overlay"===n&&t.startsWith(i+"-error-")||t===o+"-ghost");Object.entries(e[n]).forEach(([e,[n,i]])=>{t.getSource(e)||t.addSource(e,{type:"canvas",canvas:e,coordinates:[[n[1],n[0]],[i[1],n[0]],[i[1],i[0]],[n[1],i[0]]]}),t.getLayer(e)?s.indexOf(e)>(void 0===r?s.length:s.indexOf(r))&&t.moveLayer(e,r):(t.addLayer({id:e,type:"raster",source:e,paint:{"raster-resampling":"nearest","raster-opacity":1}}),t.moveLayer(e,r))})}})},a="restoreLayers";if((t._listeners.styledata??[]).find(t=>t.name===a)||(r.name=a,t.on("styledata",r)),!document.querySelector(".flex>.btn.btn-square.relative.shadow-md")){const t=document.querySelector(".gap-1+.btn-circle");t&&t.click()}return t.setStyle("https://maps.wplace.live/styles/"+e,{}),null},"halloween"===t?"fiord":t,$)}var E={data:null};async function L(t,e){if(M()){if(C((t,e,n,i)=>{t[i]({center:[n,e],zoom:16})},t,e,"jumpTo"),document.querySelector(".flex>.btn.btn-square.relative.shadow-md")){const t=document.querySelector("canvas.maplibregl-canvas"),e=new MouseEvent("click",{bubbles:!0,cancelable:!0,clientX:t.offsetWidth/2,clientY:t.offsetHeight/2,button:0});t.dispatchEvent(e)}}else{const n=document.querySelector(".mb-2>.btn-ghost");if(void 0!==n)E.data=I(t,e,!1),n.click();else{const n=`https://wplace.live/?lat=${t}&lng=${e}&zoom=16`;window.location.href=n}}}async function A(t,e){const n=B(t,e);await L(n[0],n[1])}function B(t,e,n=!0){const i=n?.5:0,o=(1e3*t[0]+e[0]+i)/2048e3,s=1-(1e3*t[1]+e[1]+i)/2048e3;return[360*Math.atan(Math.exp((2*s-1)*Math.PI))/Math.PI-90,360*o-180]}function I(t,e,n=!0){const i=(e+180)/360*2048*1e3,o=2048*(1-(Math.log(Math.tan((90+t)*Math.PI/360))/Math.PI+1)/2)*1e3,s=n?[Math.floor(i%1e3),Math.floor(o%1e3)]:[i%1e3,o%1e3];return[[Math.floor(i/1e3),Math.floor(o/1e3)],s]}function N(t){return C((t,e)=>t.setZoom(e),t)}var P,j,R,F,U,H,z,q=!1,G=[];function Y(t){if(q)return t();G.push(t)}P=new WeakSet,j=async function(t){const e=t.templates,n=this.U();if(Object.keys(e).length>0){for(const t in e){const i=t,o=e[t],s=o.coords.split(",").map(Number);if(e.hasOwnProperty(t)){const t=i.split(" "),r=Number(t?.[0]),c=t?.[1]||"0",l=o.name||`Template ${r||""}`,m=o.tiles,u={},h={};let p=0;const b=new Map;for(const t in m)if(m.hasOwnProperty(t)){const o=a(m[t]),s=new Blob([o],{type:"image/png"}),r=await createImageBitmap(s);u[t]=n?null:r,h[t]=o;try{const t=r.width,n=r.height;let o=new OffscreenCanvas(t,n);const s=o.getContext("2d",{willReadFrequently:!0});s.imageSmoothingEnabled=!1,s.clearRect(0,0,t,n),s.drawImage(r,0,0);const a=s.getImageData(0,0,t,n).data;d(o),o=null;for(let o=this.H;othis.G&&(this.G=f.M),f.shreadSize=o.shreadSize??this.q,f.$=u,f.k=h,f.T=p,f.enabled=o.enabled??!0;const g={};for(const[t,e]of b.entries())g[t]={count:e,enabled:!0};f.O=g;try{Object.keys(u).forEach(t=>{f.L?.add(t.split(",").slice(0,2).join(","))})}catch(t){}try{const t=e?.[i]?.palette;if(t)for(const[e,n]of Object.entries(t))f.O[e]?f.O[e].enabled=!!n?.enabled:f.O[e]={count:n?.count||0,enabled:!!n?.enabled}}catch(t){}f.A=i,this.Y.push(f)}}try{window.postMessage({source:"blue-marble",X:"bm-t"},"*")}catch(t){}try{window.postMessage({source:"blue-marble",X:"bm-f"},"*")}catch(t){}this.J()}},R=new WeakSet,F=function(){o(this,R,U).call(this),this.K=setInterval(()=>{o(this,R,U).call(this)},1e3)},U=function(){if(null===this.W)return void o(this,R,H).call(this);const t=this.W.charges,e=Math.floor(this.Z()),n=t.max,i=(new Intl.NumberFormat).format(e),s=(new Intl.NumberFormat).format(n),r=document.getElementById("bm-13"),a=r?.querySelector('[data-role="countdown"]'),c=r?.querySelector('[data-role="charge-count"]');r&&a&&c&&(a.textContent=this._(),c.textContent=`(${i} / ${s})`);const l=document.getElementById("bm-14"),d=l?.querySelector('[data-role="suspend-countdown"]'),m=document.getElementById("bm-o"),u=document.getElementById("bm-N");if(l&&d&&m&&u){const t=this.V();l.style.display=t?"":"none",m.style.display=t?"":"none",t&&(d.textContent=this.tt(),u.textContent=(this.W.suspensionReason??"Unknown").split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" "))}},H=function(){const t=document.querySelector(".flex>.btn.btn-square.relative.shadow-md"),e=document.querySelector(".relative>.dropdown>.dropdown-content>section>button.btn");if(void 0!==t&&void 0!==e){const t=Date.now();(null===this.et||t-this.et>1e4)&&(fetch("https://backend.wplace.live/me",{credentials:"include"}).then(t=>t.json()).then(t=>{t.status&&"2"!=t.status?.toString()[0]||(s("Fetched user data",t),o(this,R,z).call(this,t,Date.now()))}),this.et=t)}},z=function(t,e){if(null===t)return;const n=Math.ceil(Math.pow(Math.floor(t.level)*Math.pow(30,.65),1/.65)-t.pixelsPainted);t.id||t.id,this.it.nt=t.id,this.W=t,this.ot=e,this.it.st(t.extraColorsBitmap??0);const i=document.getElementById("bm-4")?.parentElement;i&&(i.style.display=-1===this.it.extraColorsBitmap?"none":"");const o=document.getElementById("bm-1b");o&&(o.textContent=t.name);const s=document.getElementById("bm-X");s&&(s.textContent=(new Intl.NumberFormat).format(t.droplets));const r=document.getElementById("bm-O"),a=document.getElementById("bm-g");r&&a&&(r.textContent=(new Intl.NumberFormat).format(n),a.textContent=1==n?"":"s");const c=document.getElementById("bm-P");c&&(c.textContent=Math.floor(t.level)+1)};var X=GM_info.script.name.toString(),J=GM_info.script.version.toString();!function(t){const e=document.createElement("script");e.setAttribute("bm-1p",X),e.setAttribute("bm-1l","color: cornflowerblue;"),e.textContent=`(${t})();`,document.documentElement?.appendChild(e),e.remove()}(()=>{const t=document.currentScript,e=t?.getAttribute("bm-1p")||"Blue Marble",n=t?.getAttribute("bm-1l")||"",i=new Map;window.addEventListener("message",t=>{const{source:o,endpoint:s,blobID:r,blobData:a,blink:c}=t.data;if(Date.now(),"blue-marble"==o&&r&&a&&!s){const t=i.get(r);"function"==typeof t?t(a):function(...t){(0,console.warn)(...t)}(`%c${e}%c: Attempted to retrieve a blob (%s) from queue, but the blobID was not a function! Skipping...`,n,"",r),i.delete(r)}});const o=window.fetch;window.fetch=async function(...t){const e=Date.now(),n=await o.apply(this,t),s=n.clone(),r=(t[0]instanceof Request?t[0]?.url:t[0])||"ignore",a=s.headers.get("content-type")||"";if(a.includes("application/json")){if(r.endsWith("/tile/random"))return new Promise(t=>{const n=crypto.randomUUID();i.set(n,e=>{t(new Response(e,{headers:s.headers,status:s.status,statusText:s.statusText}))}),s.json().then(t=>{window.postMessage({source:"blue-marble",endpoint:r,blobID:n,jsonData:t,blink:e},"*")}).catch(t=>{})});if(r.includes("/s0/pixel/")&&r.includes("?x=")&&r.includes("&y=")&&400===s.status)return new Promise((t,i)=>{n.clone().text().then(i=>{if(i.startsWith('{"error":"Invalid x","status":400}')){const o=i.slice(34);try{const n=JSON.parse(o);window.postMessage({source:"blue-marble",endpoint:r,jsonData:n,blink:e},"*"),t(new Response(o,{headers:s.headers,status:200,statusText:"OK"}))}catch(e){t(n)}}else t(n)}).catch(e=>{t(n)})});s.json().then(t=>{window.postMessage({source:"blue-marble",endpoint:r,jsonData:t,blink:e},"*")}).catch(t=>{})}else if(a.includes("image/")&&!r.includes("openfreemap")&&!r.includes("maps")){const t=await s.blob();window.postMessage({source:"blue-marble",endpoint:r,lastModified:s.headers.get("Last-Modified"),blobData:t,blink:e})}return n};const s={values:Map.prototype.values};Map.prototype.values=function(){const t=s.values.call(this);return Array.from(t).forEach(t=>{t&&t.maps instanceof Set&&Array.from(t.maps).forEach(t=>{t&&t.flyTo&&(document.head.__bmmap=t,function(){for(const t in s)Map.prototype[t]=s[t]}())})}),t}}),GM.addStyle("#bm-1i{position:fixed;background-color:#153063cc;color:#fff;padding:10px;border-radius:8px;z-index:9000;transition:all .3s ease,transform 0s;max-width:300px;width:auto;touch-action:pan-x pan-y;will-change:transform;backface-visibility:hidden;-webkit-backface-visibility:hidden;transform-style:preserve-3d;-webkit-transform-style:preserve-3d}#bm-E,#bm-1i hr,#bm-v,#bm-b{transition:opacity .2s ease,height .2s ease}div#bm-1i{font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Monaco,DejaVu Sans,sans-serif;letter-spacing:.05em}#bm-1g{margin-bottom:.5em;background:url('data:image/svg+xml;utf8,') repeat;cursor:grab;width:100%;height:1em}#bm-1g.dragging{cursor:grabbing}#bm-1i:has(#bm-1g.dragging){pointer-events:none;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none}#bm-1g.dragging{pointer-events:auto}#bm-Q{margin-bottom:.5em}#bm-Q[style*=\"text-align: center\"]{display:flex;flex-direction:column;align-items:center;justify-content:center}#bm-1i[style*=\"padding: 5px\"]{width:auto!important;max-width:300px;min-width:200px}#bm-1i img{display:inline-block;height:2.5em;margin-right:1ch;vertical-align:middle;transition:opacity .2s ease}#bm-Q[style*=\"text-align: center\"] img{display:block;margin:0 auto}#bm-1g{transition:margin-bottom .2s ease}#bm-1i h1{display:inline-block;font-size:x-large;font-weight:700;vertical-align:middle}#bm-v input[type=checkbox]{vertical-align:middle;flex:0 0 auto}#bm-v label>input[type=checkbox]{margin-right:.5ch}#bm-v label{margin-right:.5ch}.bm-1q{border:white 1px solid;height:1.5em;width:1.5em;margin-top:2px;text-align:center;line-height:1em;padding:0!important}#bm-Z{vertical-align:middle}#bm-Z svg{width:50%;margin:0 auto;fill:#111}div:has(>#bm-K){display:flex;gap:.5ch}#bm-button-favorite svg,#bm-button-template svg{height:1em;margin:2px auto 0;text-align:center;line-height:1em;vertical-align:bottom}#bm-R input[type=number]{appearance:auto;-moz-appearance:textfield;width:5.5ch;margin-left:1ch;background-color:#0003;padding:0 .5ch;font-size:small}#bm-R input[type=number]::-webkit-outer-spin-button,#bm-R input[type=number]::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}#bm-6{white-space:nowrap;text-align:center}#bm-8{display:flex;flex-direction:row;flex-wrap:wrap;align-content:center;justify-content:center;align-items:center;gap:1ch}div:has(>#bm-r)>button{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}#bm-r,input[type=file][id*=template]{display:none!important;visibility:hidden!important;position:absolute!important;left:-9999px!important;top:-9999px!important;width:0!important;height:0!important;opacity:0!important;z-index:-9999!important;pointer-events:none!important}#bm-Y{font-size:small;background-color:#0003;padding:0 .5ch;height:3.75em;width:100%}#bm-b{display:flex;justify-content:space-between}#bm-1i small{font-size:x-small;color:#d3d3d3}#bm-E,#bm-v,#bm-R,#bm-8,#bm-Y{margin-top:.5em}#bm-13,#bm-14{display:flex;align-items:baseline;gap:.5ch;white-space:nowrap;min-height:1.4em}#bm-13 .bm-F,#bm-14 .bm-B{color:orange;font-weight:700;font-variant-numeric:tabular-nums;font-feature-settings:\"tnum\"}#bm-13 .bm-15,#bm-o .bm-N{color:#d3d3d3;font-size:.8em}#bm-14,#bm-o{color:salmon}#bm-1i button{background-color:#144eb9;border-radius:1em;padding:0 .75ch;font-size:small}#bm-1i span:has(>input[type=file]+button){font-size:small}#bm-1i select{border-width:1px;border-radius:1em;padding:0 .75ch;font-size:small}#bm-1i select option{background-color:#153063cc}#bm-1i button:hover,#bm-1i button:focus-visible{background-color:#1061e5}#bm-1i button:active #bm-1i button:disabled{background-color:#2e97ff}#bm-1i button:disabled{text-decoration:line-through}#bm-1i details>summary{font-size:small}#bm-w label{font-size:small}#bm-s span{word-break:break-word}span.bm-17:hover,a.bm-17:focus{text-decoration:underline}\n");var K=new class{constructor(e,n){i(this,t),this.name=e,this.version=n,this.ct=null,this.dt="bm-Y",this.o=null,this.u=null,this.h=[]}ut(t){this.ct=t}ht(){return this.h.length>0&&(this.u=this.h.pop()),this}bt(t){t?.appendChild(this.o),this.o=null,this.u=null,this.h=[]}ft(n={},i=()=>{}){return i(this,o(this,t,e).call(this,"div",{},n)),this}gt(n={},i=()=>{}){return i(this,o(this,t,e).call(this,"p",{},n)),this}wt(n={},i=()=>{}){return i(this,o(this,t,e).call(this,"span",{},n)),this}yt(n={},i=()=>{}){return i(this,o(this,t,e).call(this,"b",{},n)),this}vt(t){if(!this.o)return this;const e=document.createTextNode(t);return this.u?.appendChild(e),this}xt(n={},i=()=>{}){return i(this,o(this,t,e).call(this,"small",{},n)),this}Mt(n={},i=()=>{}){return i(this,o(this,t,e).call(this,"img",{},n)),this}Ct(n,i={},s=()=>{}){return s(this,o(this,t,e).call(this,"h"+n,{},i)),this}$t(n={},i=()=>{}){return i(this,o(this,t,e).call(this,"hr",{},n)),this}kt(n={},i=()=>{}){return i(this,o(this,t,e).call(this,"br",{},n)),this}St(n={},i=()=>{}){const s=o(this,t,e).call(this,"label",{textContent:n.textContent??""});delete n.textContent;const r=o(this,t,e).call(this,"input",{type:"checkbox"},n);return s.insertBefore(r,s.firstChild),this.ht(),i(this,s,r),this}Tt(n={},i=()=>{}){const s=n.textContent;delete n.textContent;const r=o(this,t,e).call(this,"details",{type:"details"},n),a=o(this,t,e).call(this,"summary",{textContent:s??""});return r.appendChild(a),this.ht(),i(this,a,r),this}Dt(n={},i=()=>{}){return i(this,o(this,t,e).call(this,"button",{},n)),this}Ot(n={},i=()=>{}){const s=n.title??n.textContent??"Help: No info";delete n.textContent,n.title=`Help: ${s}`;const r={textContent:"?",className:"bm-1q",onclick:()=>{this.Et(this.dt,s)}};return i(this,o(this,t,e).call(this,"button",r,n)),this}Lt(n={},i=()=>{}){return i(this,o(this,t,e).call(this,"select",{},n)),this}At(n={},i=()=>{}){return i(this,o(this,t,e).call(this,"input",{},n)),this}Bt(n={},i=()=>{}){const s=n.textContent??"";delete n.textContent;const r=o(this,t,e).call(this,"span"),a=o(this,t,e).call(this,"input",{type:"file",style:"display: none !important; visibility: hidden !important; position: absolute !important; left: -9999px !important; width: 0 !important; height: 0 !important; opacity: 0 !important;"},n);this.ht();const c=o(this,t,e).call(this,"button",{textContent:s});return this.ht(),this.ht(),a.setAttribute("tabindex","-1"),a.setAttribute("aria-hidden","true"),c.addEventListener("click",()=>{a.click()}),a.addEventListener("change",()=>{c.style.maxWidth=`${c.offsetWidth}px`,a.files.length>0?c.textContent=a.files[0].name:c.textContent=s}),i(this,r,a,c),this}It(n={},i=()=>{}){return i(this,o(this,t,e).call(this,"textarea",{},n)),this}Et(t,e,n=!1){const i=document.getElementById(t.replace(/^#/,""));i&&(i instanceof HTMLInputElement?i.value=e:n?i.textContent=e:i.innerHTML=e)}Nt(t,e){let n,i=!1,o=0,s=null,r=0,a=0,c=0,l=0;if(t=document.querySelector("#"==t?.[0]?t:"#"+t),e=document.querySelector("#"==e?.[0]?e:"#"+e),!t||!e)return void this.Pt(`Can not drag! ${t?"":"moveMe"} ${t||e?"":"and "}${e?"":"iMoveThings "}was not found!`);const d=()=>{if(i){const e=Math.abs(r-c),n=Math.abs(a-l);(e>.5||n>.5)&&(r=c,a=l,t.style.transform=`translate(${r}px, ${a}px)`,t.style.left="0px",t.style.top="0px",t.style.right=""),s=requestAnimationFrame(d)}};let m=null;const u=(u,h)=>{i=!0,m=t.getBoundingClientRect(),n=u-m.left,o=h-m.top;const p=window.getComputedStyle(t).transform;if(p&&"none"!==p){const t=new DOMMatrix(p);r=t.m41,a=t.m42}else r=m.left,a=m.top;c=r,l=a,document.body.style.userSelect="none",e.classList.add("dragging"),s&&cancelAnimationFrame(s),d()},h=()=>{i=!1,s&&(cancelAnimationFrame(s),s=null),document.body.style.userSelect="",e.classList.remove("dragging")};e.addEventListener("mousedown",function(t){t.preventDefault(),u(t.clientX,t.clientY)}),e.addEventListener("touchstart",function(t){const e=t?.touches?.[0];e&&(u(e.clientX,e.clientY),t.preventDefault())},{passive:!1}),document.addEventListener("mousemove",function(t){i&&m&&(c=t.clientX-n,l=t.clientY-o)},{passive:!0}),document.addEventListener("touchmove",function(t){if(i&&m){const e=t?.touches?.[0];if(!e)return;c=e.clientX-n,l=e.clientY-o,t.preventDefault()}},{passive:!1}),document.addEventListener("mouseup",h),document.addEventListener("touchend",h),document.addEventListener("touchcancel",h)}jt(t){(0,console.info)(`${this.name}: ${t}`),this.Et(this.dt,"Status: "+t,!0)}Pt(t){(0,console.error)(`${this.name}: ${t}`),this.Et(this.dt,"Error: "+t,!0)}}(X,J),W=new class{constructor(t,e,n){i(this,P),this.name=t,this.version=e,this.o=n,this.Rt="1.0.0",this.nt=null,this.Ft="!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~",this.tileSize=1e3,this.q=f(5e3,5e3)?5:4,this.H=this.q-1>>1,this.Ut=null,this.Ht=null,this.zt="bm-1m",this.qt="div#map canvas.maplibregl-canvas",this.Gt=null,this.Y=[],this.Yt=null,this.Xt=new Map,this.extraColorsBitmap=0,this.Jt=0,this.Kt=0,this.Wt={},this.hideLockedColors=!1,this.G=0}Zt(){if(document.body.contains(this.Ut))return this.Ut;document.getElementById(this.zt)?.remove();const t=document.querySelector(this.qt),e=document.createElement("canvas");return e.id=this.zt,e.className="maplibregl-canvas",e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.height=t?.clientHeight*(window.devicePixelRatio||1)+"px",e.style.width=t?.clientWidth*(window.devicePixelRatio||1)+"px",e.height=t?.clientHeight*(window.devicePixelRatio||1),e.width=t?.clientWidth*(window.devicePixelRatio||1),e.style.zIndex="8999",e.style.pointerEvents="none",t?.parentElement?.appendChild(e),this.Ut=e,window.addEventListener("move",this._t),window.addEventListener("zoom",this.Vt),window.addEventListener("resize",this.Qt),this.Ut}async te(){return{whoami:this.name.replace(" ",""),scriptVersion:this.version,schemaVersion:this.Rt,templates:{}}}async ee(t,e,n,i){this.Yt||(this.Yt=await this.te()),this.o.jt(`Creating template at ${n.join(", ")}...`);const o=function(t,e){if(0===t)return e[0];let n="";const i=e.length;for(;t>0;)n=e[t%i]+n,t=Math.floor(t/i);return n}(this.nt||0,this.Ft),s=new x({displayName:e,M:this.G+1,C:o,file:t,coords:n,tileSize:this.tileSize});this.G++,s.shreadSize=this.q;const{j:r,R:c}=await s.P(i||this.ne()),l=this.ie();for(const t of Object.keys(s.O))void 0!==l[t]&&(s.O[t].enabled=l[t]);this.U()?(s.$={},Object.entries(r).forEach(([t,e])=>{s.$[t]=null,e.close()})):s.$=r,s.k=Object.fromEntries(Object.entries(c).map(([t,e])=>[t,a(e)]));const d=`${s.M} ${s.C}`;s.A=d,this.Yt.templates[d]={name:s.displayName,coords:n.join(", "),enabled:!0,tiles:c,palette:s.O,shreadSize:s.shreadSize},this.Y.push(s),this.oe(s);const m=(new Intl.NumberFormat).format(s.S);this.o.jt(`Template created at ${n.join(", ")}! Total pixels: ${m}`),this.se(),this.J(s.M),await this.re()}se(){try{window.postMessage({source:"blue-marble",X:"bm-t"},"*")}catch(t){}try{window.postMessage({source:"blue-marble",X:"bm-f"},"*")}catch(t){}}ae(){if(this.ce())try{const t=document.querySelector("#bm-y");t&&(t.style.display=""),window.postMessage({source:"blue-marble",X:"bm-u"},"*")}catch(t){}}async re(){await GM.setValue("bmTemplates",JSON.stringify(this.Yt))}async le(t){const e=this.Y.find(e=>e.A===t);if(void 0===e)return;const n=this.Y.indexOf(e);this.Y.splice(n,1);const i=this.Yt?.templates;i&&i?.[t]&&delete i[t],this.oe(e),S(null,e.M),this.o.jt(`Template ${e.displayName} is deleted!`),await this.re(),this.se()}async de(){this.Yt||(this.Yt=await this.te())}async me(t,e){performance.now();const n=e[0].toString().padStart(4,"0")+","+e[1].toString().padStart(4,"0"),i=this.ue(e);if(0===i.length)return;const o=this.U(),s=i.map(t=>{const e=Object.keys(t.$).filter(t=>t.startsWith(n));if(0===e.length)return null;const i=e[0],o=i.split(",");return{Gt:t,he:i,pe:[+o[0],+o[1]],be:[+o[2],+o[3]]}}).filter(Boolean),r=s?.length||0,a=this.Y.filter(t=>t.enabled).length,c=this.fe()&&this.ge(),m=c?new Set(this.we()):null;let u=0,h=0,p=0,b={},f={};const g=await createImageBitmap(t),w=this.fe(),y=this.q,v=this.H,x=this.tileSize;let M=new OffscreenCanvas(x,x);const C=M.getContext("2d");C.imageSmoothingEnabled=!1,C.beginPath(),C.rect(0,0,x,x),C.clip(),C.clearRect(0,0,x,x),C.drawImage(g,0,0,x,x),g.close();const $=C.getImageData(0,0,x,x).data;for(const t of s){const n=t.Gt,i=n.A,s=await n.F(t.he,o),r=s.width,a=s.height;let g=new OffscreenCanvas(r,a);const M=g.getContext("2d",{willReadFrequently:!0});M.imageSmoothingEnabled=!1,M.clearRect(0,0,r,a),M.drawImage(s,0,0);const C=M.getImageData(0,0,r,a).data,S=r/y,T=a/y;let D=null,O=null,E=null,L=null;const A=t.Gt.enabled??!0;w&&A&&(D=new OffscreenCanvas(S,T),O=D.getContext("2d",{willReadFrequently:!0}),O.clearRect(0,0,S,T),E=O.getImageData(0,0,S,T),L=E.data);const B=t.be[0],I=t.be[1];try{for(let t=v,n=I,o=0;t=x||n>=x)continue;const g=4*(t*r+s),y=C[g],v=C[g+1],M=C[g+2],k=C[g+3],T=4*(n*x+a),D=$[T],O=$[T+1],E=$[T+2],B=$[T+3];let I=!1;const N=4*(o*S+d);if(k<64){try{const t=l.has(`${D},${O},${E}`)?`${D},${O},${E}`:"other";B>=64&&"other"!==t&&h++}catch(t){}continue}p++;let P=`${y},${v},${M}`;l.has(P)||(P="other");const j=!c||m.has(P);if(B<64?0!==k&&w&&A&&j&&(L[N]=128,L[N+1]=128,L[N+2]=128,L[N+3]=200):D===y&&O===v&&E===M?(u++,I=!0,void 0===b[P]?b[P]={painted:1,ye:+A,ve:0,xe:[]}:(b[P].painted++,A&&b[P].ye++),void 0===f[i]?f[i]={painted:1}:f[i].painted++,w&&A&&j&&(L[N]=0,L[N+1]=128,L[N+2]=0,L[N+3]=160)):(h++,w&&A&&j&&(L[N]=255,L[N+1]=0,L[N+2]=0,L[N+3]=224)),!I){let t=`${y},${v},${M}`;l.has(t)||(t="other");const i=[e,[a,n]];if(void 0===b[t])b[t]={painted:0,ye:0,ve:1,xe:[]},A&&b[t].xe.push(i);else{const e=this.Wt?.smartPlace?1<<20:1e4;if(b[t].ve++,A)if(b[t].xe.length[t.A,t.enabled]));for(const t of this.Xt.values())Object.entries(t.Gt).forEach(([t,e])=>{T[t]&&(S+=e.painted||0)});const D=this.Y.reduce((t,e)=>t+(e.enabled&&(e.T||e.S)||0),0),O=(new Intl.NumberFormat).format(S),E=(new Intl.NumberFormat).format(D),L=(new Intl.NumberFormat).format(D-S);return this.o.jt(`Displaying ${a} template${1==a?"":"s"}.\nPainted ${O} / ${E} • Wrong ${L}`),d(M),window.buildColorFilterList(),window.buildTemplateFilterList(),t}async J(t=null){performance.now();const e=this.U(),n=(this.Y??[]).filter(e=>e.enabled&&(null===t||e.M==t));for(const t of n){if(!t.enabled)return;const n=this.we(),i=new Set(n),o=n.length!==Object.keys(this.ie()).length,s=0===n.length;if(s){S("overlay",t.M);continue}const r=this.isLegacyDisplay();for(const n of Object.keys(t.$)){n.split(",");const a=t.shreadSize,c=t.shreadSize-1>>1,m=r?3:this.q,u=await t.F(n,e),h=u.width/t.shreadSize,p=u.height/t.shreadSize,b=h*m,f=p*m;let g=new OffscreenCanvas(b,f);const w=g.getContext("2d");w.imageSmoothingEnabled=!1,w.beginPath(),w.rect(0,0,b,f),w.clip(),w.clearRect(0,0,b,f);try{if(o||a!==m){if(!s){const e=u.width,n=u.height,o=new OffscreenCanvas(e,n).getContext("2d",{willReadFrequently:!0});o.imageSmoothingEnabled=!1,o.clearRect(0,0,e,n),o.drawImage(u,0,0);const s=o.getImageData(0,0,e,n).data,d=w.getImageData(0,0,b,f),h=d.data,p=r?[[1,1]]:t.N(m);for(const[t,o]of p)for(let r=c,d=o;rk(t.M,n,[h,p],y,"overlay")),d(g),g=null,e&&u.close()}}}Ce(t){"BlueMarble"==t?.whoami&&(this.Yt=t,o(this,P,j).call(this,t))}ie(){const t={};for(const e of this.Y)for(const[n,i]of Object.entries(e.O))t[n]||(t[n]=i.enabled);return t}we(){const t=this.$e(),e=-1!==this.extraColorsBitmap&&this.ke(),n=this.ie(),i=this.Se(),o=[];if(t){const t=w();Object.entries(n).forEach(([n,s])=>{const r=l.get(n).id;r===t&&(e&&!this.Te(r)||i&&this.De(r)||o.push(n))})}else Object.entries(n).forEach(([t,n])=>{const s=l.get(t).id;n&&(e&&!this.Te(s)||i&&this.De(s)||o.push(t))});return o.sort()}Oe(){this.Ee();const t=new Set;for(let e=0,n=1;e<64;e++,n<<=1)this.Le&n&&t.add(e);return t}ue(t){const e=t[0].toString().padStart(4,"0")+","+t[1].toString().padStart(4,"0");return this.Y.filter(t=>!!t?.$&&(t.L&&t.L.size>0?t.L.has(e):Object.keys(t.$).some(t=>t.startsWith(e)))).sort((t,e)=>t.M-e.M)}Ae(t){const e=this.we(),n=this.ue(t);return this.Be(e,n)}Be(t,e){return t.join(";")+"||"+e.map(t=>t.A+","+t.B+","+ +(t.enabled??!0)).join(";")}Ee(){const t={};(this.Y??[]).forEach(e=>{if(e.enabled&&e?.O)for(const[n,i]of Object.entries(e.O))t[n]=(t[n]??0)+i.count});const e={};for(const t of this.Xt.values())Object.entries(t.palette).forEach(([t,n])=>{void 0===e[t]?(e[t]=Object.fromEntries(Object.entries(n)),e[t].xe=n.xe.slice()):(e[t].painted+=n.painted,e[t].ye+=n.ye,e[t].ve+=n.ve,e[t].xe.extend(n.xe))});var n=0,i=0;return Object.entries(t).forEach(([t,o])=>{if((e[t]?.ye??0)>=o){const e=l.get(t)?.id??0;e<32?n|=1<{if(!t?.$)return;const e=t.$,n={};Object.entries(e).forEach(([t,e])=>{n[t]=null,null!==e&&e.close()}),t.$=n})}ne(){const t=this.Wt?.anchor??"lt";return this.Xe(t)?t.toLowerCase():"lt"}Xe(t){return 2===t.length&&(t=t.toLowerCase(),"lmr".includes(t[0])&&"tmb".includes(t[1]))}async Je(t){return!!this.Xe(t)&&(this.Wt.anchor=t.toLowerCase(),await this.Pe(),!0)}ce(){return this.Wt?.eventEnabled??!1}async Ke(t){this.Wt.eventEnabled=t,await this.Pe()}We(){return this.Wt?.eventClaimedShown??!0}async Ze(t){this.Wt.eventClaimedShown=t,await this.Pe()}_e(){return this.Wt?.eventUnavailableShown??!0}async Ve(t){this.Wt.eventUnavailableShown=t,await this.Pe()}Qe(){return this.Wt?.eventProvider??""}async tn(t){this.Wt.eventProvider=t,await this.Pe()}$e(){return this.Wt?.onlyCurrentColorShown??!1}async en(t){this.Wt.onlyCurrentColorShown=t,await this.Pe()}nn(){return this.Wt?.themeOverridden??!1}async sn(t){this.Wt.themeOverridden=t,await this.Pe()}rn(){const t=(this.Wt?.currentTheme??Object.keys(D)[0]).toLowerCase();return D[t]?t:Object.keys(D)[0]}async an(t){return t=t.toLowerCase(),!!D[t]&&(this.Wt.currentTheme=t,await this.Pe(),!0)}cn(){return this.Wt?.hideStatus??!1}async ln(t){this.Wt.hideStatus=t,await this.Pe()}isLegacyDisplay(){return this.Wt?.dn??!1}async mn(t){this.Wt.dn=t,await this.Pe()}fe(){return this.Wt?.showErrorMap??!1}async un(t){this.Wt.showErrorMap=t,await this.Pe()}ge(){return this.Wt?.showOnlyEnabledColorsErrorMap??!1}async hn(t){this.Wt.showOnlyEnabledColorsErrorMap=t,await this.Pe()}pn(){return this.Wt?.showIntegerZoom??!1}async bn(t){this.Wt.showIntegerZoom=t,await this.Pe()}fn(){return this.Wt?.enableKeybinds??!1}async gn(t){this.Wt.enableKeybinds=t,await this.Pe()}wn(){return this.Wt?.lineTemplateButton??!1}async yn(t){this.Wt.lineTemplateButton=t,await this.Pe()}st(t){this.extraColorsBitmap!==t&&(this.extraColorsBitmap=t,window.buildColorFilterList(),this.J())}Te(t){if(-1===this.extraColorsBitmap)return!0;if(t<32)return!0;const e=1<{this.Xt.delete(t)}),this.Jt=0,this.Kt=0}}(X,J,K),Z=new class{constructor(t){i(this,R),this.it=t,this.vn=!1,this.xn=[],this.Mn=[],this.W=null,this.ot=null,this.K=null,this.Cn={},this.$n=null,this.et=null,this.kn=null,this.Sn=null}Z(){if(null===this.W)return o(this,R,H).call(this),0;const t=this.W.charges,e=(Date.now()-this.ot)/t.cooldownMs,n=t.count+e,i=t.count>t.max?t.count:t.max;return n>i?i:n}Tn(){const t=this.Z(),e=this.W?.charges??{max:0,cooldownMs:3e4};return t>=e.max?0:(e.max-t)*e.cooldownMs}_(){return this.Dn(this.Tn())}On(){const t=new Date(this.W?.timeoutUntil??0).getTime();return Math.max(0,t-Date.now())}V(){return this.On()>0}tt(){return this.Dn(this.On())}Dn(t){if(t<=0)return"00:00";const e=Math.floor(t/1e3),n=Math.floor(e/3600),i=Math.floor(e%3600/60).toString().padStart(2,"0"),o=(e%60).toString().padStart(2,"0");return n>0?`${n}:${i}:${o}`:`${i}:${o}`}En(){return document.querySelector(".flex.gap-2.px-3>button.btn-circle,.flex.gap-1\\.5.px-3>button.btn-circle")}Ln(){const t=this.En();if(t)return t.parentElement.parentElement.lastElementChild}An(){const t=[this.xn[0],this.xn[1]],e=[this.xn[2],this.xn[3]];let n=document.getElementById("bm-H"),i=document.getElementById("bm-I"),o=document.getElementById("bm-i"),s=document.getElementById("bm-j");const r=B(t,e),a=`(Tl X: ${t[0]}, Tl Y: ${t[1]}, Px X: ${e[0]}, Px Y: ${e[1]})`,c=`(${r[0].toFixed(5)}, ${r[1].toFixed(5)})`;if(!n){const t=this.En();if(!t)return;const e=t.parentElement;n=document.createElement("span"),n.id="bm-H",n.style="margin-left: calc(var(--spacing)*3); font-size: small;",e.insertAdjacentElement("afterend",n);const r=function(){const t=this.dataset.text;!function(t){if(navigator.clipboard&&"function"==typeof navigator.clipboard.writeText)navigator.clipboard.writeText(t);else{var e=document.createElement("textArea");e.innerHTML=t,document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e)}}(t),alert("Copied to clipboard: "+t)};o=document.createElement("a"),o.href="#",o.id="bm-i",o.textContent="Copy",o.style="font-size: small; text-decoration: underline;",o.className="text-nowrap",o.addEventListener("click",r),n.insertAdjacentElement("afterend",o),n.insertAdjacentText("afterend"," ");const a=document.createElement("br");o.insertAdjacentElement("afterend",a),i=document.createElement("span"),i.id="bm-I",i.style="margin-left: calc(var(--spacing)*3); font-size: small;",a.insertAdjacentElement("afterend",i),s=document.createElement("a"),s.href="#",s.id="bm-j",s.textContent="Copy",s.style="font-size: small; text-decoration: underline;",s.className="text-nowrap",s.addEventListener("click",r),i.insertAdjacentElement("afterend",s),i.insertAdjacentText("afterend"," ")}n&&(n.textContent=a,i.textContent=c,o.dataset.text=a,s.dataset.text=c),this.Bn(),this.In()}Bn(){if(this.it.wn()){let t=document.getElementById("bm-k");const e=this;if(!t){const n=this.Ln();if(!n)return;t=document.createElement("span"),t.id="bm-k",t.textContent="+ Line",t.className=n.querySelector("button").className,t.classList.add("btn-soft"),n.appendChild(t),t.addEventListener("click",function(){if(!h())return void alert("Some coordinates textboxes are empty or invalid!");if(4!==e.xn.length)return void alert("Coordinates are malformed! Did you try clicking on the canvas first?");const t=u(),n=[e.xn[0],e.xn[1]],i=[e.xn[2],e.xn[3]],[[o,s],[r,a]]=b([n,i],t),l=e.it.q;if(!f(r*l,a*l))return void alert("The line is too large for the browser to handle.");const d=0==(n[0]%2048*1e3+i[0]%1e3==o^n[1]%2048*1e3+i[1]%1e3==s),m=w(),p=c[m],{p:g,offsetX:v,offsetY:x}=d?y([o,s],[o+r-1,s+a-1],p.rgb):y([o,s+a-1],[o+r-1,s],p.rgb),M=Math.floor(o/1e3),C=Math.floor(s/1e3),$=o%1e3,k=s%1e3;e.it.ee(g,`${p?.name??"Unknown Color"} Line`,[M,C,$,k],"lt")})}}}In(){if(this.it.wn()){let t=document.getElementById("bm-9");const e=this;if(!t){const n=this.Ln();if(!n)return;t=document.createElement("span"),t.id="bm-9",t.textContent="+ Circle",t.className=n.querySelector("button").className,t.classList.add("btn-soft"),n.appendChild(t),t.addEventListener("click",function(){if(!h())return void alert("Some coordinates textboxes are empty or invalid!");if(4!==e.xn.length)return void alert("Coordinates are malformed! Did you try clicking on the canvas first?");const t=u(),n=[e.xn[0],e.xn[1]],i=[e.xn[2],e.xn[3]],[[o,s],[r,a]]=b([n,i],t),{d:l,y:d}=v([0,0],[r-1,a-1]),m=2*d+1,p=e.it.q;if(!f(m*p,m*p))return void alert("The line is too large for the browser to handle.");const g=t[0][0]%2048*1e3+t[1][0]%1e3,y=t[0][1]%2048*1e3+t[1][1]%1e3,x=n[0]%2048*1e3+i[0]%1e3,M=n[1]%2048*1e3+i[1]%1e3,C=w(),$=c[C],{p:k,offsetX:S,offsetY:T}=function([t,e],[n,i],[o,s,r]){2*Math.abs(n-t)>2048e3&&(n>t?t+=2048e3:n+=2048e3);let{d:a,y:c}=v([t,e],[n,i]);const l=(t+2048e3-c)%2048e3,d=Math.max(0,e-c),m=l+c,u=n+(m-t),h=m+c-l+1,p=Math.min(e+c,2047999)-d+1,b=new Uint8ClampedArray(h*p*4),f=new ImageData(b,h,p);for(const[t,n]of function*([t,e],[n,i]){let{d:o,y:s}=v([t,e],[n,i]);if(yield[t,e+s],0===s)return;yield[t,e-s],yield[t+s,e],yield[t-s,e];let r=1;for(;r=0&&(--s,o-=8*s),yield[t+r,e+s],yield[t+r,e-s],yield[t-r,e+s],yield[t-r,e-s],r!=s);)yield[t+s,e+r],yield[t+s,e-r],yield[t-s,e+r],yield[t-s,e-r],++r}([m,e],[u,i])){const e=t-l,i=n-d;if(e<0||e>=h)continue;if(i<0||i>=p)continue;const a=4*(i*h+e);b[a+0]=o,b[a+1]=s,b[a+2]=r,b[a+3]=255}return{p:f,offsetX:l,offsetY:d}}([g,y],[x,M],$.rgb),D=Math.floor(S/1e3),O=Math.floor(T/1e3),E=S%1e3,L=T%1e3;e.it.ee(k,`${$?.name??"Unknown Color"} Circle`,[D,O,E,L],"lt")})}}}Nn(){if(4!==this.xn.length)return;const t=[this.xn[0],this.xn[1]],e=[this.xn[2],this.xn[3]],n=document.querySelectorAll("dialog.modal > div");for(const i of n){if(null===i.querySelector("input[readonly]"))continue;let n=document.querySelector("#bm-J"),o=document.querySelector("#bm-p"),s=document.querySelector("#bm-z"),r=document.querySelector("#bm-a");if(!n){const t=document.createElement("div");i.appendChild(t);const e=document.createElement("h3");e.innerText="Download as Template",e.className="mb-1 mt-5 flex items-center gap-1 text-xl font-semibold",t.appendChild(e);const a=document.createElement("div");a.className="bg-base-200 border-base-content/10 rounded-xl border-2 p-3",a.style.fontSize="small",a.innerText=["Instruction to mark the rectangular range for downloading:",'1. Pick the first reference point (e.g. the Top Left Corner) and use the "Pin" icon to record the coordinates.','2. Pick the second reference point, i.e. the opposite corner (e.g. the Bottom Right Corner), and click the "Share" button.'].join("\n"),t.appendChild(a),o=document.createElement("span"),o.id="bm-p",o.style.fontSize="small",t.appendChild(o),t.appendChild(document.createElement("br"));const c=document.createElement("div");c.className="mt-3 flex items-end justify-end gap-2",s=document.createElement("progress"),s.id="bm-z",s.max="100",s.value="0",s.hidden=!0,c.appendChild(s),r=document.createElement("span"),r.id="bm-a",r.hidden=!0,r.textContent="0 / 0",c.appendChild(r),n=document.createElement("button"),n.id="bm-J",n.className="btn btn-primary";const l=document.createElementNS("http://www.w3.org/2000/svg","svg");l.setAttribute("xmlns","http://www.w3.org/2000/svg"),l.setAttribute("viewBox","0 -960 960 960"),l.setAttribute("fill","currentColor"),l.setAttribute("class","size-5");const d=document.createElementNS("http://www.w3.org/2000/svg","path");d.setAttribute("d","M480-320 280-520l56-58 104 104v-326h80v326l104-104 56 58-200 200ZM240-160q-33 0-56.5-23.5T160-240v-120h80v120h480v-120h80v120q0 33-23.5 56.5T720-160H240Z"),l.appendChild(d),n.appendChild(l),n.appendChild(document.createTextNode(" Download"));const m=this;n.addEventListener("click",async function(){this.disabled=!0;const t=[m.xn[0],m.xn[1]],e=[m.xn[2],m.xn[3]];if(!h())return void alert("Some coordinates textboxes are empty or invalid!");const n=u(),[[i,o],[a,c]]=b([t,e],n),l=Math.floor(i/1e3),d=Math.floor(o/1e3),p=i%1e3,f=o%1e3,w=Math.floor((i+a-1)/1e3),y=Math.floor((o+c-1)/1e3),v=w-l+1,x=y-d+1;s.max=v*x,s.value=0,s.hidden=!1,r.textContent=`0 / ${s.max}`,r.hidden=!1;try{const t=new OffscreenCanvas(a,c),e=t.getContext("2d");e.clearRect(0,0,a,c);for(let t=d;t<=y;t++)for(let n=l;n<=w;n++){const a=await g(n%2048,t);e.drawImage(a,1e3*n-i,1e3*t-o),s.value++,r.textContent=`${s.value} / ${s.max}`}const n=await t.convertToBlob({type:"image/png"});var M=document.createElement("a");M.href=URL.createObjectURL(n,{type:"image/png"}),M.setAttribute("download",`template_${l}_${d}_${p}_${f}_${(new Date).toISOString()}.png`),M.click(),URL.revokeObjectURL(M.href)}catch(t){throw alert("Download Failed!"),t}finally{s.hidden=!0,r.hidden=!0,this.disabled=!1}}),c.appendChild(n),t.appendChild(c)}const a=[];if(h()){const i=u(),[[o,s],[r,c]]=b([t,e],i),l=Math.floor(o/1e3),d=Math.floor(s/1e3),m=o%1e3,h=s%1e3,p=(o+r-1)%2048e3,g=s+c-1,w=Math.floor(p/1e3),y=Math.floor(g/1e3),v=p%1e3,x=g%1e3;a.push(`Top Left: (Tl X: ${l}, Tl Y: ${d}, Px X: ${m}, Px Y: ${h})`),a.push(`Bottom Right: (Tl X: ${w}, Tl Y: ${y}, Px X: ${v}, Px Y: ${x})`),a.push(`Image Size: ${r}×${c}`),f(r,c)?n.disabled=!1:(n.disabled=!0,a.push("Too large for the browser to export."))}else a.push("Some coordinates textboxes are empty or invalid."),n.disabled=!0;o.innerText=a.join("\n")}}Pn(t){o(this,R,F).call(this),window.addEventListener("message",async e=>{const n=e.data,i=n.jsonData;if(!n||"blue-marble"!==n.source)return;if(!n.endpoint)return;const s=n.endpoint?.split("?")[0].split("/").filter(t=>t&&isNaN(Number(t))).filter(t=>t&&!t.includes(".")).pop();switch(s){case"me":if(i.status&&"2"!=i.status?.toString()[0])return void(i.fallback||t.Pt("You are not logged in!\nCould not fetch userdata."));o(this,R,z).call(this,i,Date.now());break;case"pixel":const e=n.endpoint.split("?")[0].split("/").filter(t=>t&&!isNaN(Number(t))).map(t=>Number(t));if(void 0!==(n.jsonData??{}).painted){if(!e.length)return;const t=e[0].toString().padStart(4,"0")+","+e[1].toString().padStart(4,"0");this.Cn[t]&&delete this.Cn[t];break}const s=new URLSearchParams(n.endpoint.split("?")[1]),r=[+s.get("x"),+s.get("y")];if(this.xn.length&&(!e.length||!r.length))return void t.Pt("Coordinates are malformed!\nDid you try clicking the canvas first?");e[0]<0&&r[0]<0?(e[0]+=2048,r[0]+=1e3):e[0]>=2048&&(e[0]-=2048),this.xn=[...e,...r],this.An(),this.Nn();break;case"tiles":let a=n.endpoint.split("/");a=[parseInt(a[a.length-2]),parseInt(a[a.length-1].replace(".png",""))];const c=n.blobData,l=a[0].toString().padStart(4,"0")+","+a[1].toString().padStart(4,"0"),d=n.lastModified,m=this.it.Ae(a),u=+this.it.fe(),h=!this.Cn[l]||this.Cn[l].fullKey!==m,p=!this.Cn[l]||this.Cn[l].lastModified!==d,b=!this.Cn[l]||this.Cn[l].errorMap!==u;(h||p||b)&&(this.it.ue(a).length>0&&(h||p||b&&u)&&await this.it.me(c,a),this.Cn[l]={lastModified:d,fullKey:m,errorMap:u});break;case"random":const f=n.blobID,g=E.data,w=null===g?i:{pixel:{x:g[1][0],y:g[1][1]},tile:{x:g[0][0],y:g[0][1]}};E.data=null,window.postMessage({source:"blue-marble",blobID:f,blobData:JSON.stringify(w),blink:n.blink});break;case"claimed":this.$n=i.claimed??[],this.it.ae();break;case"locations":this.$n=i.filter(t=>t?.claimed??!1).map((t,e)=>t.id??e),this.kn=i,this.Sn=n.endpoint,this.it.ae();break;case"robots":this.vn="false"==i.userscript?.toString().toLowerCase()}})}}(W);K.ut(Z),GM.getValue("bmTemplates","{}").then(async t=>{const e=await GM.getValue("bmUserSettings","{}");let n,i;try{n=JSON.parse(e)}catch{n={}}if(0==Object.keys(n).length){const t=crypto.randomUUID();W.je({uuid:t,hideLockedColors:!1,progressBarEnabled:!0,hideCompletedColors:!1,sortBy:"total-desc",anchor:"lt",smartPlace:!1,memorySavingMode:!1,eventEnabled:!1,eventProvider:"",eventClaimedShown:!0,eventUnavailableShown:!0,onlyCurrentColorShown:!1,themeOverridden:!1,currentTheme:"",hideStatus:!1,isLegacyDisplay:!1,showErrorMap:!1,showOnlyEnabledColorsErrorMap:!1,showIntegerZoom:!1,enableKeybinds:!1,lineTemplateButton:!1}),W.Pe()}else W.je(n);try{i=JSON.parse(t)}catch{i={}}W.Ce(i),await async function(){let t=!1,e={};const n=await GM.getValue("bmCoords","{}");try{e=JSON.parse(n)||{}}catch{e={}}K.ft({id:"bm-1i",style:"top: 10px; right: 75px;"}).ft({id:"bm-Q"}).ft({id:"bm-1g"}).ht().Mt({alt:"Blue Marble Icon - Click to minimize/maximize",src:"https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/dist/assets/Favicon.png",style:"cursor: pointer;"},(e,n)=>{n.addEventListener("click",()=>{t=!t;const i=document.querySelector("#bm-1i"),o=document.querySelector("#bm-Q"),s=document.querySelector("#bm-1g"),r=document.querySelector("#bm-R"),a=document.querySelector("#bm-Z"),c=document.querySelector("#bm--"),l=document.querySelector("#bm-_"),d=document.querySelector("#bm-S"),m=document.querySelector("#bm-A"),u=document.querySelectorAll("#bm-R input"),h=document.getElementById(e.dt);t||(i.style.width="auto",i.style.maxWidth="300px",i.style.minWidth="200px",i.style.padding="10px"),["#bm-1i h1","#bm-E","#bm-1i hr","#bm-v > *:not(#bm-R)","#bm-b"].forEach(e=>{document.querySelectorAll(e).forEach(e=>{e.style.display=t?"none":""})}),t?(r&&(r.style.display="none"),a&&(a.style.display="none"),c&&(c.style.display="none"),l&&(l.style.display="none"),d&&(d.style.display="none"),W.ce()&&(m.style.display="none"),W.cn()||(h.style.display="none"),u.forEach(t=>{t.style.display="none"}),i.style.width="60px",i.style.height="76px",i.style.maxWidth="60px",i.style.minWidth="60px",i.style.padding="8px",n.style.marginLeft="3px",o.style.textAlign="center",o.style.margin="0",o.style.marginBottom="0",s&&(s.style.display="",s.style.marginBottom="0.25em")):(r&&(r.style.display="",r.style.flexDirection="",r.style.justifyContent="",r.style.alignItems="",r.style.gap="",r.style.textAlign="",r.style.margin=""),a&&(a.style.display=""),c&&(c.style.display="",c.style.marginTop=""),l&&(l.style.display="",l.style.marginTop=""),d&&(d.style.display="",d.style.marginTop=""),W.ce()?m.style.display="":m.style.display="none",W.cn()?h.style.display="none":h.style.display="",u.forEach(t=>{t.style.display=""}),n.style.marginLeft="",i.style.padding="10px",o.style.textAlign="",o.style.margin="",o.style.marginBottom="",s&&(s.style.marginBottom="0.5em"),i.style.width="",i.style.height=""),n.alt=t?"Blue Marble Icon - Minimized (Click to maximize)":"Blue Marble Icon - Maximized (Click to minimize)"})}).ht().Ct(1,{textContent:X}).xt({textContent:` v${J}`}).ht().ht().ht().$t().ht().ft({id:"bm-E"}).gt({textContent:"Username: "}).yt({id:"bm-1b"}).ht().ht().gt({id:"bm-13"},(t,e)=>{e.setAttribute("aria-live","polite")}).vt("Full Charges in ").wt({className:"bm-F",textContent:"--:--"},(t,e)=>{e.dataset.role="countdown"}).ht().vt(" ").wt({className:"bm-15",textContent:"(0 / 0)"},(t,e)=>{e.dataset.role="charge-count"}).ht().ht().gt({id:"bm-14",style:"display: none;"},(t,e)=>{e.setAttribute("aria-live","polite")}).vt("Suspension Expires in ").wt({className:"bm-B",textContent:"--:--"},(t,e)=>{e.dataset.role="suspend-countdown"}).ht().ht().gt({id:"bm-o",textContent:"Reason: ",style:"display: none;"}).yt({id:"bm-N",textContent:"Unknown"}).ht().ht().gt({textContent:"Droplets: "}).yt({id:"bm-X"}).ht().ht().gt().yt({id:"bm-O",textContent:"--"}).ht().vt(" more pixel").wt({id:"bm-g",textContent:"s"}).ht().vt(" to Lv. ").yt({id:"bm-P",textContent:"--"}).ht().ht().ht().$t().ht().ft({id:"bm-v"}).ft({id:"bm-R"}).Dt({id:"bm-Z",className:"bm-1q",style:"margin-top: 0;",innerHTML:''},(t,e)=>{e.onclick=()=>{const e=t.ct?.xn,n=t=>t??"";void 0!==e?.[0]?(t.Et("bm-1c",n(e?.[0])),t.Et("bm-1d",n(e?.[1])),t.Et("bm-1e",n(e?.[2])),t.Et("bm-1f",n(e?.[3])),Z.Nn(),_()):t.Pt("Coordinates are malformed! Did you try clicking on the canvas first?")}}).ht().At({type:"number",id:"bm-1c",placeholder:"Tl X",min:0,max:2047,step:1,required:!0,value:e.tx??""},(t,e)=>{e.addEventListener("paste",t=>{const e=(t.clipboardData||window.clipboardData).getData("text"),n=[/^\s*([012]?\d{1,3}),\s*([012]?\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\s*$/,/^\s*([012]?\d{1,3})\s+([012]?\d{1,3})\s+(\d{1,3})\s+(\d{1,3})\s*$/,/^\s*\(?Tl X: ([012]?\d{1,3}), Tl Y: ([012]?\d{1,3}), Px X: (\d{1,3}), Px Y: (\d{1,3})\)?\s*$/].map(t=>t.exec(e)).filter(t=>t).pop();if(void 0===n)return;let i=n.slice(1).map(Number),o=(s=document,coords=[],coords.push(s.querySelector("#bm-1c")),coords.push(s.querySelector("#bm-1d")),coords.push(s.querySelector("#bm-1e")),coords.push(s.querySelector("#bm-1f")),coords);var s;for(let t=0;t(Z.Nn(),_());e.addEventListener("input",n),e.addEventListener("change",n)}).ht().At({type:"number",id:"bm-1d",placeholder:"Tl Y",min:0,max:2047,step:1,required:!0,value:e.ty??""},(t,e)=>{const n=()=>(Z.Nn(),_());e.addEventListener("input",n),e.addEventListener("change",n)}).ht().At({type:"number",id:"bm-1e",placeholder:"Px X",min:0,max:2047,step:1,required:!0,value:e.px??""},(t,e)=>{const n=()=>(Z.Nn(),_());e.addEventListener("input",n),e.addEventListener("change",n)}).ht().At({type:"number",id:"bm-1f",placeholder:"Px Y",min:0,max:2047,step:1,required:!0,value:e.py??""},(t,e)=>{const n=()=>(Z.Nn(),_());e.addEventListener("input",n),e.addEventListener("change",n)}).ht().Dt({id:"bm-K",className:"bm-1q",style:"margin-top: 0;",innerHTML:"✈️",title:"Teleport"},(t,e)=>{e.onclick=()=>{V()}}).ht().ht().Tt({id:"bm-w",textContent:"User Settings",style:"max-width: 100%; white-space: nowrap; border: 1px solid rgba(255,255,255,0.1); padding: 4px; border-radius: 4px; margin-top: 4px;"}).ft({id:"bm-C",style:"max-height: 125px; overflow-x: hidden; overflow-y: auto; touch-action: pan-x pan-y; display: flex; flex-direction: column; gap: 4px; margin-top: 3px;"}).St({id:"bm-1",textContent:"Show Current Color Only",checked:W.$e()},(t,e,n)=>{n.addEventListener("change",()=>{W.en(n.checked),n.checked?(t.jt("Only the currently selected color will be shown."),buildColorFilterList()):(t.jt("Color filter is restored."),buildColorFilterList()),W.J(),W.fe()&&W.ge()&&T(),buildColorFilterList()})}).ht().St({id:"bm-4",textContent:"Hide Locked Colors",checked:W.ke()},(t,e,n)=>{n.addEventListener("change",()=>{W.Re(n.checked),buildColorFilterList(),W.J(),n.checked?t.jt("Hidden all locked colors."):t.jt("Restored all colors.")})}).ht().St({id:"bm-2",textContent:"Hide Completed Colors",checked:W.Se()},(t,e,n)=>{n.addEventListener("change",()=>{W.Ge(n.checked),buildColorFilterList(),W.J(),n.checked?t.jt("Hidden all completed colors."):t.jt("Restored all colors."),W.fe()&&W.ge()&&T()})}).ht().St({id:"bm-T",textContent:"Show Error Map",checked:W.fe()},(t,e,n)=>{n.addEventListener("change",()=>{W.un(n.checked),document.getElementById("bm-0").parentElement.style.display=n.checked?"":"none",n.checked?(t.jt("Error Map is now Displayed."),Z.Cn={},T()):(t.jt("Error Map is now Hidden."),S("error"))})}).ht().St({id:"bm-0",textContent:"Only Enabled Colors on Error Map",checked:W.ge()},(t,e,n)=>{e.style.paddingLeft="1em",W.fe()?e.style.display="":e.style.display="none",n.addEventListener("change",()=>{W.hn(n.checked),n.checked?t.jt("Error Map now only shows enabled colors."):t.jt("Error Map now shows every pixel involved in the template."),Z.Cn={},T()})}).ht().St({id:"bm-c",textContent:"Theme Override: ",checked:W.nn()},(t,e,n)=>{n.addEventListener("change",async()=>{await W.sn(n.checked),document.getElementById("bm-10").disabled=!n.checked,forceUpdateTheme()})}).Lt({id:"bm-10"},(t,e)=>{const n=W.rn();Object.entries(D).forEach(([t,[i,o]])=>{const s=document.createElement("option");s.value=t,s.textContent=i,t===n&&(s.selected=!0),e.appendChild(s)}),e.addEventListener("change",async()=>{await W.an(e.value),t.jt(`Changed the theme to "${D[e.value][0]}".`),forceUpdateTheme()})}).ht().ht().St({id:"bm-11",textContent:"Enable Event",checked:W.ce()},(t,e,n)=>{n.addEventListener("change",()=>{W.Ke(n.checked),n.checked?(t.jt("Event Mode Enabled."),document.getElementById("bm-A").style.display="",document.getElementById("bm-x").parentElement.style.display="",document.getElementById("bm-d").parentElement.style.display="",Z.jn(),buildEventList()):(t.jt("Event Mode Disabled."),document.getElementById("bm-A").style.display="none",document.getElementById("bm-x").parentElement.style.display="none",document.getElementById("bm-d").parentElement.style.display="none")})}).ht().St({id:"bm-x",textContent:"Hide Claimed Event Items",checked:!W.We()},(t,e,n)=>{e.style.paddingLeft="1em",W.ce()?e.style.display="":e.style.display="none",n.addEventListener("change",()=>{W.Ze(!n.checked),n.checked?t.jt("Hidden All Event Claimed Items."):t.jt("Restored All Event Claimed Items."),buildEventList()})}).ht().St({id:"bm-d",textContent:"Hide Unavailable Event Items",checked:!W._e()},(t,e,n)=>{e.style.paddingLeft="1em",W.ce()?e.style.display="":e.style.display="none",n.addEventListener("change",()=>{W.Ve(!n.checked),n.checked?t.jt("Hidden All Unavailable Event Items."):t.jt("Restored All Unavailable Event Items."),buildEventList()})}).ht().St({id:"bm-16",textContent:"Use Dot Template (Original ver.)",checked:W.isLegacyDisplay()},(t,e,n)=>{n.addEventListener("change",()=>{W.mn(n.checked),n.checked?t.jt("Switched to the Dot Template Display."):t.jt("Switched to the Cross Template Display."),W.J()})}).ht().St({id:"bm-D",textContent:"Show Integer Zoom Buttons",checked:W.pn()},(t,e,n)=>{n.addEventListener("change",()=>{W.bn(n.checked);const e=Array.from(document.getElementsByClassName("bm-1h"));n.checked?(t.jt("Integer Zoom Buttons are now Displayed."),e.forEach(t=>t.style.display="")):(t.jt("Integer Zoom Buttons are now Hidden."),e.forEach(t=>t.style.display="none"))})}).ht().St({id:"bm-L",textContent:"Enable WASD Keybinds",checked:W.fn()},(t,e,n)=>{n.addEventListener("change",()=>{W.gn(n.checked),n.checked?t.jt("WASD Keybinds are now Enabled."):t.jt("WASD Keybinds are now Disabled.")})}).ht().St({id:"bm-l",textContent:"Shape Templates (Experimental)",checked:W.wn()},(t,e,n)=>{n.addEventListener("change",()=>{if(W.yn(n.checked),n.checked)Z.Bn(),Z.In(),t.jt("The Line and Circle Template Buttons are now Shown in Pixel Info.");else{const e=document.getElementById("bm-k");e&&e.remove();const n=document.getElementById("bm-9");n&&n.remove(),t.jt("The Line and Circle Template Buttons are now Hidden from Pixel Info.")}})}).ht().St({id:"bm-m",textContent:"Show Progress Bar",checked:W.ze()},(t,e,n)=>{n.addEventListener("change",()=>{W.qe(n.checked),buildColorFilterList(),n.checked?t.jt("Progress Bar Enabled."):t.jt("Progress Bar Disabled.")})}).ht().St({id:"bm-12",textContent:"Hide Status Display",checked:W.cn()},(t,e,n)=>{n.addEventListener("change",()=>{W.ln(n.checked),n.checked?(t.jt("Status Display Hidden."),document.getElementById(K.dt).style.display="none"):(t.jt("Status Display Restored."),document.getElementById(K.dt).style.display="")})}).ht().St({id:"bm-h",textContent:"Memory-Saving Mode (Experimental)",checked:W.U()},(t,e,n)=>{n.addEventListener("change",()=>{W.Ye(n.checked),buildColorFilterList(),n.checked?t.jt("Memory Saving Mode Enabled. The Effect will be Fully Active After a Page Refresh."):t.jt("Memory Saving Mode Disabled. The Effect will be Fully Active After a Page Refresh.")})}).ht().ht().ht().Tt({id:"bm-q",textContent:"Colors",style:"border: 1px solid rgba(255,255,255,0.1); padding: 4px; border-radius: 4px; margin-top: 4px;"},(t,e,n)=>{n.open=!0}).gt({textContent:"Sort Colors by ",style:"font-size: small; margin-top: 3px; margin-left: 5px;"}).Lt({id:"bm-1a"},(t,e)=>{const n=["Asc","Desc"],i=W.Fe();Object.keys(p).forEach(t=>{n.forEach(n=>{const o=document.createElement("option");o.value=`${t.toLowerCase()}-${n.toLowerCase()}`,o.textContent=`${t[0].toUpperCase()+t.slice(1).toLowerCase()} (${n}.)`,o.value===i&&(o.selected=!0),e.appendChild(o)})}),e.addEventListener("change",()=>{W.He(e.value),buildColorFilterList();const n=e.value.split("-");t.jt(`Changed the sort criteria to "${n[0][0].toUpperCase()+n[0].slice(1).toLowerCase()}" in ${n[1]}ending order.`)})}).ht().ht().ft({id:"bm-8",style:"display: flex; gap: 6px; margin-top: 3px; margin-bottom: 3px;"}).Dt({id:"bm-5",textContent:"Enable All"},(t,e)=>{e.onclick=()=>{W.Y.forEach(t=>{t?.O&&Object.values(t.O).forEach(t=>t.enabled=!0)}),syncToggleList(),W.J(),buildColorFilterList(),t.jt("Enabled all colors"),W.fe()&&W.ge()&&T()}}).ht().Dt({id:"bm-3",textContent:"Disable All"},(t,e)=>{e.onclick=()=>{W.Y.forEach(t=>{t?.O&&Object.values(t.O).forEach(t=>t.enabled=!1)}),syncToggleList(),S("overlay"),buildColorFilterList(),t.jt("Disabled all colors"),W.fe()&&W.ge()&&T()}}).ht().ht().ft({id:"bm-G",style:"max-height: 125px; overflow: auto; touch-action: pan-x pan-y; display: flex; flex-direction: column; gap: 4px;"}).ht().ht().Tt({id:"bm-e",textContent:"Templates",style:"border: 1px solid rgba(255,255,255,0.1); padding: 4px; border-radius: 4px; margin-top: 4px;"},(t,e,n)=>{n.open=!0}).ft({id:"bm-6",style:"margin-bottom: 3px;"}).Bt({id:"bm-r",textContent:"Select Image",accept:"image/png, image/jpeg, image/webp, image/bmp, image/gif"}).Dt({id:"bm--",textContent:"Create Template",style:"margin: 0 1ch;"},(t,e)=>{e.onclick=async()=>{const e=document.querySelector("#bm-r"),n=document.querySelector("#bm-1c");if(!n.checkValidity())return n.reportValidity(),void t.Pt("Coordinates are malformed! Did you try clicking on the canvas first?");const i=document.querySelector("#bm-1d");if(!i.checkValidity())return i.reportValidity(),void t.Pt("Coordinates are malformed! Did you try clicking on the canvas first?");const o=document.querySelector("#bm-1e");if(!o.checkValidity())return o.reportValidity(),void t.Pt("Coordinates are malformed! Did you try clicking on the canvas first?");const s=document.querySelector("#bm-1f");if(!s.checkValidity())return s.reportValidity(),void t.Pt("Coordinates are malformed! Did you try clicking on the canvas first?");e?.files[0]?(await W.ee(e.files[0],e.files[0]?.name.replace(/\.[^/.]+$/,""),[Number(n.value),Number(i.value),Number(o.value),Number(s.value)],W.ne()),t.jt("Drew to canvas!")):t.Pt("No file selected!")}}).ht().Lt({id:"bm-M"},(t,e)=>{const n={l:"Left",m:"Center",r:"Right"},i={t:"Top",m:"Middle",b:"Bottom"},o=W.ne();Object.entries({lt:"⟔",mt:"⨪",rt:"ᒬ",lm:"꜏",mm:"⊡",rm:"꜊",lb:"Ŀ",mb:"∸",rb:"⟓"}).forEach(([t,n])=>{const i=document.createElement("option");i.value=t,i.textContent=n,t===o&&(i.selected=!0),e.appendChild(i)}),e.addEventListener("change",()=>{W.Je(e.value),t.jt(`Changed the default template anchor to "${i[e.value[1]]} ${n[e.value[0]]}".`)})}).ht().ht().ft({id:"bm-s",style:"max-height: 125px; overflow: auto; touch-action: pan-x pan-y; display: flex; flex-direction: column; gap: 4px;"}).ht().ht().Tt({id:"bm-A",textContent:"Event",style:"border: 1px solid rgba(255,255,255,0.1); padding: 4px; border-radius: 4px; display: none; margin-top: 4px;"},(t,e,n)=>{W.ce()&&(n.style.display=""),n.open=!0}).Dt({id:"bm-7",textContent:"Set Data Provider",style:"margin: 0 1ch;"},(t,e)=>{e.onclick=()=>{const t=W.Qe(),e=prompt("Enter the event data provider JSON URL:",""===t?"https://wplace.samuelscheit.com/tiles/pumpkin.json":t);e&&((t=>{try{return Boolean(new URL(t))}catch(t){return!1}})(e)?(W.tn(e),buildEventList()):alert("The URL you entered is not valid!"))}}).ht().Dt({id:"bm-n",textContent:"Refresh Data",style:"margin: 0 1ch;"},(t,e)=>{e.onclick=()=>buildEventList()}).ht().ft({id:"bm-U",style:"max-height: 125px; overflow: auto; touch-action: pan-x pan-y; display: flex; flex-direction: column; gap: 4px;"}).ht().ht().It({id:K.dt,placeholder:`Status: Sleeping...\nVersion: ${J}`,readOnly:!0},(t,e)=>{W.cn()&&(e.style.display="none")}).ht().ft({id:"bm-b"}).ft().Dt({id:"bm-V",className:"bm-1q",innerHTML:"🎨",title:"Template Color Converter"},(t,e)=>{e.addEventListener("click",()=>{window.open("https://pepoafonso.github.io/color_converter_wplace/","_blank","noopener noreferrer")})}).ht().Dt({id:"bm-W",className:"bm-1q",innerHTML:"🌐",title:"Official Blue Marble Website"},(t,e)=>{e.addEventListener("click",()=>{window.open("https://bluemarble.lol/","_blank","noopener noreferrer")})}).ht().ht().ft({id:"bm-1n"}).xt({textContent:"by SwingTheVine | Forked by TWY",style:"margin-top: auto;"}).ht().ht().ht().ht().bt(document.body),window.syncToggleList=function(){try{(W.Y??[]).forEach(t=>{const e=t.A;if(e&&W.Yt?.templates?.[e]){const n=W.Yt.templates[e];n.enabled=t.enabled,n.palette=t.O}}),W.re()}catch(t){}},window.buildColorFilterList=function(){const t=document.querySelector("#bm-G"),e=W.ie(),n=W.Se(),i=W.ke();t.innerHTML="";const{Ie:o,Ne:s}=W.Ee();if(!t||!Object.keys(o).length)return void(t&&(t.innerHTML="No template colors to display."));const r=W.Fe().split("-"),a=p[r[0]],c="asc"===r[1]?(t,e)=>a(t)-a(e):(t,e)=>a(e)-a(t),d=Object.entries(o).map(([t,e])=>[t,s[t]?.ye??0,e]).sort(c);let m=!1;for(const[o,a,c]of d){if(i&&"other"===o)continue;if(n&&a===c)continue;let d=document.createElement("div");d.style.display="flex",d.style.alignItems="center",d.style.gap="6px";let u=document.createElement("div");u.style.width="14px",u.style.height="14px",u.style.border="1px solid rgba(255,255,255,0.5)";let h="",p="";const b=l.get(o);if("other"===o)u.style.background="#888",h="Other",p="other";else if("#deface"===o)u.style.background="#deface",h="Transparent",p="transparent";else{const[t,e,n]=o.split(",").map(Number);u.style.background=`rgb(${t},${e},${n})`;try{if(b&&"number"==typeof b.id){if(i&&!W.Te(b.id))continue;const o=b?.name||`rgb(${t},${e},${n})`;b.premium&&(u.style.borderColor="gold",u.style.boxShadow="0 0 2px yellow"),h=`#${b.id} ${o}`,p=`${t},${e},${n}`}}catch(t){}}let f=document.createElement("span");if(f.style.fontSize="12px","remaining"===r[0]||n&&"painted"!==r[0]){const t=(c-a).toLocaleString();f.textContent=`${h} • ${t} Left`}else{const t=c.toLocaleString(),e=a.toLocaleString();f.textContent=`${h} • ${e} / ${t}`}if(W.ze()){const t=a/(0===c?1:c)*100;d.style.background=`linear-gradient(to right, rgb(0, 128, 0, 0.8) 0%, rgb(0, 128, 0, 0.8) ${t}%, transparent ${t}%, transparent 100%)`}const g=s[p];let y=0;u.addEventListener("click",()=>{if((g?.xe?.length??0)>0){const t=g.xe,e=y%t.length;A(t[e][0],t[e][1]),++y}}),(g?.xe?.length??0)>0&&(u.style.cursor="pointer");const v=document.createElement("input");v.type="checkbox",W.$e()?(v.checked=b?.id===w(),v.disabled=!0):v.checked=e[o]??!0,v.addEventListener("change",()=>{(W.Y??[]).forEach(t=>{t?.O&&void 0!==t.O[o]&&(t.O[o].enabled=v.checked)}),K.jt(`${v.checked?"Enabled":"Disabled"} ${o}`),syncToggleList(),W.J(),W.fe()&&W.ge()&&T()}),d.appendChild(v),d.appendChild(u),d.appendChild(f),t.appendChild(d),m=!0}!m&&t&&(t.innerHTML=i?n?"All owned colors have been completed.":"Remaining colors are all locked.":"All colors have been completed.")},window.buildTemplateFilterList=function t(){const e=document.querySelector("#bm-s");if(s(W),0===W.Y?.length)return void(e&&(e.innerHTML="No templates to display."));e.innerHTML="";const n=W.Y,i={};for(const t of W.Xt.values())Object.entries(t.Gt).forEach(([t,e])=>{void 0===i[t]?i[t]=Object.fromEntries(Object.entries(e)):i[t].painted+=e.painted});for(const o of n){let n=document.createElement("div");n.style.display="flex",n.style.alignItems="center",n.style.gap="6px";let s=document.createElement("a");s.title="Remove template",s.textContent="🗑️",s.style.fontSize="12px",s.onclick=()=>{confirm(`Remove template ${o?.displayName}?`)&&W.le(o?.A)};let r=document.createElement("a");r.title="Teleport to template",r.textContent="✈️",r.style.fontSize="12px",r.onclick=()=>{A(o.coords.slice(0,2),o.coords.slice(2,4))};let a=document.createElement("span");a.style.fontSize="12px";const c=`${o.T.toLocaleString()}`,l=o.displayName,d=`${(i[o.A]?.painted??0).toLocaleString()}`,m=document.createElement("span");m.textContent=l,m.addEventListener("click",()=>{const e=o.displayName,n=prompt("Rename template",e);if(n){if(n.trim()===e)return;o.displayName=n.trim();try{const t=W.Yt?.templates?.[o.A];t&&(t.name=n.trim(),W.re())}catch(t){}t()}}),m.className="bm-17",a.appendChild(m),a.appendChild(document.createTextNode(` • ${d} / ${c}`));const u=document.createElement("input");u.type="checkbox",u.checked=o.enabled,u.addEventListener("change",()=>{o.enabled=u.checked,K.jt(`${u.checked?"Enabled":"Disabled"} ${l}`),u.checked?W.J(o.M):(W.oe(o),S(null,o.M)),syncToggleList(),buildColorFilterList(),T()}),n.appendChild(u),n.appendChild(s),n.appendChild(r),n.appendChild(a),e.appendChild(n)}},window.buildEventList=function(){const t=document.querySelector("#bm-U"),e=W.We(),n=W._e(),i=Z.Sn??W.Qe();if(null===Z.$n)return void(t.innerHTML="The event claimed items list is not loaded. Make sure you have clicked the ongoing Event button from the top left corner.");if(null===Z.kn&&(null===i||""==i))return void(t.innerHTML="Event data provider is not set.");const o=new Set(Z.$n);s("eventClaimedList",o),(null===Z.kn?fetch(i,{credentials:"include"}).then(t=>t.json()):new Promise(t=>{const e=Z.kn;Z.kn=null,t(e)})).then(i=>{if(s("event Location data",i),"object"!=typeof i)return void(t.innerHTML="The event data provider does not provide a known format.");t.textContent="";let r=!1;(Array.isArray(i)?i.map((t,e)=>[t.id??e,t]):Object.entries(i)).forEach(([i,s])=>{if(i=Number(i),o.has(i)&&!e)return;const a=document.createElement("div");a.style.display="flex",a.style.alignItems="center",a.style.gap="6px";let c=null,l="";if("object"==typeof s&&(void 0!==s.lat&&void 0!==s.lng?c=[s.lat,s.lng]:void 0!==s.latitude&&void 0!==s.longitude?c=[s.latitude,s.longitude]:void 0!==s.tileX&&void 0!==s.offsetX&&void 0!==s.tileY&&void 0!==s.offsetY&&(c=B([s.tileX,s.tileY],[s.offsetX,s.offsetY])),void 0!==s.foundAt)){const t=Date.now(),e=t-t%36e5,i=new Date(s.foundAt).getTime();if(e!==i-i%36e5&&(l="Expired • ",!n))return}if(null!==c){let t=document.createElement("a");t.title="Teleport to event item",t.textContent="✈️",t.style.fontSize="12px",t.onclick=()=>{L(c[0],c[1]);const t=Array.from(document.querySelectorAll(".cursor-pointer.z-10")).filter(t=>{if(1!=t.style.opacity)return!1;const e=t.getBoundingClientRect(),n=window.innerWidth||document.documentElement.clientWidth,i=window.innerHeight||document.documentElement.clientHeight;return e.top>=0&&e.bottom<=n&&e.left>=0&&e.right<=i});1===t.length&&t[0].click()},a.appendChild(t)}else l="Unknown Coordinate Format • ";let d=document.createElement("span");d.style.fontSize="12px",d.textContent=`#${i} • ${l}${o.has(i)?"Claimed":"Unclaimed"}`,a.appendChild(d),t.appendChild(a),r=!0}),!r&&t&&(t.innerHTML=`No ${e?"":"unclaimed "}items have ${n?"":"recent "}data available.`)}).catch(e=>{t.innerHTML="Failed fetching the event item info from the event data provider. Make sure the provider URL is a valid JSON resource and can be accessed with appropriate CORS."})},window.forceUpdateTheme=function(){W.nn()?O(W.rn()):O(Object.keys(D)[0])},window.forceClickCenter=function t(){if(!M()){if(t.clickCount||(t.clickCount=0),t.clickCount<10&&document.querySelector(".flex>.btn.btn-square.relative.shadow-md")){const e=document.querySelector("canvas.maplibregl-canvas");if(e){const n=new MouseEvent("click",{bubbles:!0,cancelable:!0,clientX:e.offsetWidth/2,clientY:e.offsetHeight/2,button:0});e.dispatchEvent(n),++t.clickCount}}setTimeout(t,100)}},window.addEventListener("message",t=>{if("bm-t"===t?.data?.X)try{buildColorFilterList()}catch(t){}else if("bm-f"===t?.data?.X)try{buildTemplateFilterList()}catch(t){}else if("bm-u"===t?.data?.X)try{buildEventList()}catch(t){}}),setTimeout(()=>{try{W.Y?.length>0&&buildColorFilterList(),W.Y?.length>0&&buildTemplateFilterList()}catch(t){}try{W.ce()&&buildEventList()}catch(t){}try{W.nn()&&Y(forceUpdateTheme)}catch(t){}try{forceClickCenter()}catch(t){}},0)}(),K.Nt("#bm-1i","#bm-1g");const o=new Set;let r=null;function a(){if(W.fn()||o.clear(),0===o.size)return void(r=null);let t=0,e=0;if((o.has("w")||o.has("arrowup"))&&(e-=1),(o.has("s")||o.has("arrowdown"))&&(e+=1),(o.has("a")||o.has("arrowleft"))&&(t-=1),(o.has("d")||o.has("arrowright"))&&(t+=1),0!==t||0!==e){if(0!==t&&0!==e){const n=Math.sqrt(t*t+e*e);t/=n,e/=n}C((t,e)=>{t.panBy(e,{duration:0})},[25*t,25*e])}r=requestAnimationFrame(a)}document.addEventListener("keydown",t=>{if(!W.fn())return;if("INPUT"===document.activeElement.tagName||"TEXTAREA"===document.activeElement.tagName)return;const e=t.key.toLowerCase();["w","a","s","d"].includes(e)&&!o.has(e)&&(o.add(e),r||(r=requestAnimationFrame(a)))}),document.addEventListener("keyup",t=>{const e=t.key.toLowerCase();o.delete(e)}),Z.Pn(K),new MutationObserver((t,e)=>{!function(){if(document.getElementById("BM-zoom-1x"))return;const t=Array.from(document.querySelectorAll(".gap-1>.btn[title]")).slice(-1)[0];if(!t)return;const e=t.parentNode;if(!e)return;const n=W.pn();[0,1,2,3,4,5,10,25].forEach(i=>function(i){const o=document.createElement("button"),s=0===i?"Min":i+"x";o.id=`BM-zoom-${s}`,o.textContent=s,o.className=t.className,o.classList.add("bm-1h"),n||(o.style.display="none"),o.onclick=function(){var t=i;if(0!==i){var e;N(Math.log2(4e3*t/window.devicePixelRatio))}else{var n=null===(e=C(t=>{var e=t.getSource("pixel-art-layer");if(e)return e.tileSize}))?window.innerWidth>640?550:400:e;N(Math.log2(8*n*n)/2+1e-7)}},e.appendChild(o)}(i))}();const n=document.querySelector("#color-1");if(!n)return;let i=document.querySelector("#bm-19");if(!i){i=document.createElement("button"),i.id="bm-19",i.textContent="Move ↑",i.className="btn btn-soft",i.onclick=function(){const t=this.parentNode.parentNode.parentNode.parentNode,e="Move ↑"==this.textContent;t.parentNode.className=t.parentNode.className.replace(e?"bottom":"top",e?"top":"bottom"),t.style.borderTopLeftRadius=e?"0px":"var(--radius-box)",t.style.borderTopRightRadius=e?"0px":"var(--radius-box)",t.style.borderBottomLeftRadius=e?"var(--radius-box)":"0px",t.style.borderBottomRightRadius=e?"var(--radius-box)":"0px",this.textContent=e?"Move ↓":"Move ↑"};const t=n.parentNode.parentNode.parentNode.parentNode.querySelector("h2");t.parentNode?.appendChild(i)}if(W.Wt?.smartPlace){let t=document.querySelector("#bm-18");if(!t){t=document.createElement("button"),t.id="bm-18",t.textContent="Paint",t.className="btn btn-soft",t.onclick=function(){const t=Math.floor(Z.Z());if(0===t)return;let e=[];const n=new Set(W.we());for(const t of W.Xt.values())Object.entries(t.palette).forEach(([t,i])=>{if(!n.has(t))return;const o=l.get(t).id;W.Te(o)&&e.extend(i.xe.map(t=>[o,t]))});let i;if(0===e.length)return;try{const t=C(t=>{const e=t.transform.center;return[e.lat,e.lng]}),e=I(t[0],t[1]);i=[e[0][0]*W.tileSize+e[1][0],e[0][1]*W.tileSize+e[1][1]]}catch{const t=e[Math.floor(Math.random()*e.length)][1];i=[t[0][0]*W.tileSize+t[1][0],t[0][1]*W.tileSize+t[1][1]]}if(e.length<=t);else if(e.length<5e3)e=e.sort(([t,e],[n,o])=>{const s=[e[0][0]*W.tileSize+e[1][0],e[0][1]*W.tileSize+e[1][1]],r=[o[0][0]*W.tileSize+o[1][0],o[0][1]*W.tileSize+o[1][1]];return Math.sqrt(Math.pow(s[0]-i[0],2)+Math.pow(s[1]-i[1],2))*(1+.2*Math.random())-Math.sqrt(Math.pow(r[0]-i[0],2)+Math.pow(r[1]-i[1],2))*(1+.2*Math.random())}).slice(0,t);else{const n={},o=[];e.forEach(([t,e])=>{const o=[e[0][0]*W.tileSize+e[1][0],e[0][1]*W.tileSize+e[1][1]],s=Math.floor(Math.sqrt(Math.pow(o[0]-i[0],2)+Math.pow(o[1]-i[1],2))*(1+.2*Math.random()));void 0===n[s]?n[s]=[[t,e]]:n[s].push([t,e])});const s=Object.keys(n).sort((t,e)=>t-e);for(const e of s)if(o.extend(n[e]),o.length>=t)break;e=o.slice(0,t)}const o=document.querySelector("canvas.maplibregl-canvas");A(e[0][1][0],e[0][1][1]);const s=!M();setTimeout(()=>{let t=e[0][0];document.getElementById("color-"+t).click();const n=[e[0][1][0][0]*W.tileSize+e[0][1][1][0],e[0][1][0][1]*W.tileSize+e[0][1][1][1]],i=[o.offsetWidth/2,o.offsetHeight/2],r=s?2.048:C(t=>t.transform.tileSize*t.transform.scale/2048e3);for(let s=0;s{t.parentElement.classList.contains("bm-1o")||(t.addEventListener("click",function(){W.$e()&&setTimeout(()=>{W.J(),W.fe()&&W.ge()&&T(),buildColorFilterList()},0)}),t.parentElement.classList.add("bm-1o"))})}).observe(document.body,{childList:!0,subtree:!0}),s(`%c${X}%c (${J}) userscript has loaded!`,"color: cornflowerblue;","")});var _=()=>{try{const[[t,e],[n,i]]=u(),o={tx:t,ty:e,px:n,py:i};GM.setValue("bmCoords",JSON.stringify(o))}catch(t){}},V=()=>{try{const[[t,e],[n,i]]=u();A([t,e],[n,i])}catch(t){}}})();