mirror of
https://github.com/SwingTheVine/Wplace-BlueMarble.git
synced 2026-03-11 17:15:38 +00:00
31 lines
No EOL
33 KiB
JavaScript
31 lines
No EOL
33 KiB
JavaScript
// ==UserScript==
|
|
// @name Blue Marble
|
|
// @name:en Blue Marble
|
|
// @namespace https://github.com/SwingTheVine/
|
|
// @version 0.88.80
|
|
// @description A userscript to automate and/or enhance the user experience on Wplace.live. Make sure to comply with the site's Terms of Service, and rules! This script is not affiliated with Wplace.live in any way, use at your own risk. This script is not affiliated with TamperMonkey. The author of this userscript is not responsible for any damages, issues, loss of data, or punishment that may occur as a result of using this script. This script is provided "as is" under the MPL-2.0 license. The "Blue Marble" icon is licensed under CC0 1.0 Universal (CC0 1.0) Public Domain Dedication. The image is owned by NASA.
|
|
// @description:en A userscript to automate and/or enhance the user experience on Wplace.live. Make sure to comply with the site's Terms of Service, and rules! This script is not affiliated with Wplace.live in any way, use at your own risk. This script is not affiliated with TamperMonkey. The author of this userscript is not responsible for any damages, issues, loss of data, or punishment that may occur as a result of using this script. This script is provided "as is" under the MPL-2.0 license. The "Blue Marble" icon is licensed under CC0 1.0 Universal (CC0 1.0) Public Domain Dedication. The image is owned by NASA.
|
|
// @author SwingTheVine
|
|
// @license MPL-2.0
|
|
// @donate https://ko-fi.com/swingthevine
|
|
// @supportURL https://discord.gg/tpeBPy46hf
|
|
// @homepageURL https://bluemarble.lol/
|
|
// @icon https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/0c760b903739e6214f7b8990ffc4089a93e73bd2/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_xmlhttpRequest
|
|
// @connect telemetry.thebluecorner.net
|
|
// @resource CSS-BM-File https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/0c760b903739e6214f7b8990ffc4089a93e73bd2/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/
|
|
|
|
(()=>{var e,t,n=e=>{throw TypeError(e)},i=(e,t,i)=>t.has(e)?n("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),o=(e,t,i)=>(((e,t)=>{t.has(e)||n("Cannot access private method")})(e,t),i),s=class{constructor(t,n){i(this,e),this.name=t,this.version=n,this.t=null,this.i="bm-o",this.o=null,this.l=null,this.m=[]}u(e){this.t=e}h(){return this.m.length>0&&(this.l=this.m.pop()),this}p(e){e?.appendChild(this.o),this.o=null,this.l=null,this.m=[]}v(n={},i=()=>{}){return i(this,o(this,e,t).call(this,"div",{},n)),this}S(n={},i=()=>{}){return i(this,o(this,e,t).call(this,"p",{},n)),this}$(n={},i=()=>{}){return i(this,o(this,e,t).call(this,"small",{},n)),this}M(n={},i=()=>{}){return i(this,o(this,e,t).call(this,"img",{},n)),this}T(n,i={},s=()=>{}){return s(this,o(this,e,t).call(this,"h"+n,{},i)),this}k(n={},i=()=>{}){return i(this,o(this,e,t).call(this,"hr",{},n)),this}D(n={},i=()=>{}){return i(this,o(this,e,t).call(this,"br",{},n)),this}O(n={},i=()=>{}){const s=o(this,e,t).call(this,"label",{textContent:n.textContent??""});delete n.textContent;const a=o(this,e,t).call(this,"input",{type:"checkbox"},n);return s.insertBefore(a,s.firstChild),this.h(),i(this,s,a),this}C(n={},i=()=>{}){return i(this,o(this,e,t).call(this,"button",{},n)),this}N(n={},i=()=>{}){const s=n.title??n.textContent??"Help: No info";delete n.textContent,n.title=`Help: ${s}`;const a={textContent:"?",className:"bm-D",onclick:()=>{this.B(this.i,s)}};return i(this,o(this,e,t).call(this,"button",a,n)),this}I(n={},i=()=>{}){return i(this,o(this,e,t).call(this,"input",{},n)),this}L(n={},i=()=>{}){const s=n.textContent??"";delete n.textContent;const a=o(this,e,t).call(this,"div"),r=o(this,e,t).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.h();const l=o(this,e,t).call(this,"button",{textContent:s});return this.h(),this.h(),r.setAttribute("tabindex","-1"),r.setAttribute("aria-hidden","true"),l.addEventListener("click",()=>{r.click()}),r.addEventListener("change",()=>{l.style.maxWidth=`${l.offsetWidth}px`,r.files.length>0?l.textContent=r.files[0].name:l.textContent=s}),i(this,a,r,l),this}P(n={},i=()=>{}){return i(this,o(this,e,t).call(this,"textarea",{},n)),this}B(e,t,n=!1){const i=document.getElementById(e.replace(/^#/,""));i&&(i instanceof HTMLInputElement?i.value=t:n?i.textContent=t:i.innerHTML=t)}G(e,t){let n,i=!1,o=0,s=null,a=0,r=0,l=0,m=0;if(e=document.querySelector("#"==e?.[0]?e:"#"+e),t=document.querySelector("#"==t?.[0]?t:"#"+t),!e||!t)return void this.W(`Can not drag! ${e?"":"moveMe"} ${e||t?"":"and "}${t?"":"iMoveThings "}was not found!`);const c=()=>{if(i){const t=Math.abs(a-l),n=Math.abs(r-m);(t>.5||n>.5)&&(a=l,r=m,e.style.transform=`translate(${a}px, ${r}px)`,e.style.left="0px",e.style.top="0px",e.style.right=""),s=requestAnimationFrame(c)}};let u=null;const d=(d,h)=>{i=!0,u=e.getBoundingClientRect(),n=d-u.left,o=h-u.top;const b=window.getComputedStyle(e).transform;if(b&&"none"!==b){const e=new DOMMatrix(b);a=e.m41,r=e.m42}else a=u.left,r=u.top;l=a,m=r,document.body.style.userSelect="none",t.classList.add("dragging"),s&&cancelAnimationFrame(s),c()},h=()=>{i=!1,s&&(cancelAnimationFrame(s),s=null),document.body.style.userSelect="",t.classList.remove("dragging")};t.addEventListener("mousedown",function(e){e.preventDefault(),d(e.clientX,e.clientY)}),t.addEventListener("touchstart",function(e){const t=e?.touches?.[0];t&&(d(t.clientX,t.clientY),e.preventDefault())},{passive:!1}),document.addEventListener("mousemove",function(e){i&&u&&(l=e.clientX-n,m=e.clientY-o)},{passive:!0}),document.addEventListener("touchmove",function(e){if(i&&u){const t=e?.touches?.[0];if(!t)return;l=t.clientX-n,m=t.clientY-o,e.preventDefault()}},{passive:!1}),document.addEventListener("mouseup",h),document.addEventListener("touchend",h),document.addEventListener("touchcancel",h)}_(e){(0,console.info)(`${this.name}: ${e}`),this.B(this.i,"Status: "+e,!0)}W(e){(0,console.error)(`${this.name}: ${e}`),this.B(this.i,"Error: "+e,!0)}};function a(...e){(0,console.error)(...e)}function r(e,t){if(0===e)return t[0];let n="";const i=t.length;for(;e>0;)n=t[e%i]+n,e=Math.floor(e/i);return n}function l(e){let t="";for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function m(e){const t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}e=new WeakSet,t=function(e,t={},n={}){const i=document.createElement(e);this.o?(this.l?.appendChild(i),this.m.push(this.l),this.l=i):(this.o=i,this.l=i);for(const[e,n]of Object.entries(t))i[e]=n;for(const[e,t]of Object.entries(n))i[e]=t;return i};var c,u,d,h,b,p,g,f,w=[{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]}],y=class{constructor({displayName:e="My template",X:t=0,J:n="",url:o="",file:s=null,coords:a=null,j:r=null,R:l=1e3}={}){i(this,c),this.displayName=e,this.X=t,this.J=n,this.url=o,this.file=s,this.coords=a,this.j=r,this.R=l,this.U={total:0,colors:new Map}}async Y(e,t){console.log("Template coordinates:",this.coords);const n=await createImageBitmap(this.file),i=n.width,s=n.height;this.R=e;const a={},r={},m=new OffscreenCanvas(this.R,this.R),d=m.getContext("2d",{V:!0});m.width=i,m.height=s,d.imageSmoothingEnabled=!1,d.drawImage(n,0,0);let h=Date.now();const b=o(this,c,u).call(this,d.getImageData(0,0,i,s),t);console.log(`Calculating total pixels took ${(Date.now()-h)/1e3} seconds`);let p=0;for(const[e,t]of b)0!=e&&(p+=t);this.U={total:p,colors:b},h=Date.now();const g=new OffscreenCanvas(3,3),f=g.getContext("2d");f.clearRect(0,0,3,3),f.fillStyle="white",f.fillRect(1,1,1,1);for(let e=this.coords[3];e<s+this.coords[3];){const t=Math.min(this.R-e%this.R,s-(e-this.coords[3]));console.log(`Math.min(${this.R} - (${e} % ${this.R}), ${s} - (${e-this.coords[3]}))`);for(let o=this.coords[2];o<i+this.coords[2];){console.log(`Pixel X: ${o}\nPixel Y: ${e}`);const s=Math.min(this.R-o%this.R,i-(o-this.coords[2]));console.log(`Math.min(${this.R} - (${o} % ${this.R}), ${i} - (${o-this.coords[2]}))`),console.log(`Draw Size X: ${s}\nDraw Size Y: ${t}`);const c=3*s,u=3*t;m.width=c,m.height=u,console.log(`Draw X: ${s}\nDraw Y: ${t}\nCanvas Width: ${c}\nCanvas Height: ${u}`),d.imageSmoothingEnabled=!1,console.log(`Getting X ${o}-${o+s}\nGetting Y ${e}-${e+t}`),d.clearRect(0,0,c,u),d.drawImage(n,o-this.coords[2],e-this.coords[3],s,t,0,0,3*s,3*t),d.save(),d.globalCompositeOperation="destination-in",d.fillStyle=d.createPattern(g,"repeat"),d.fillRect(0,0,c,u),d.restore();const h=d.getImageData(0,0,c,u);console.log(`Shreaded pixels for ${o}, ${e}`,h),d.putImageData(h,0,0);const b=`${(this.coords[0]+Math.floor(o/1e3)).toString().padStart(4,"0")},${(this.coords[1]+Math.floor(e/1e3)).toString().padStart(4,"0")},${(o%1e3).toString().padStart(3,"0")},${(e%1e3).toString().padStart(3,"0")}`;a[b]=await createImageBitmap(m);const p=await m.convertToBlob(),f=await p.arrayBuffer(),w=Array.from(new Uint8Array(f));r[b]=l(w),console.log(a),o+=s}e+=t}return console.log(`Parsing template took ${(Date.now()-h)/1e3} seconds`),console.log("Template Tiles: ",a),console.log("Template Tiles Buffers: ",r),{A:a,H:r}}};c=new WeakSet,u=function(e,t){const n=new Uint32Array(e.data.buffer),{palette:i,F:o}=t,s=new Map;for(let e=0;e<n.length;e++){const t=n[e];let i=-2;i=t>>>24==0?0:o.get(t)??-2,null==s.get(i)?s.set(i,1):s.set(i,s.get(i)+1)}return console.log(s),s},d=new WeakSet,h=async function(){GM.setValue("bmTemplates",JSON.stringify(this.q))},b=async function(e){console.log("Parsing BlueMarble...");const t=e.templates;if(console.log(`BlueMarble length: ${Object.keys(t).length}`),Object.keys(t).length>0)for(const e in t){const n=e,i=t[e];if(console.log(`Template Key: ${n}`),t.hasOwnProperty(e)){const e=n.split(" "),t=Number(e?.[0]),o=e?.[1]||"0",s=i.name||`Template ${t||""}`,a={total:i.pixels.total,colors:new Map(Object.entries(i.pixels.colors).map(([e,t])=>[Number(e),t]))};console.log(a);const r=i.tiles,l={};for(const e in r)if(console.log(e),r.hasOwnProperty(e)){const t=m(r[e]),n=new Blob([t],{type:"image/png"}),i=await createImageBitmap(n);l[e]=i}const c=new y({displayName:s,X:t||this.K?.length||0,J:o||""});c.U=a,c.j=l,this.K.push(c),console.log(this.K),console.log("^^^ This ^^^")}}},p=new WeakSet,g=async function(e=navigator.userAgent){return(e=e||"").includes("OPR/")||e.includes("Opera")?"Opera":e.includes("Edg/")?"Edge":e.includes("Vivaldi")?"Vivaldi":e.includes("YaBrowser")?"Yandex":e.includes("Kiwi")?"Kiwi":e.includes("Brave")?"Brave":e.includes("Firefox/")?"Firefox":e.includes("Chrome/")?"Chrome":e.includes("Safari/")?"Safari":navigator.brave&&"function"==typeof navigator.brave.isBrave&&await navigator.brave.isBrave()?"Brave":"Unknown"},f=function(e=navigator.userAgent){return/Windows NT 11/i.test(e=e||"")?"Windows 11":/Windows NT 10/i.test(e)?"Windows 10":/Windows NT 6\.3/i.test(e)?"Windows 8.1":/Windows NT 6\.2/i.test(e)?"Windows 8":/Windows NT 6\.1/i.test(e)?"Windows 7":/Windows NT 6\.0/i.test(e)?"Windows Vista":/Windows NT 5\.1|Windows XP/i.test(e)?"Windows XP":/Mac OS X 10[_\.]15/i.test(e)?"macOS Catalina":/Mac OS X 10[_\.]14/i.test(e)?"macOS Mojave":/Mac OS X 10[_\.]13/i.test(e)?"macOS High Sierra":/Mac OS X 10[_\.]12/i.test(e)?"macOS Sierra":/Mac OS X 10[_\.]11/i.test(e)?"OS X El Capitan":/Mac OS X 10[_\.]10/i.test(e)?"OS X Yosemite":/Mac OS X 10[_\.]/i.test(e)?"macOS":/Android/i.test(e)?"Android":/iPhone|iPad|iPod/i.test(e)?"iOS":/Linux/i.test(e)?"Linux":"Unknown"};var v=GM_info.script.name.toString(),x=GM_info.script.version.toString();!function(e){const t=document.createElement("script");t.setAttribute("bm-E",v),t.setAttribute("bm-B","color: cornflowerblue;"),t.textContent=`(${e})();`,document.documentElement?.appendChild(t),t.remove()}(()=>{const e=document.currentScript,t=e?.getAttribute("bm-E")||"Blue Marble",n=e?.getAttribute("bm-B")||"",i=new Map;window.addEventListener("message",e=>{const{source:o,endpoint:s,blobID:a,blobData:r,blink:l}=e.data,m=Date.now()-l;if(console.groupCollapsed(`%c${t}%c: ${i.size} Recieved IMAGE message about blob "${a}"`,n,""),console.log(`Blob fetch took %c${String(Math.floor(m/6e4)).padStart(2,"0")}:${String(Math.floor(m/1e3)%60).padStart(2,"0")}.${String(m%1e3).padStart(3,"0")}%c MM:SS.mmm`,n,""),console.log(i),console.groupEnd(),"blue-marble"==o&&a&&r&&!s){const e=i.get(a);"function"==typeof e?e(r):function(...e){(0,console.warn)(...e)}(`%c${t}%c: Attempted to retrieve a blob (%s) from queue, but the blobID was not a function! Skipping...`,n,"",a),i.delete(a)}});const o=window.fetch;window.fetch=async function(...e){const s=await o.apply(this,e),a=s.clone(),r=(e[0]instanceof Request?e[0]?.url:e[0])||"ignore",l=a.headers.get("content-type")||"";if(l.includes("application/json"))console.log(`%c${t}%c: Sending JSON message about endpoint "${r}"`,n,""),a.json().then(e=>{window.postMessage({source:"blue-marble",endpoint:r,jsonData:e},"*")}).catch(e=>{console.error(`%c${t}%c: Failed to parse JSON: `,n,"",e)});else if(l.includes("image/")&&!r.includes("openfreemap")&&!r.includes("maps")){const e=Date.now(),o=await a.blob();return console.log(`%c${t}%c: ${i.size} Sending IMAGE message about endpoint "${r}"`,n,""),new Promise(s=>{const l=crypto.randomUUID();i.set(l,e=>{s(new Response(e,{headers:a.headers,status:a.status,statusText:a.statusText})),console.log(`%c${t}%c: ${i.size} Processed blob "${l}"`,n,"")}),window.postMessage({source:"blue-marble",endpoint:r,blobID:l,blobData:o,blink:e})}).catch(o=>{const s=Date.now();console.error(`%c${t}%c: Failed to Promise blob!`,n,""),console.groupCollapsed(`%c${t}%c: Details of failed blob Promise:`,n,""),console.log(`Endpoint: ${r}\nThere are ${i.size} blobs processing...\nBlink: ${e.toLocaleString()}\nTime Since Blink: ${String(Math.floor(s/6e4)).padStart(2,"0")}:${String(Math.floor(s/1e3)%60).padStart(2,"0")}.${String(s%1e3).padStart(3,"0")} MM:SS.mmm`),console.error("Exception stack:",o),console.groupEnd()})}return s}});var S=GM_getResourceText("CSS-BM-File");GM_addStyle(S);var $,M="robotoMonoInjectionPoint";M.indexOf("@font-face")+1?(console.log("Loading Roboto Mono as a file..."),GM_addStyle(M)):(($=document.createElement("link")).href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap",$.rel="preload",$.as="style",$.onload=function(){this.onload=null,this.rel="stylesheet"},document.head?.appendChild($)),new class{constructor(){this.Z=null,this.ee=null,this.te="#bm-h"}ne(e){return this.ee=e,this.Z=new MutationObserver(e=>{for(const t of e)for(const e of t.addedNodes)e instanceof HTMLElement&&e.matches?.(this.te)}),this}ie(){return this.Z}observe(e,t=!1,n=!1){e.observe(this.ee,{childList:t,subtree:n})}};var T=new s(v,x),k=(new s(v,x),new class{constructor(e,t,n){i(this,d),this.name=e,this.version=t,this.o=n,this.oe="1.0.0",this.se=null,this.ae="!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~",this.R=1e3,this.re=3,this.le=3,this.me=function(e){const t=w;t.unshift({id:-1,premium:!1,name:"Erased",rgb:[222,250,206]}),t.unshift({id:-2,premium:!1,name:"Other",rgb:[0,0,0]});const n=new Map;for(const i of t){if(0==i.id||-2==i.id)continue;const t=i.rgb[0],o=i.rgb[1],s=i.rgb[2];for(let a=-e;a<=e;a++)for(let r=-e;r<=e;r++)for(let l=-e;l<=e;l++){const e=t+a,m=o+r,c=s+l;if(e<0||e>255||m<0||m>255||c<0||c>255)continue;const u=(255<<24|c<<16|m<<8|e)>>>0;n.has(u)||n.set(u,i.id)}}return{palette:t,F:n}}(this.le),this.ce=null,this.ue=null,this.de="bm-C",this.he="div#map canvas.maplibregl-canvas",this.be=null,this.pe="",this.K=[],this.q=null,this.ge=!0}fe(){if(document.body.contains(this.ce))return this.ce;document.getElementById(this.de)?.remove();const e=document.querySelector(this.he),t=document.createElement("canvas");return t.id=this.de,t.className="maplibregl-canvas",t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.height=e?.clientHeight*(window.devicePixelRatio||1)+"px",t.style.width=e?.clientWidth*(window.devicePixelRatio||1)+"px",t.height=e?.clientHeight*(window.devicePixelRatio||1),t.width=e?.clientWidth*(window.devicePixelRatio||1),t.style.zIndex="8999",t.style.pointerEvents="none",e?.parentElement?.appendChild(t),this.ce=t,window.addEventListener("move",this.we),window.addEventListener("zoom",this.ye),window.addEventListener("resize",this.ve),this.ce}async xe(){return{whoami:this.name.replace(" ",""),scriptVersion:this.version,schemaVersion:this.oe,templates:{}}}async Se(e,t,n){this.q||(this.q=await this.xe(),console.log("Creating JSON...")),this.o._(`Creating template at ${n.join(", ")}...`);const i=new y({displayName:t,X:0,J:r(this.se||0,this.ae),file:e,coords:n}),{A:s,H:a}=await i.Y(this.R,this.me);i.j=s;const l={total:i.U.total,colors:Object.fromEntries(i.U.colors)};this.q.templates[`${i.X} ${i.J}`]={name:i.displayName,coords:n.join(", "),enabled:!0,pixels:l,tiles:a},this.K=[],this.K.push(i),this.o._(`Template created at ${n.join(", ")}!`),console.log(Object.keys(this.q.templates).length),console.log(this.q),console.log(this.K),console.log(JSON.stringify(this.q)),await o(this,d,h).call(this)}$e(){}async Me(){this.q||(this.q=await this.xe(),console.log("Creating JSON..."))}async Te(e,t){if(!this.ge)return e;const n=this.R*this.re;t=t[0].toString().padStart(4,"0")+","+t[1].toString().padStart(4,"0"),console.log(`Searching for templates in tile: "${t}"`);const i=this.K;console.log(i),i.sort((e,t)=>e.X-t.X),console.log(i);const o=i.map(e=>{const n=Object.keys(e.j).filter(e=>e.startsWith(t));if(0===n.length)return null;const i=n.map(t=>{const n=t.split(",");return{ke:e.j[t],De:[n[0],n[1]],Oe:[n[2],n[3]]}});return i?.[0]}).filter(Boolean);console.log(o);const s=o?.length||0;if(console.log(`templateCount = ${s}`),!(s>0))return this.o._(`Sleeping\nVersion: ${this.version}`),e;{const e=i.filter(e=>Object.keys(e.j).filter(e=>e.startsWith(t)).length>0).reduce((e,t)=>e+(t.U.total||0),0),n=(new Intl.NumberFormat).format(e);this.o._(`Displaying ${s} template${1==s?"":"s"}.\nTotal pixels: ${n}`)}const a=await createImageBitmap(e),r=new OffscreenCanvas(n,n),l=r.getContext("2d");l.imageSmoothingEnabled=!1,l.beginPath(),l.rect(0,0,n,n),l.clip(),l.clearRect(0,0,n,n),l.drawImage(a,0,0,n,n);for(const e of o)console.log("Template:"),console.log(e),l.drawImage(e.ke,Number(e.Oe[0])*this.re,Number(e.Oe[1])*this.re);return await r.convertToBlob({type:"image/png"})}Ce(e){console.log("Importing JSON..."),console.log(e),"BlueMarble"==e?.whoami&&o(this,d,b).call(this,e)}Ne(e){this.ge=e}}(v,x,T)),D=new class{constructor(e){i(this,p),this.Be=e,this.Ie=!1,this.Le=[],this.Pe=[]}Ge(e){window.addEventListener("message",async t=>{const n=t.data,i=n.jsonData;if(!n||"blue-marble"!==n.source)return;if(!n.endpoint)return;const o=n.endpoint?.split("?")[0].split("/").filter(e=>e&&isNaN(Number(e))).filter(e=>e&&!e.includes(".")).pop();switch(console.log('%cBlue Marble%c: Recieved message about "%s"',"color: cornflowerblue;","",o),o){case"me":if(i.status&&"2"!=i.status?.toString()[0])return void e.W("You are not logged in!\nCould not fetch userdata.");const t=Math.ceil(Math.pow(Math.floor(i.level)*Math.pow(30,.65),1/.65)-i.pixelsPainted);console.log(i.id),(i.id||0===i.id)&&console.log(r(i.id,"!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~")),this.Be.se=i.id,e.B("bm-p",`Droplets: <b>${(new Intl.NumberFormat).format(i.droplets)}</b>`),e.B("bm-i",`Next level in <b>${(new Intl.NumberFormat).format(t)}</b> pixel${1==t?"":"s"}`);break;case"pixel":const o=n.endpoint.split("?")[0].split("/").filter(e=>e&&!isNaN(Number(e))),l=new URLSearchParams(n.endpoint.split("?")[1]),m=[l.get("x"),l.get("y")];if(this.Le.length&&(!o.length||!m.length))return void e.W("Coordinates are malformed!\nDid you try clicking the canvas first?");this.Le=[...o,...m];const c=(s=o,a=m,[parseInt(s[0])%4*1e3+parseInt(a[0]),parseInt(s[1])%4*1e3+parseInt(a[1])]),u=document.querySelectorAll("span");for(const e of u)if(e.textContent.trim().includes(`${c[0]}, ${c[1]}`)){let t=document.querySelector("#bm-h");const n=`(Tl X: ${o[0]}, Tl Y: ${o[1]}, Px X: ${m[0]}, Px Y: ${m[1]})`;t?t.textContent=n:(t=document.createElement("span"),t.id="bm-h",t.textContent=n,t.style="margin-left: calc(var(--spacing)*3); font-size: small;",e.parentNode.parentNode.insertAdjacentElement("afterend",t))}break;case"tiles":let d=n.endpoint.split("/");d=[parseInt(d[d.length-2]),parseInt(d[d.length-1].replace(".png",""))];const h=n.blobID,b=n.blobData,p=await this.Be.Te(b,d);window.postMessage({source:"blue-marble",blobID:h,blobData:p,blink:n.blink});break;case"robots":this.Ie="false"==i.userscript?.toString().toLowerCase();break}var s,a})}async We(e){console.log("Sending heartbeat to telemetry server...");let t=GM_getValue("bmUserSettings","{}");if(t=JSON.parse(t),!t||!t.telemetry||!t.uuid)return void console.log("Telemetry is disabled, not sending heartbeat.");const n=navigator.userAgent;let i=await o(this,p,g).call(this,n),s=o(this,p,f).call(this,n);GM_xmlhttpRequest({method:"POST",url:"https://telemetry.thebluecorner.net/heartbeat",headers:{"Content-Type":"application/json"},data:JSON.stringify({uuid:t.uuid,version:e,browser:i,os:s}),onload:e=>{200!==e.status&&a("Failed to send heartbeat:",e.statusText)},onerror:e=>{a("Error sending heartbeat:",e)}})}}(k);T.u(D);var O=JSON.parse(GM_getValue("bmTemplates","{}"));console.log(O),k.Ce(O);var C=JSON.parse(GM_getValue("bmUserSettings","{}"));if(console.log(C),console.log(Object.keys(C).length),0==Object.keys(C).length){const e=crypto.randomUUID();console.log(e),GM.setValue("bmUserSettings",JSON.stringify({uuid:e}))}if(setInterval(()=>D.We(x),18e5),console.log(`Telemetry is ${!(null==C?.telemetry)}`),null==C?.telemetry||C?.telemetry>1){const e=new s(v,x);e.u(D),e.v({id:"bm-d",style:"top: 0px; left: 0px; width: 100vw; max-width: 100vw; height: 100vh; max-height: 100vh; z-index: 9999;"}).v({id:"bm-7",style:"display: flex; flex-direction: column; align-items: center;"}).v({id:"bm-1",style:"margin-top: 10%;"}).T(1,{textContent:`${v} Telemetry`}).h().h().v({id:"bm-e",style:"max-width: 50%; overflow-y: auto; max-height: 80vh;"}).k().h().D().h().v({style:"width: fit-content; margin: auto; text-align: center;"}).C({id:"bm-8",textContent:"More Information"},(e,t)=>{t.onclick=()=>{window.open("https://github.com/SwingTheVine/Wplace-TelemetryServer#telemetry-data","_blank","noopener noreferrer")}}).h().h().D().h().v({style:"width: fit-content; margin: auto; text-align: center;"}).C({id:"bm-5",textContent:"Enable Telemetry",style:"margin-right: 2ch;"},(e,t)=>{t.onclick=()=>{const e=JSON.parse(GM_getValue("bmUserSettings","{}"));e.telemetry=1,GM.setValue("bmUserSettings",JSON.stringify(e));const t=document.getElementById("bm-d");t&&(t.style.display="none")}}).h().C({id:"bm-2",textContent:"Disable Telemetry"},(e,t)=>{t.onclick=()=>{const e=JSON.parse(GM_getValue("bmUserSettings","{}"));e.telemetry=0,GM.setValue("bmUserSettings",JSON.stringify(e));const t=document.getElementById("bm-d");t&&(t.style.display="none")}}).h().h().D().h().S({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 the Blue Marble!"}).h().S({textContent:'You can disable telemetry by pressing the "Disable" button below.'}).h().h().h().p(document.body)}!function(){let e=!1;T.v({id:"bm-A",style:"top: 10px; right: 75px;"}).v({id:"bm-j"}).v({id:"bm-z"}).h().M({alt:"Blue Marble Icon - Click to minimize/maximize",src:"https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/dist/assets/Favicon.png",style:"cursor: pointer;"},(t,n)=>{n.addEventListener("click",()=>{e=!e;const i=document.querySelector("#bm-A"),o=document.querySelector("#bm-j"),s=document.querySelector("#bm-z"),a=document.querySelector("#bm-k"),r=document.querySelector("#bm-q"),l=document.querySelector("#bm-r"),m=document.querySelector("#bm-s"),c=document.querySelector("#bm-l"),u=document.querySelectorAll("#bm-k input");e||(i.style.width="auto",i.style.maxWidth="300px",i.style.minWidth="200px",i.style.padding="10px"),["#bm-A h1","#bm-f","#bm-A hr","#bm-c > *:not(#bm-k)","#bm-a","#bm-6",`#${t.i}`].forEach(t=>{document.querySelectorAll(t).forEach(t=>{t.style.display=e?"none":""})}),e?(a&&(a.style.display="none"),r&&(r.style.display="none"),l&&(l.style.display="none"),m&&(m.style.display="none"),c&&(c.style.display="none"),u.forEach(e=>{e.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")):(a&&(a.style.display="",a.style.flexDirection="",a.style.justifyContent="",a.style.alignItems="",a.style.gap="",a.style.textAlign="",a.style.margin=""),r&&(r.style.display=""),l&&(l.style.display="",l.style.marginTop=""),m&&(m.style.display="",m.style.marginTop=""),c&&(c.style.display="",c.style.marginTop=""),u.forEach(e=>{e.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=e?"Blue Marble Icon - Minimized (Click to maximize)":"Blue Marble Icon - Maximized (Click to minimize)"})}).h().T(1,{textContent:v}).h().h().k().h().v({id:"bm-f"}).S({id:"bm-p",textContent:"Droplets:"}).h().S({id:"bm-i",textContent:"Next level in..."}).h().h().k().h().v({id:"bm-c"}).v({id:"bm-k"}).C({id:"bm-q",className:"bm-D",style:"margin-top: 0;",innerHTML:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4 6"><circle cx="2" cy="2" r="2"></circle><path d="M2 6 L3.7 3 L0.3 3 Z"></path><circle cx="2" cy="2" r="0.7" fill="white"></circle></svg></svg>'},(e,t)=>{t.onclick=()=>{const t=e.t?.Le;t?.[0]?(e.B("bm-v",t?.[0]||""),e.B("bm-w",t?.[1]||""),e.B("bm-x",t?.[2]||""),e.B("bm-y",t?.[3]||"")):e.W("Coordinates are malformed! Did you try clicking on the canvas first?")}}).h().I({type:"number",id:"bm-v",placeholder:"Tl X",min:0,max:2047,step:1,required:!0},(e,t)=>{t.addEventListener("paste",e=>{let t=(e.clipboardData||window.clipboardData).getData("text").split(" ").filter(e=>e).map(Number).filter(e=>!isNaN(e));if(4!==t.length)return;let n=selectAllCoordinateInputs(document);for(let e=0;e<n.length;e++)n[e].value=t[e];e.preventDefault()});const n=()=>persistCoords();t.addEventListener("input",n),t.addEventListener("change",n)}).h().I({type:"number",id:"bm-w",placeholder:"Tl Y",min:0,max:2047,step:1,required:!0},(e,t)=>{const n=()=>persistCoords();t.addEventListener("input",n),t.addEventListener("change",n)}).h().I({type:"number",id:"bm-x",placeholder:"Px X",min:0,max:2047,step:1,required:!0},(e,t)=>{const n=()=>persistCoords();t.addEventListener("input",n),t.addEventListener("change",n)}).h().I({type:"number",id:"bm-y",placeholder:"Px Y",min:0,max:2047,step:1,required:!0},(e,t)=>{const n=()=>persistCoords();t.addEventListener("input",n),t.addEventListener("change",n)}).h().h().L({id:"bm-a",textContent:"Upload Template",accept:"image/png, image/jpeg, image/webp, image/bmp, image/gif"}).h().v({id:"bm-4"}).C({id:"bm-s",textContent:"Enable"},(e,t)=>{t.onclick=()=>{e.t?.Be?.Ne(!0),e._("Enabled templates!")}}).h().C({id:"bm-r",textContent:"Create"},(e,t)=>{t.onclick=()=>{const t=document.querySelector("#bm-a"),n=document.querySelector("#bm-v");if(!n.checkValidity())return n.reportValidity(),void e.W("Coordinates are malformed! Did you try clicking on the canvas first?");const i=document.querySelector("#bm-w");if(!i.checkValidity())return i.reportValidity(),void e.W("Coordinates are malformed! Did you try clicking on the canvas first?");const o=document.querySelector("#bm-x");if(!o.checkValidity())return o.reportValidity(),void e.W("Coordinates are malformed! Did you try clicking on the canvas first?");const s=document.querySelector("#bm-y");if(!s.checkValidity())return s.reportValidity(),void e.W("Coordinates are malformed! Did you try clicking on the canvas first?");t?.files[0]?(k.Se(t.files[0],t.files[0]?.name.replace(/\.[^/.]+$/,""),[Number(n.value),Number(i.value),Number(o.value),Number(s.value)]),e._("Drew to canvas!")):e.W("No file selected!")}}).h().C({id:"bm-l",textContent:"Disable"},(e,t)=>{t.onclick=()=>{e.t?.Be?.Ne(!1),e._("Disabled templates!")}}).h().h().P({id:T.i,placeholder:`Status: Sleeping...\nVersion: ${x}`,readOnly:!0}).h().v({id:"bm-6"}).v().C({id:"bm-m",className:"bm-D",innerHTML:"🎨",title:"Template Color Converter"},(e,t)=>{t.addEventListener("click",()=>{window.open("https://pepoafonso.github.io/color_converter_wplace/","_blank","noopener noreferrer")})}).h().C({id:"bm-n",className:"bm-D",innerHTML:"🌐",title:"Official Blue Marble Website"},(e,t)=>{t.addEventListener("click",()=>{window.open("https://bluemarble.lol/","_blank","noopener noreferrer")})}).h().h().$({textContent:"Made by SwingTheVine",style:"margin-top: auto;"}).h().h().h().p(document.body)}(),T.G("#bm-A","#bm-z"),D.Ge(T),new MutationObserver((e,t)=>{const n=document.querySelector("#color-1");if(!n)return;let i=document.querySelector("#bm-t");if(!i){i=document.createElement("button"),i.id="bm-t",i.textContent="Move ↑",i.className="btn btn-soft",i.onclick=function(){const e=this.parentNode.parentNode.parentNode.parentNode,t="Move ↑"==this.textContent;e.parentNode.className=e.parentNode.className.replace(t?"bottom":"top",t?"top":"bottom"),e.style.borderTopLeftRadius=t?"0px":"var(--radius-box)",e.style.borderTopRightRadius=t?"0px":"var(--radius-box)",e.style.borderBottomLeftRadius=t?"var(--radius-box)":"0px",e.style.borderBottomRightRadius=t?"var(--radius-box)":"0px",this.textContent=t?"Move ↓":"Move ↑"};const e=n.parentNode.parentNode.parentNode.parentNode.querySelector("h2");e.parentNode?.appendChild(i)}}).observe(document.body,{childList:!0,subtree:!0}),function(...e){(0,console.log)(...e)}(`%c${v}%c (${x}) userscript has loaded!`,"color: cornflowerblue;","")})(); |