diff --git a/dist/BlueMarble.user.js b/dist/BlueMarble.user.js index 55a95eb..2133688 100644 --- a/dist/BlueMarble.user.js +++ b/dist/BlueMarble.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Blue Marble // @namespace https://github.com/SwingTheVine/ -// @version 0.63.58 +// @version 0.63.68 // @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 // @license MPL-2.0 @@ -20,4 +20,4 @@ // Wplace --> https://wplace.live // License --> https://www.mozilla.org/en-US/MPL/2.0/ -(()=>{var t,e,n=t=>{throw TypeError(t)},s=(t,e,s)=>(((t,e)=>{e.has(t)||n("Cannot access private method")})(t,e),s);t=new WeakSet,e=function(t,e={},n={}){const s=document.createElement(t);this.t?(this.i.appendChild(s),this.o.push(this.i),this.i=s):(this.t=s,this.i=s);for(const[t,n]of Object.entries(e))s[t]=n;for(const[t,e]of Object.entries(n))s[t]=e;return s};var i=GM_info.script.name.toString(),o=GM_info.script.version.toString();!function(t){const e=document.createElement("script");e.setAttribute("bm-s",i),e.setAttribute("bm-q","color: cornflowerblue;"),e.textContent=`(${t})();`,document.documentElement.appendChild(e),e.remove()}(()=>{const t=document.currentScript,e=t?.getAttribute("bm-s")||"Blue Marble",n=t?.getAttribute("bm-q")||"",s=new Map;window.addEventListener("message",t=>{const{source:i,endpoint:o,blobID:a,blobData:c,blink:r}=t.data,l=Date.now()-r;console.groupCollapsed(`%c${e}%c: ${s.size} Recieved IMAGE message about blob "${a}"`,n,""),console.log(`Blob fetch took %c${String(Math.floor(l/6e4)).padStart(2,"0")}:${String(Math.floor(l/1e3)%60).padStart(2,"0")}.${String(l%1e3).padStart(3,"0")}%c MM:SS.mmm`,n,""),console.log(s),console.groupEnd(),"blue-marble"==i&&a&&c&&!o&&s.get(a)(c)});const i=window.fetch;window.fetch=async function(...t){const o=await i.apply(this,t),a=o.clone(),c=(t[0]instanceof Request?t[0]?.url:t[0])||"ignore",r=a.headers.get("content-type")||"";if(r.includes("application/json"))console.log(`%c${e}%c: Sending JSON message about endpoint "${c}"`,n,""),a.json().then(t=>{window.postMessage({source:"blue-marble",endpoint:c,jsonData:t},"*")}).catch(t=>{console.error(`%c${e}%c: Failed to parse JSON: `,n,"",t)});else if(r.includes("image/")&&!c.includes("openfreemap")){const t=Date.now(),i=await a.blob();return console.log(`%c${e}%c: ${s.size} Sending IMAGE message about endpoint "${c}"`,n,""),new Promise(o=>{const r=crypto.randomUUID();s.set(r,t=>{o(new Response(t,{headers:a.headers,status:a.status,statusText:a.statusText})),s.delete(r),console.log(`%c${e}%c: ${s.size} Processed blob "${r}"`,n,"")}),window.postMessage({source:"blue-marble",endpoint:c,blobID:r,blobData:i,blink:t})}).catch(i=>{const o=Date.now();console.error(`%c${e}%c: Failed to Promise blob!`,n,""),console.groupCollapsed(`%c${e}%c: Details of failed blob Promise:`,n,""),console.log(`Endpoint: ${c}\nThere are ${s.size} blobs processing...\nBlink: ${t.toLocaleString()}\nTime Since Blink: ${String(Math.floor(o/6e4)).padStart(2,"0")}:${String(Math.floor(o/1e3)%60).padStart(2,"0")}.${String(o%1e3).padStart(3,"0")} MM:SS.mmm`),console.error("Exception stack:",i),console.groupEnd()})}return o}});var a=GM_getResourceText("CSS-BM-File");GM_addStyle(a);var c=document.createElement("link");c.href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap",c.rel="preload",c.as="style",c.onload=function(){this.onload=null,this.rel="stylesheet"},document.head.appendChild(c),new class{constructor(){this.l=null,this.h=null,this.m="#bm-9"}u(t){return this.h=t,this.l=new MutationObserver(t=>{for(const e of t)for(const t of e.addedNodes)t instanceof HTMLElement&&t.matches?.(this.m)}),this}p(){return this.l}observe(t,e=!1,n=!1){t.observe(this.h,{childList:e,subtree:n})}};var r=new class{constructor(e,s){var i,o;i=this,(o=t).has(i)?n("Cannot add the same private member more than once"):o instanceof WeakSet?o.add(i):o.set(i,undefined),this.name=e,this.version=s,this.v=null,this.$="bm-e",this.t=null,this.i=null,this.o=[]}M(t){this.v=t}S(){return this.o.length>0&&(this.i=this.o.pop()),this}C(t){t.appendChild(this.t),this.t=null,this.i=null,this.o=[]}k(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"div",{},n)),this}T(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"p",{},n)),this}D(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"small",{},n)),this}I(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"img",{},n)),this}B(n,i={},o=()=>{}){return o(this,s(this,t,e).call(this,"h"+n,{},i)),this}N(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"hr",{},n)),this}L(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"br",{},n)),this}P(n={},i=()=>{}){const o=s(this,t,e).call(this,"label",{textContent:n.textContent??""});delete n.textContent;const a=s(this,t,e).call(this,"input",{type:"checkbox"},n);return o.insertBefore(a,o.firstChild),this.S(),i(this,o,a),this}H(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"button",{},n)),this}O(n={},i=()=>{}){const o=n.title??n.textContent??"Help: No info";delete n.textContent,n.title=`Help: ${o}`;const a={textContent:"?",className:"bm-t",onclick:()=>{this.R(this.$,o)}};return i(this,s(this,t,e).call(this,"button",a,n)),this}G(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"input",{},n)),this}U(n={},i=()=>{}){const o=n.textContent??"";delete n.textContent;const a=s(this,t,e).call(this,"div"),c=s(this,t,e).call(this,"input",{type:"file",style:"display: none;"},n);this.S();const r=s(this,t,e).call(this,"button",{textContent:o});return this.S(),this.S(),r.addEventListener("click",()=>{c.click()}),c.addEventListener("change",()=>{r.style.maxWidth=`${r.offsetWidth}px`,c.files.length>0?r.textContent=c.files[0].name:r.textContent=o}),i(this,a,c,r),this}j(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"textarea",{},n)),this}R(t,e,n=!1){const s=document.getElementById(t.replace(/^#/,""));s&&(s instanceof HTMLInputElement?s.value=e:n?s.textContent=e:s.innerHTML=e)}F(t,e){let n,s=!1,i=0;t=document.querySelector("#"==t?.[0]?t:"#"+t),e=document.querySelector("#"==e?.[0]?e:"#"+e),t&&e?(e.addEventListener("mousedown",function(o){s=!0,n=o.clientX-t.getBoundingClientRect().left,i=o.clientY-t.getBoundingClientRect().top,document.body.style.userSelect="none",e.classList.add("dragging")}),e.addEventListener("touchstart",function(o){s=!0;const a=o?.touches?.[0];a&&(n=a.clientX-t.getBoundingClientRect().left,i=a.clientY-t.getBoundingClientRect().top,document.body.style.userSelect="none",e.classList.add("dragging"))},{passive:!1}),document.addEventListener("mousemove",function(e){s&&(t.style.left=e.clientX-n+"px",t.style.top=e.clientY-i+"px",t.style.right="")}),document.addEventListener("touchmove",function(e){if(s){const s=e?.touches?.[0];if(!s)return;t.style.left=s.clientX-n+"px",t.style.top=s.clientY-i+"px",e.preventDefault()}},{passive:!1}),document.addEventListener("mouseup",function(){s=!1,document.body.style.userSelect="",e.classList.remove("dragging")}),document.addEventListener("touchend",function(){s=!1,document.body.style.userSelect="",e.classList.remove("dragging")}),document.addEventListener("touchcancel",function(){s=!1,document.body.style.userSelect="",e.classList.remove("dragging")})):this._(`Can not drag! ${t?"":"moveMe"} ${t||e?"":"and "}${e?"":"iMoveThings "}was not found!`)}W(t){(0,console.info)(`${this.name}: ${t}`),this.R(this.$,"Status: "+t,!0)}_(t){(0,console.error)(`${this.name}: ${t}`),this.R(this.$,"Error: "+t,!0)}}(i,o),l=new class{constructor(){this.X=null,this.Y="bm-r",this.q="div#map canvas.maplibregl-canvas",this.A=null,this.V=""}J(){if(document.body.contains(this.X))return this.X;document.getElementById(this.Y)?.remove();const t=document.querySelector(this.q),e=document.createElement("canvas");return e.id=this.Y,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.X=e,window.addEventListener("move",this.Z),window.addEventListener("zoom",this.K),window.addEventListener("resize",this.tt),this.X}et(t){this.A=t,this.V="file"}async nt(t){if("file"!=this.V&&"template"!=this.V)return;const e=3e3;console.log(this.A);const n="template"==this.V?this.A:await createImageBitmap(await this.st(this.A)),s=await createImageBitmap(t),i=new OffscreenCanvas(e,e),o=i.getContext("2d");o.imageSmoothingEnabled=!1,o.clearRect(0,0,e,e),o.drawImage(n,0,0),o.drawImage(s,0,0,e,e);const a=await i.convertToBlob({type:"image/png"});if("template"!=this.V){this.A=n,this.V="template";const t=URL.createObjectURL(a);window.open(t,"_blank"),setTimeout(()=>URL.revokeObjectURL(t),1e4)}return a}async st(t,e=3,n="image/png"){const s=await createImageBitmap(t);e|=1;const i=s.width*Math.round(e),o=s.height*Math.round(e),a=document.createElement("canvas");a.width=i,a.height=o;const c=a.getContext("2d");c.imageSmoothingEnabled=!1,c.drawImage(s,0,0,i,o);const r=c.getImageData(0,0,i,o);for(let t=0;t{a.toBlob(t,n)})}},h=new class{constructor(t){this.it=t,this.ot=!1,this.ct=[]}rt(t){window.addEventListener("message",async e=>{const n=e.data,s=n.jsonData;if(!n||"blue-marble"!==n.source)return;if(!n.endpoint)return;const i=n.endpoint?.split("?")[0].split("/").filter(t=>t&&isNaN(Number(t))).filter(t=>t&&!t.includes(".")).pop();switch(console.log(`%cBlue Marble%c: Recieved message about "${i}"`,"color: cornflowerblue;",""),i){case"me":if(s.status&&"2"!=s.status?.toString()[0])return void t._("The game is down!\nCould not fetch userdata.");const e=Math.ceil(Math.pow(Math.floor(s.level)*Math.pow(30,.65),1/.65)-s.pixelsPainted);t.R("bm-j",`Username: ${function(t){const e=document.createElement("div");return e.textContent=t,e.innerHTML}(s.name)}`),t.R("bm-f",`Droplets: ${(new Intl.NumberFormat).format(s.droplets)}`),t.R("bm-a",`Next level in ${(new Intl.NumberFormat).format(e)} pixel${1==e?"":"s"}`);break;case"pixel":const i=n.endpoint.split("?")[0].split("/").filter(t=>t&&!isNaN(Number(t))),c=new URLSearchParams(n.endpoint.split("?")[1]),r=[c.get("x"),c.get("y")];if(this.ct.length&&(!i.length||!r.length))return void t._("Coordinates are malformed!\nDid you try clicking the canvas first?");this.ct=[...i,...r];const l=(o=i,a=r,[parseInt(o[0])%4*1e3+parseInt(a[0]),parseInt(o[1])%4*1e3+parseInt(a[1])]),h=document.querySelectorAll("span");for(const t of h)if(t.textContent.trim().includes(`${l[0]}, ${l[1]}`)){let e=document.querySelector("#bm-9");const n=`(Tl X: ${i[0]}, Tl Y: ${i[1]}, Px X: ${r[0]}, Px Y: ${r[1]})`;e?e.textContent=n:(e=document.createElement("span"),e.id="bm-9",e.textContent=n,e.style="margin-left: calc(var(--spacing)*3); font-size: small;",t.parentNode.parentNode.parentNode.insertAdjacentElement("afterend",e))}break;case"tiles":const d=n.blobID,m=n.blobData;console.log(`templateState: ${this.it.V||null}`);let u=this.it.V?await this.it.nt(m):m;window.postMessage({source:"blue-marble",blobID:d,blobData:u,blink:n.blink});break;case"robots":this.ot="false"==s.userscript?.toString().toLowerCase();break}var o,a})}}(l);r.M(h),r.k({id:"bm-p",style:"top: 10px; right: 75px;"}).k({id:"bm-b"}).k({id:"bm-k"}).S().I({alt:"Blue Marble Icon",src:"https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/dist/assets/Favicon.png"}).S().B(1,{textContent:i}).S().S().N().S().k({id:"bm-4"}).T({id:"bm-j",textContent:"Username:"}).S().T({id:"bm-f",textContent:"Droplets:"}).S().T({id:"bm-a",textContent:"Next level in..."}).S().S().N().S().k({id:"bm-3"}).P({id:"bm-g",textContent:"Stealth",checked:!0}).S().O({title:"Waits for the website to make requests, instead of sending requests."}).S().L().S().P({id:"bm-6",textContent:"Possessed",checked:!0}).S().O({title:"Controls the website as if it were possessed."}).S().L().S().k({id:"bm-c"}).H({id:"bm-h",className:"bm-t",style:"margin-top: 0;",innerHTML:''},(t,e)=>{e.onclick=()=>{const e=t.v?.ct;e?.[0]?(t.R("bm-l",e?.[0]||""),t.R("bm-m",e?.[1]||""),t.R("bm-n",e?.[2]||""),t.R("bm-o",e?.[3]||"")):t._("Coordinates are malformed! Did you try clicking on the canvas first?")}}).S().G({type:"number",id:"bm-l",placeholder:"Tl X",min:0,max:2047,step:1}).S().G({type:"number",id:"bm-m",placeholder:"Tl Y",min:0,max:2047,step:1}).S().G({type:"number",id:"bm-n",placeholder:"Px X",min:0,max:2047,step:1}).S().G({type:"number",id:"bm-o",placeholder:"Px Y",min:0,max:2047,step:1}).S().S().U({id:"bm-2",textContent:"Upload Template",accept:"image/png, image/jpeg, image/webp, image/bmp, image/gif"}).S().k({id:"bm-0"}).H({id:"bm-i",textContent:"Enable"},(t,e)=>{e.onclick=()=>{const e=document.querySelector("#bm-2");e?.files[0]?(l.et(e.files[0]),t.W("Drew to canvas!")):t._("No file selected!")}}).S().H({id:"bm-d",textContent:"Disable"}).S().S().j({id:r.$,placeholder:`Status: Sleeping...\nVersion: ${o}`,readOnly:!0}).S().k({id:"bm-1"}).k().H({id:"bm-7",className:"bm-t",textContent:"✈"}).S().H({id:"bm-8",className:"bm-t",innerHTML:''}).S().H({id:"bm-5",className:"bm-t",innerHTML:"🖌"}).S().S().D({textContent:"Made by SwingTheVine",style:"margin-top: auto;"}).S().S().S().C(document.body),r.F("#bm-p","#bm-k"),h.rt(r),function(...t){(0,console.log)(...t)}(`%c${i}%c (${o}) userscript has loaded!`,"color: cornflowerblue;","")})(); \ No newline at end of file +(()=>{var t,e,n=t=>{throw TypeError(t)},s=(t,e,s)=>(((t,e)=>{e.has(t)||n("Cannot access private method")})(t,e),s);t=new WeakSet,e=function(t,e={},n={}){const s=document.createElement(t);this.t?(this.i.appendChild(s),this.o.push(this.i),this.i=s):(this.t=s,this.i=s);for(const[t,n]of Object.entries(e))s[t]=n;for(const[t,e]of Object.entries(n))s[t]=e;return s};var i=GM_info.script.name.toString(),o=GM_info.script.version.toString();!function(t){const e=document.createElement("script");e.setAttribute("bm-s",i),e.setAttribute("bm-q","color: cornflowerblue;"),e.textContent=`(${t})();`,document.documentElement.appendChild(e),e.remove()}(()=>{const t=document.currentScript,e=t?.getAttribute("bm-s")||"Blue Marble",n=t?.getAttribute("bm-q")||"",s=new Map;window.addEventListener("message",t=>{const{source:i,endpoint:o,blobID:a,blobData:c,blink:r}=t.data,l=Date.now()-r;console.groupCollapsed(`%c${e}%c: ${s.size} Recieved IMAGE message about blob "${a}"`,n,""),console.log(`Blob fetch took %c${String(Math.floor(l/6e4)).padStart(2,"0")}:${String(Math.floor(l/1e3)%60).padStart(2,"0")}.${String(l%1e3).padStart(3,"0")}%c MM:SS.mmm`,n,""),console.log(s),console.groupEnd(),"blue-marble"==i&&a&&c&&!o&&s.get(a)(c)});const i=window.fetch;window.fetch=async function(...t){const o=await i.apply(this,t),a=o.clone(),c=(t[0]instanceof Request?t[0]?.url:t[0])||"ignore",r=a.headers.get("content-type")||"";if(r.includes("application/json"))console.log(`%c${e}%c: Sending JSON message about endpoint "${c}"`,n,""),a.json().then(t=>{window.postMessage({source:"blue-marble",endpoint:c,jsonData:t},"*")}).catch(t=>{console.error(`%c${e}%c: Failed to parse JSON: `,n,"",t)});else if(r.includes("image/")&&!c.includes("openfreemap")){const t=Date.now(),i=await a.blob();return console.log(`%c${e}%c: ${s.size} Sending IMAGE message about endpoint "${c}"`,n,""),new Promise(o=>{const r=crypto.randomUUID();s.set(r,t=>{o(new Response(t,{headers:a.headers,status:a.status,statusText:a.statusText})),s.delete(r),console.log(`%c${e}%c: ${s.size} Processed blob "${r}"`,n,"")}),window.postMessage({source:"blue-marble",endpoint:c,blobID:r,blobData:i,blink:t})}).catch(i=>{const o=Date.now();console.error(`%c${e}%c: Failed to Promise blob!`,n,""),console.groupCollapsed(`%c${e}%c: Details of failed blob Promise:`,n,""),console.log(`Endpoint: ${c}\nThere are ${s.size} blobs processing...\nBlink: ${t.toLocaleString()}\nTime Since Blink: ${String(Math.floor(o/6e4)).padStart(2,"0")}:${String(Math.floor(o/1e3)%60).padStart(2,"0")}.${String(o%1e3).padStart(3,"0")} MM:SS.mmm`),console.error("Exception stack:",i),console.groupEnd()})}return o}});var a=GM_getResourceText("CSS-BM-File");GM_addStyle(a);var c=document.createElement("link");c.href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap",c.rel="preload",c.as="style",c.onload=function(){this.onload=null,this.rel="stylesheet"},document.head.appendChild(c),new class{constructor(){this.l=null,this.h=null,this.m="#bm-9"}u(t){return this.h=t,this.l=new MutationObserver(t=>{for(const e of t)for(const t of e.addedNodes)t instanceof HTMLElement&&t.matches?.(this.m)}),this}p(){return this.l}observe(t,e=!1,n=!1){t.observe(this.h,{childList:e,subtree:n})}};var r=new class{constructor(e,s){var i,o;i=this,(o=t).has(i)?n("Cannot add the same private member more than once"):o instanceof WeakSet?o.add(i):o.set(i,undefined),this.name=e,this.version=s,this.v=null,this.$="bm-e",this.t=null,this.i=null,this.o=[]}M(t){this.v=t}S(){return this.o.length>0&&(this.i=this.o.pop()),this}C(t){t.appendChild(this.t),this.t=null,this.i=null,this.o=[]}k(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"div",{},n)),this}T(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"p",{},n)),this}I(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"small",{},n)),this}D(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"img",{},n)),this}B(n,i={},o=()=>{}){return o(this,s(this,t,e).call(this,"h"+n,{},i)),this}N(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"hr",{},n)),this}L(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"br",{},n)),this}P(n={},i=()=>{}){const o=s(this,t,e).call(this,"label",{textContent:n.textContent??""});delete n.textContent;const a=s(this,t,e).call(this,"input",{type:"checkbox"},n);return o.insertBefore(a,o.firstChild),this.S(),i(this,o,a),this}H(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"button",{},n)),this}O(n={},i=()=>{}){const o=n.title??n.textContent??"Help: No info";delete n.textContent,n.title=`Help: ${o}`;const a={textContent:"?",className:"bm-t",onclick:()=>{this.R(this.$,o)}};return i(this,s(this,t,e).call(this,"button",a,n)),this}G(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"input",{},n)),this}U(n={},i=()=>{}){const o=n.textContent??"";delete n.textContent;const a=s(this,t,e).call(this,"div"),c=s(this,t,e).call(this,"input",{type:"file",style:"display: none;"},n);this.S();const r=s(this,t,e).call(this,"button",{textContent:o});return this.S(),this.S(),r.addEventListener("click",()=>{c.click()}),c.addEventListener("change",()=>{r.style.maxWidth=`${r.offsetWidth}px`,c.files.length>0?r.textContent=c.files[0].name:r.textContent=o}),i(this,a,c,r),this}j(n={},i=()=>{}){return i(this,s(this,t,e).call(this,"textarea",{},n)),this}R(t,e,n=!1){const s=document.getElementById(t.replace(/^#/,""));s&&(s instanceof HTMLInputElement?s.value=e:n?s.textContent=e:s.innerHTML=e)}F(t,e){let n,s=!1,i=0;t=document.querySelector("#"==t?.[0]?t:"#"+t),e=document.querySelector("#"==e?.[0]?e:"#"+e),t&&e?(e.addEventListener("mousedown",function(o){s=!0,n=o.clientX-t.getBoundingClientRect().left,i=o.clientY-t.getBoundingClientRect().top,document.body.style.userSelect="none",e.classList.add("dragging")}),e.addEventListener("touchstart",function(o){s=!0;const a=o?.touches?.[0];a&&(n=a.clientX-t.getBoundingClientRect().left,i=a.clientY-t.getBoundingClientRect().top,document.body.style.userSelect="none",e.classList.add("dragging"))},{passive:!1}),document.addEventListener("mousemove",function(e){s&&(t.style.left=e.clientX-n+"px",t.style.top=e.clientY-i+"px",t.style.right="")}),document.addEventListener("touchmove",function(e){if(s){const s=e?.touches?.[0];if(!s)return;t.style.left=s.clientX-n+"px",t.style.top=s.clientY-i+"px",e.preventDefault()}},{passive:!1}),document.addEventListener("mouseup",function(){s=!1,document.body.style.userSelect="",e.classList.remove("dragging")}),document.addEventListener("touchend",function(){s=!1,document.body.style.userSelect="",e.classList.remove("dragging")}),document.addEventListener("touchcancel",function(){s=!1,document.body.style.userSelect="",e.classList.remove("dragging")})):this._(`Can not drag! ${t?"":"moveMe"} ${t||e?"":"and "}${e?"":"iMoveThings "}was not found!`)}W(t){(0,console.info)(`${this.name}: ${t}`),this.R(this.$,"Status: "+t,!0)}_(t){(0,console.error)(`${this.name}: ${t}`),this.R(this.$,"Error: "+t,!0)}}(i,o),l=new class{constructor(){this.X=null,this.Y=null,this.q="bm-r",this.A="div#map canvas.maplibregl-canvas",this.V=null,this.J=""}Z(){if(document.body.contains(this.X))return this.X;document.getElementById(this.q)?.remove();const t=document.querySelector(this.A),e=document.createElement("canvas");return e.id=this.q,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.X=e,window.addEventListener("move",this.K),window.addEventListener("zoom",this.tt),window.addEventListener("resize",this.et),this.X}nt(t){this.V=t,this.J="file"}async st(t,e=[0,0,0,0]){if("file"!=this.J&&"template"!=this.J)return;const n=3e3;e=e?.length?e:[0,0,0,0],console.log(this.V);const s="template"==this.J?this.V:await createImageBitmap(await this.it(this.V)),i=await createImageBitmap(t),o=new OffscreenCanvas(n,n),a=o.getContext("2d");a.imageSmoothingEnabled=!1,a.beginPath(),a.rect(0,0,n,n),a.clip(),a.clearRect(0,0,n,n),a.drawImage(s,3*e[2],3*e[3]),a.drawImage(i,0,0,n,n);const c=await o.convertToBlob({type:"image/png"});if("template"!=this.J){this.V=s,this.J="template";const t=URL.createObjectURL(c);window.open(t,"_blank"),setTimeout(()=>URL.revokeObjectURL(t),1e4)}return c}async it(t,e=3,n="image/png"){const s=await createImageBitmap(t);e|=1;const i=s.width*Math.round(e),o=s.height*Math.round(e),a=document.createElement("canvas");a.width=i,a.height=o;const c=a.getContext("2d");c.imageSmoothingEnabled=!1,c.drawImage(s,0,0,i,o);const r=c.getImageData(0,0,i,o);for(let t=0;t{a.toBlob(t,n)})}},h=new class{constructor(t){this.ot=t,this.ct=!1,this.rt=[]}lt(t){window.addEventListener("message",async e=>{const n=e.data,s=n.jsonData;if(!n||"blue-marble"!==n.source)return;if(!n.endpoint)return;const i=n.endpoint?.split("?")[0].split("/").filter(t=>t&&isNaN(Number(t))).filter(t=>t&&!t.includes(".")).pop();switch(console.log(`%cBlue Marble%c: Recieved message about "${i}"`,"color: cornflowerblue;",""),i){case"me":if(s.status&&"2"!=s.status?.toString()[0])return void t._("The game is down!\nCould not fetch userdata.");const e=Math.ceil(Math.pow(Math.floor(s.level)*Math.pow(30,.65),1/.65)-s.pixelsPainted);t.R("bm-j",`Username: ${function(t){const e=document.createElement("div");return e.textContent=t,e.innerHTML}(s.name)}`),t.R("bm-f",`Droplets: ${(new Intl.NumberFormat).format(s.droplets)}`),t.R("bm-a",`Next level in ${(new Intl.NumberFormat).format(e)} pixel${1==e?"":"s"}`);break;case"pixel":const i=n.endpoint.split("?")[0].split("/").filter(t=>t&&!isNaN(Number(t))),c=new URLSearchParams(n.endpoint.split("?")[1]),r=[c.get("x"),c.get("y")];if(this.rt.length&&(!i.length||!r.length))return void t._("Coordinates are malformed!\nDid you try clicking the canvas first?");this.rt=[...i,...r];const l=(o=i,a=r,[parseInt(o[0])%4*1e3+parseInt(a[0]),parseInt(o[1])%4*1e3+parseInt(a[1])]),h=document.querySelectorAll("span");for(const t of h)if(t.textContent.trim().includes(`${l[0]}, ${l[1]}`)){let e=document.querySelector("#bm-9");const n=`(Tl X: ${i[0]}, Tl Y: ${i[1]}, Px X: ${r[0]}, Px Y: ${r[1]})`;e?e.textContent=n:(e=document.createElement("span"),e.id="bm-9",e.textContent=n,e.style="margin-left: calc(var(--spacing)*3); font-size: small;",t.parentNode.parentNode.parentNode.insertAdjacentElement("afterend",e))}break;case"tiles":let d=n.endpoint.split("/");d=[parseInt(d[d.length-2]),parseInt(d[d.length-1].replace(".png",""))];const m=n.blobID,u=n.blobData;let p=u;d[0]==this.rt[0]&&d[1]==this.rt[1]&&(console.log(`templateState: ${this.ot.J||null}`),p=this.ot.J?await this.ot.st(u,this.rt):u),window.postMessage({source:"blue-marble",blobID:m,blobData:p,blink:n.blink});break;case"robots":this.ct="false"==s.userscript?.toString().toLowerCase();break}var o,a})}}(l);r.M(h),r.k({id:"bm-p",style:"top: 10px; right: 75px;"}).k({id:"bm-b"}).k({id:"bm-k"}).S().D({alt:"Blue Marble Icon",src:"https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/dist/assets/Favicon.png"}).S().B(1,{textContent:i}).S().S().N().S().k({id:"bm-4"}).T({id:"bm-j",textContent:"Username:"}).S().T({id:"bm-f",textContent:"Droplets:"}).S().T({id:"bm-a",textContent:"Next level in..."}).S().S().N().S().k({id:"bm-3"}).P({id:"bm-g",textContent:"Stealth",checked:!0}).S().O({title:"Waits for the website to make requests, instead of sending requests."}).S().L().S().P({id:"bm-6",textContent:"Possessed",checked:!0}).S().O({title:"Controls the website as if it were possessed."}).S().L().S().k({id:"bm-c"}).H({id:"bm-h",className:"bm-t",style:"margin-top: 0;",innerHTML:''},(t,e)=>{e.onclick=()=>{const e=t.v?.rt;e?.[0]?(t.R("bm-l",e?.[0]||""),t.R("bm-m",e?.[1]||""),t.R("bm-n",e?.[2]||""),t.R("bm-o",e?.[3]||"")):t._("Coordinates are malformed! Did you try clicking on the canvas first?")}}).S().G({type:"number",id:"bm-l",placeholder:"Tl X",min:0,max:2047,step:1}).S().G({type:"number",id:"bm-m",placeholder:"Tl Y",min:0,max:2047,step:1}).S().G({type:"number",id:"bm-n",placeholder:"Px X",min:0,max:2047,step:1}).S().G({type:"number",id:"bm-o",placeholder:"Px Y",min:0,max:2047,step:1}).S().S().U({id:"bm-2",textContent:"Upload Template",accept:"image/png, image/jpeg, image/webp, image/bmp, image/gif"}).S().k({id:"bm-0"}).H({id:"bm-i",textContent:"Enable"},(t,e)=>{e.onclick=()=>{const e=document.querySelector("#bm-2");e?.files[0]?(l.nt(e.files[0]),t.W("Drew to canvas!")):t._("No file selected!")}}).S().H({id:"bm-d",textContent:"Disable"}).S().S().j({id:r.$,placeholder:`Status: Sleeping...\nVersion: ${o}`,readOnly:!0}).S().k({id:"bm-1"}).k().H({id:"bm-7",className:"bm-t",textContent:"✈"}).S().H({id:"bm-8",className:"bm-t",innerHTML:''}).S().H({id:"bm-5",className:"bm-t",innerHTML:"🖌"}).S().S().I({textContent:"Made by SwingTheVine",style:"margin-top: auto;"}).S().S().S().C(document.body),r.F("#bm-p","#bm-k"),h.lt(r),function(...t){(0,console.log)(...t)}(`%c${i}%c (${o}) userscript has loaded!`,"color: cornflowerblue;","")})(); \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 81f71d7..f0ffcb4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -35,7 +35,7 @@ Software License: MPL-2.0 Contact Me WakaTime -Total Patches +Total Patches Total Lines of Code Total Comments Compression diff --git a/package-lock.json b/package-lock.json index f35df87..07ddcfa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "wplace-bluemarble", - "version": "0.63.58", + "version": "0.63.68", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "wplace-bluemarble", - "version": "0.63.58", + "version": "0.63.68", "devDependencies": { "esbuild": "^0.25.0", "terser": "^5.43.1" diff --git a/package.json b/package.json index e972be7..c7647c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wplace-bluemarble", - "version": "0.63.58", + "version": "0.63.68", "type": "module", "scripts": { "build": "node build/build.js", diff --git a/src/BlueMarble.meta.js b/src/BlueMarble.meta.js index 87ccaa2..b7661c4 100644 --- a/src/BlueMarble.meta.js +++ b/src/BlueMarble.meta.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Blue Marble // @namespace https://github.com/SwingTheVine/ -// @version 0.63.58 +// @version 0.63.68 // @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 // @license MPL-2.0 diff --git a/src/apiManager.js b/src/apiManager.js index 555c7aa..73f77be 100644 --- a/src/apiManager.js +++ b/src/apiManager.js @@ -107,25 +107,20 @@ export default class ApiManager { case 'tiles': + // Runs only if the tile has the a template + let tileCoordsTile = data['endpoint'].split('/'); + tileCoordsTile = [parseInt(tileCoordsTile[tileCoordsTile.length - 2]), parseInt(tileCoordsTile[tileCoordsTile.length - 1].replace('.png', ''))]; + const blobUUID = data['blobID']; const blobData = data['blobData']; + let templateBlob = blobData; // By default, apply no template - // let templateBlob = blobData; // By default, apply no template + if ((tileCoordsTile[0] == this.coordsTilePixel[0]) && (tileCoordsTile[1] == this.coordsTilePixel[1])) { + + console.log(`templateState: ${this.templateManager.templateState || null}`); + templateBlob = !!this.templateManager.templateState ? await this.templateManager.drawTemplate(blobData, this.coordsTilePixel) : blobData; + } - console.log(`templateState: ${this.templateManager.templateState || null}`); - let templateBlob = !!this.templateManager.templateState ? await this.templateManager.drawTemplate(blobData) : blobData; - // Only apply the template if a template is loaded - // Otherwise, draw the template so the next attempted load will not need a re-draw - // switch (this.templateManager.templateState) { - // case 'file': // Draw the template - // console.log(`Attempting to draw template...`); - // templateBlob = await this.templateManager.drawTemplate(blobData); - // break; - // case 'template': // The template is already processed, pass it in - // templateBlob = this.templateManager.template; - // break; - // } - window.postMessage({ source: 'blue-marble', blobID: blobUUID, @@ -137,7 +132,6 @@ export default class ApiManager { case 'robots': // Request to retrieve what script types are allowed this.disableAll = dataJSON['userscript']?.toString().toLowerCase() == 'false'; // Disables Blue Marble if site owner wants userscripts disabled break; - } }); } diff --git a/src/templateManager.js b/src/templateManager.js index 66c49e8..ec2ef24 100644 --- a/src/templateManager.js +++ b/src/templateManager.js @@ -69,7 +69,13 @@ export default class TemplateManager { // setTimeout(() => URL.revokeObjectURL(url), 10000); // Destroys the blob 10 seconds later } - async drawTemplate(tileBlob) { + /** Draws the template on the tile. + * @param {File|Blob} tileBlob - The blob of the tile + * @param {Array} [coordsTilePixel=[0,0,0,0]] - A number array of the four coordinates + * @returns {File|Blob} A image/png blob file + * @since 0.63.59 + */ + async drawTemplate(tileBlob, coordsTilePixel=[0, 0, 0, 0]) { // Only continue if template state is NOT 'file' NOR 'template' if (!((this.templateState == 'file') || (this.templateState == 'template'))) {return;} @@ -78,13 +84,10 @@ export default class TemplateManager { const drawMult = 3; // Multiplier of draw size const drawSize = tileSize * drawMult; // Draw multiplier - // const [templateBitmap, tileBitmap] = await Promise.all([ - // createImageBitmap(await this.shrinkPixelsInPlace(this.template)), - // createImageBitmap(tileBlob) - // ]); + coordsTilePixel = !!coordsTilePixel?.length ? coordsTilePixel : [0, 0, 0, 0]; // Set to default if [] passed in - // If the template has already been drawn, don't draw it again console.log(this.template); + // If the template has already been drawn, don't draw it again const templateBitmap = this.templateState == 'template' ? this.template : await createImageBitmap(await this.shreadBlob(this.template)); const tileBitmap = await createImageBitmap(tileBlob); @@ -93,8 +96,13 @@ export default class TemplateManager { context.imageSmoothingEnabled = false; // Nearest neighbor + // Tells the canvas to ignore anything outside of this area + context.beginPath(); + context.rect(0, 0, drawSize, drawSize); + context.clip(); + context.clearRect(0, 0, drawSize, drawSize); // Draws transparent background - context.drawImage(templateBitmap, 0, 0); // TODO: Change X Y here + context.drawImage(templateBitmap, coordsTilePixel[2]*3, coordsTilePixel[3]*3); context.drawImage(tileBitmap, 0, 0, drawSize, drawSize); const final = await canvas.convertToBlob({ type: 'image/png' }); @@ -105,9 +113,9 @@ export default class TemplateManager { this.template = templateBitmap; // Store the drawn template this.templateState = 'template'; // Indicate that the template has been drawn - const url = URL.createObjectURL(final); // Creates a blob URL - window.open(url, '_blank'); // Opens a new tab with blob - setTimeout(() => URL.revokeObjectURL(url), 10000); // Destroys the blob 10 seconds later + // const url = URL.createObjectURL(final); // Creates a blob URL + // window.open(url, '_blank'); // Opens a new tab with blob + // setTimeout(() => URL.revokeObjectURL(url), 10000); // Destroys the blob 10 seconds later } return final;