mirror of
https://github.com/SwingTheVine/Wplace-BlueMarble.git
synced 2026-04-20 06:02:04 +00:00
Fixed spontaneousResponseListener for "pixel" fetches
This commit is contained in:
parent
f37565dd85
commit
5a3d09dcf3
8 changed files with 17 additions and 11 deletions
6
dist/BlueMarble.user.js
vendored
6
dist/BlueMarble.user.js
vendored
|
|
@ -1,7 +1,7 @@
|
|||
// ==UserScript==
|
||||
// @name Blue Marble
|
||||
// @namespace https://github.com/SwingTheVine/
|
||||
// @version 0.39.0
|
||||
// @version 0.39.2
|
||||
// @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,5 +20,5 @@
|
|||
// Wplace --> https://wplace.live
|
||||
// License --> https://www.mozilla.org/en-US/MPL/2.0/
|
||||
|
||||
(()=>{var h=class{constructor(o,t){this.name=o,this.version=t}create(){let o="bm-output-status",t=document.createElement("div");t.id="bm-overlay",t.style.top="10px",t.style.right="75px";let e=document.createElement("div");e.id="bm-contain-header";let n=document.createElement("div");n.id="bm-bar-drag",e.appendChild(n);let i=document.createElement("img");i.src="https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/src/assets/Favicon.png",i.alt="Blue Marble Icon",e.appendChild(i);let s=document.createElement("h1");s.textContent=this.name,e.appendChild(s);let c=document.createElement("div");c.id="bm-contain-userinfo";let f=document.createElement("p");f.id="bm-user-name",f.textContent="Username:",c.appendChild(f);let C=document.createElement("p");C.id="bm-user-droplets",C.textContent="Droplets:",c.appendChild(C);let g=document.createElement("p");g.id="bm-user-nextlevel",g.textContent="Next level in...",c.appendChild(g);let a=document.createElement("div");a.id="bm-contain-automation",a.appendChild(this.createInputCheckbox("Stealth","bm-input-stealth",!0)),a.appendChild(this.createButtonQuestion("bm-help-stealth","Help: Waits for the website to make requests, instead of sending requests.",o)),a.appendChild(document.createElement("br")),a.appendChild(this.createInputCheckbox("Possessed","bm-input-possessed",!0)),a.appendChild(this.createButtonQuestion("bm-help-possessed","Help: Controls the website as if it were possessed.",o)),a.appendChild(document.createElement("br")),a.appendChild(this.createInputCheckbox("Panic","bm-input-panic")),a.appendChild(this.createButtonQuestion("bm-help-panic","Help: Stops placing for a while if it detects a user nearby.",o)),a.appendChild(document.createElement("br"));let l=document.createElement("div");l.id="bm-contain-coords";let d=document.createElement("button");d.id="bm-button-coords",d.className="bm-help",d.style="margin-top: 0",d.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>',d.onclick=()=>{},l.appendChild(d),l.appendChild(this.createInputText("bm-input-tx","Tl X","","4")),l.appendChild(this.createInputText("bm-input-ty","Tl Y","","4")),l.appendChild(this.createInputText("bm-input-px","Px X","","4")),l.appendChild(this.createInputText("bm-input-py","Px Y","","4")),a.appendChild(l),a.appendChild(this.createInputFile("bm-input-file"));let p=document.createElement("div");p.id="bm-contain-buttons",p.appendChild(this.createButton("bm-button-start","Start")),p.appendChild(this.createButton("bm-button-pause","Pause",!1)),p.appendChild(this.createButton("bm-button-stop","Stop",!1)),a.appendChild(p);let m=document.createElement("textarea");m.id=o,m.readOnly=!0,m.placeholder=`Status: Sleeping...
|
||||
Version: ${this.version}`,a.appendChild(m),t.appendChild(e),t.appendChild(document.createElement("hr")),t.appendChild(c),t.appendChild(document.createElement("hr")),t.appendChild(a),document.body.appendChild(t),this.handleDrag(t,n)}updateInnerHTML(o,t,e=!1){let n=document.getElementById(o);if(n){if(n instanceof HTMLInputElement){n.value=t;return}e?n.textContent=t:n.innerHTML=t}}createButtonQuestion(o,t,e){let n=this.createButton(o,"?");return n.className="bm-help",n.title=t,n.onclick=()=>{this.updateInnerHTML(e,t)},n}createButton(o,t,e=!0){let n=document.createElement("button");return n.id=o,n.textContent=t,n.disabled=!e,n}createInputText(o,t="",e="",n="",i=!1){let s=document.createElement("input");return s.id=o,s.type="text",s.placeholder=t,s.value=e,s.readOnly=i,s.maxLength=n,s}createInputCheckbox(o,t,e=!1){let n=document.createElement("label");n.textContent=o;let i=document.createElement("input");return i.type="checkbox",i.id=t,i.checked=e,n.prepend(i),n}createInputFile(o){let t=document.createElement("div"),e=document.createElement("input");e.id=o,e.type="file",e.style="display: none";let n=document.createElement("button");return n.textContent="Upload File",n.addEventListener("click",()=>{e.click()}),e.addEventListener("change",()=>{n.style.maxWidth=`${n.offsetWidth}px`,e.files.length>0?n.textContent=e.files[0].name:n.textContent="Upload File"}),t.appendChild(e),t.appendChild(n),t}handleDrag(o,t){let e=!1,n,i=0;t.addEventListener("mousedown",function(s){e=!0,n=s.clientX-o.getBoundingClientRect().left,i=s.clientY-o.getBoundingClientRect().top,document.body.style.userSelect="none",t.classList.add("dragging")}),t.addEventListener("touchstart",function(s){e=!0;let c=s?.touches?.[0];c&&(n=c.clientX-o.getBoundingClientRect().left,i=c.clientY-o.getBoundingClientRect().top,document.body.style.userSelect="none",t.classList.add("dragging"))},{passive:!1}),document.addEventListener("mousemove",function(s){e&&(o.style.left=s.clientX-n+"px",o.style.top=s.clientY-i+"px",o.style.right="")}),document.addEventListener("touchmove",function(s){if(e){let c=s?.touches?.[0];if(!c)return;o.style.left=c.clientX-n+"px",o.style.top=c.clientY-i+"px",s.preventDefault()}},{passive:!1}),document.addEventListener("mouseup",function(){e=!1,document.body.style.userSelect="",t.classList.remove("dragging")}),document.addEventListener("touchend",function(){e=!1,document.body.style.userSelect="",t.classList.remove("dragging")}),document.addEventListener("touchcancel",function(){e=!1,document.body.style.userSelect="",t.classList.remove("dragging")})}};var b=class{constructor(){this.disableAll=!1}spontaneousResponseListener(o){window.addEventListener("message",t=>{let e=t.data;if(e&&e.source==="blue-marble")switch(e.endpoint){case"me":let n=Math.ceil(Math.pow(Math.floor(e.jsonData?.level)*Math.pow(30,.65),1.5384615384615383)-e.jsonData?.pixelsPainted);o.updateInnerHTML("bm-user-name",`Username: <b>${e.jsonData?.name}</b>`),o.updateInnerHTML("bm-user-droplets",`Droplets: <b>${new Intl.NumberFormat().format(e.jsonData?.droplets)}</b>`),o.updateInnerHTML("bm-user-nextlevel",`Next level in <b>${new Intl.NumberFormat().format(n)}</b> pixel${n==1?"":"s"}`);break;case"robots":this.disableAll=e.jsonData?.userscript?.toString().toLowerCase()=="false"}})}};var x=GM_info.script.name.toString(),E=GM_info.script.version.toString();function y(r){let o=document.createElement("script");o.textContent=`(${r})();`,document.documentElement.appendChild(o),o.remove()}y(()=>{let r=window.fetch;window.fetch=async function(...o){let t=await r.apply(this,o),e=t.clone();if((e.headers.get("content-type")||"").includes("application/json")){let i=(o[0]instanceof Request?o[0]?.url:o[0])||"ignore";i=i.split("/").filter(Boolean).pop()||"ignore",console.log(`Sending JSON message about endpoint "${i}"`),e.json().then(s=>{window.postMessage({source:"blue-marble",endpoint:i,jsonData:s},"*")}).catch(s=>{console.error("BM - Failed to parse JSON:",s)})}return t}});var w=GM_getResourceText("CSS-BM-File");GM_addStyle(w);var u=document.createElement("link");u.href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap";u.rel="preload";u.as="style";u.onload="this.onload=null;this.rel='stylesheet'";document.head.appendChild(u);var v=new h(x,E);v.create();var L=new b;L.spontaneousResponseListener(v);console.log(`${x} (${E}) userscript has loaded!`);})();
|
||||
(()=>{var h=class{constructor(o,t){this.name=o,this.version=t}create(){let o="bm-output-status",t=document.createElement("div");t.id="bm-overlay",t.style.top="10px",t.style.right="75px";let e=document.createElement("div");e.id="bm-contain-header";let n=document.createElement("div");n.id="bm-bar-drag",e.appendChild(n);let i=document.createElement("img");i.src="https://raw.githubusercontent.com/SwingTheVine/Wplace-BlueMarble/main/src/assets/Favicon.png",i.alt="Blue Marble Icon",e.appendChild(i);let s=document.createElement("h1");s.textContent=this.name,e.appendChild(s);let c=document.createElement("div");c.id="bm-contain-userinfo";let f=document.createElement("p");f.id="bm-user-name",f.textContent="Username:",c.appendChild(f);let C=document.createElement("p");C.id="bm-user-droplets",C.textContent="Droplets:",c.appendChild(C);let g=document.createElement("p");g.id="bm-user-nextlevel",g.textContent="Next level in...",c.appendChild(g);let a=document.createElement("div");a.id="bm-contain-automation",a.appendChild(this.createInputCheckbox("Stealth","bm-input-stealth",!0)),a.appendChild(this.createButtonQuestion("bm-help-stealth","Help: Waits for the website to make requests, instead of sending requests.",o)),a.appendChild(document.createElement("br")),a.appendChild(this.createInputCheckbox("Possessed","bm-input-possessed",!0)),a.appendChild(this.createButtonQuestion("bm-help-possessed","Help: Controls the website as if it were possessed.",o)),a.appendChild(document.createElement("br")),a.appendChild(this.createInputCheckbox("Panic","bm-input-panic")),a.appendChild(this.createButtonQuestion("bm-help-panic","Help: Stops placing for a while if it detects a user nearby.",o)),a.appendChild(document.createElement("br"));let l=document.createElement("div");l.id="bm-contain-coords";let d=document.createElement("button");d.id="bm-button-coords",d.className="bm-help",d.style="margin-top: 0",d.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>',d.onclick=()=>{},l.appendChild(d),l.appendChild(this.createInputText("bm-input-tx","Tl X","","4")),l.appendChild(this.createInputText("bm-input-ty","Tl Y","","4")),l.appendChild(this.createInputText("bm-input-px","Px X","","4")),l.appendChild(this.createInputText("bm-input-py","Px Y","","4")),a.appendChild(l),a.appendChild(this.createInputFile("bm-input-file"));let p=document.createElement("div");p.id="bm-contain-buttons",p.appendChild(this.createButton("bm-button-start","Start")),p.appendChild(this.createButton("bm-button-pause","Pause",!1)),p.appendChild(this.createButton("bm-button-stop","Stop")),a.appendChild(p);let m=document.createElement("textarea");m.id=o,m.readOnly=!0,m.placeholder=`Status: Sleeping...
|
||||
Version: ${this.version}`,a.appendChild(m),t.appendChild(e),t.appendChild(document.createElement("hr")),t.appendChild(c),t.appendChild(document.createElement("hr")),t.appendChild(a),document.body.appendChild(t),this.handleDrag(t,n)}updateInnerHTML(o,t,e=!1){let n=document.getElementById(o);if(n){if(n instanceof HTMLInputElement){n.value=t;return}e?n.textContent=t:n.innerHTML=t}}createButtonQuestion(o,t,e){let n=this.createButton(o,"?");return n.className="bm-help",n.title=t,n.onclick=()=>{this.updateInnerHTML(e,t)},n}createButton(o,t,e=!0){let n=document.createElement("button");return n.id=o,n.textContent=t,n.disabled=!e,n}createInputText(o,t="",e="",n="",i=!1){let s=document.createElement("input");return s.id=o,s.type="text",s.placeholder=t,s.value=e,s.readOnly=i,s.maxLength=n,s}createInputCheckbox(o,t,e=!1){let n=document.createElement("label");n.textContent=o;let i=document.createElement("input");return i.type="checkbox",i.id=t,i.checked=e,n.prepend(i),n}createInputFile(o){let t=document.createElement("div"),e=document.createElement("input");e.id=o,e.type="file",e.style="display: none";let n=document.createElement("button");return n.textContent="Upload File",n.addEventListener("click",()=>{e.click()}),e.addEventListener("change",()=>{n.style.maxWidth=`${n.offsetWidth}px`,e.files.length>0?n.textContent=e.files[0].name:n.textContent="Upload File"}),t.appendChild(e),t.appendChild(n),t}handleDrag(o,t){let e=!1,n,i=0;t.addEventListener("mousedown",function(s){e=!0,n=s.clientX-o.getBoundingClientRect().left,i=s.clientY-o.getBoundingClientRect().top,document.body.style.userSelect="none",t.classList.add("dragging")}),t.addEventListener("touchstart",function(s){e=!0;let c=s?.touches?.[0];c&&(n=c.clientX-o.getBoundingClientRect().left,i=c.clientY-o.getBoundingClientRect().top,document.body.style.userSelect="none",t.classList.add("dragging"))},{passive:!1}),document.addEventListener("mousemove",function(s){e&&(o.style.left=s.clientX-n+"px",o.style.top=s.clientY-i+"px",o.style.right="")}),document.addEventListener("touchmove",function(s){if(e){let c=s?.touches?.[0];if(!c)return;o.style.left=c.clientX-n+"px",o.style.top=c.clientY-i+"px",s.preventDefault()}},{passive:!1}),document.addEventListener("mouseup",function(){e=!1,document.body.style.userSelect="",t.classList.remove("dragging")}),document.addEventListener("touchend",function(){e=!1,document.body.style.userSelect="",t.classList.remove("dragging")}),document.addEventListener("touchcancel",function(){e=!1,document.body.style.userSelect="",t.classList.remove("dragging")})}};var b=class{constructor(){this.disableAll=!1}spontaneousResponseListener(o){window.addEventListener("message",t=>{let e=t.data;if(!(e&&e.source==="blue-marble"))return;let n=e.endpoint.split("?")[0].split("/").filter(i=>i&&isNaN(Number(i))).pop();switch(console.log(`Recieved message about "${n}"`),n){case"me":let i=Math.ceil(Math.pow(Math.floor(e.jsonData?.level)*Math.pow(30,.65),1.5384615384615383)-e.jsonData?.pixelsPainted);o.updateInnerHTML("bm-user-name",`Username: <b>${e.jsonData?.name}</b>`),o.updateInnerHTML("bm-user-droplets",`Droplets: <b>${new Intl.NumberFormat().format(e.jsonData?.droplets)}</b>`),o.updateInnerHTML("bm-user-nextlevel",`Next level in <b>${new Intl.NumberFormat().format(i)}</b> pixel${i==1?"":"s"}`);break;case"robots":this.disableAll=e.jsonData?.userscript?.toString().toLowerCase()=="false"}})}};var x=GM_info.script.name.toString(),E=GM_info.script.version.toString();function y(r){let o=document.createElement("script");o.textContent=`(${r})();`,document.documentElement.appendChild(o),o.remove()}y(()=>{let r=window.fetch;window.fetch=async function(...o){let t=await r.apply(this,o),e=t.clone();if((e.headers.get("content-type")||"").includes("application/json")){let i=(o[0]instanceof Request?o[0]?.url:o[0])||"ignore";console.log(`Sending JSON message about endpoint "${i}"`),e.json().then(s=>{window.postMessage({source:"blue-marble",endpoint:i,jsonData:s},"*")}).catch(s=>{console.error("BM - Failed to parse JSON:",s)})}return t}});var w=GM_getResourceText("CSS-BM-File");GM_addStyle(w);var u=document.createElement("link");u.href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap";u.rel="preload";u.as="style";u.onload="this.onload=null;this.rel='stylesheet'";document.head.appendChild(u);var v=new h(x,E);v.create();var L=new b;L.spontaneousResponseListener(v);console.log(`${x} (${E}) userscript has loaded!`);})();
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
<a href="https://github.com/SwingTheVine/Wplace-BlueMarble/blob/main/LICENSE.txt" target="_blank"><img alt="Software License: MPL-2.0" src="https://img.shields.io/badge/Software_License-MPL--2.0-brightgreen?style=flat"></a>
|
||||
<a href="https://discord.gg/tpeBPy46hf" target="_blank"><img alt="Contact Me" src="https://img.shields.io/badge/Contact_Me-gray?style=flat&logo=Discord&logoColor=white&logoSize=auto&labelColor=cornflowerblue"></a>
|
||||
<a href="" target="_blank"><img alt="WakaTime" src="https://img.shields.io/badge/Coding_Time-10hrs_0mins-blue?style=flat&logo=wakatime&logoColor=black&logoSize=auto&labelColor=white"></a>
|
||||
<a href="" target="_blank"><img alt="Total Patches" src="https://img.shields.io/badge/Total_Patches-79-black?style=flat"></a>
|
||||
<a href="" target="_blank"><img alt="Total Patches" src="https://img.shields.io/badge/Total_Patches-81-black?style=flat"></a>
|
||||
<a href="" target="_blank"><img alt="Total Lines of Code" src="https://tokei.rs/b1/github/SwingTheVine/Wplace-BlueMarble?category=code"></a>
|
||||
<a href="" target="_blank"><img alt="Total Comments" src="https://tokei.rs/b1/github/SwingTheVine/Wplace-BlueMarble?category=comments"></a>
|
||||
<a href="" target="_blank"><img alt="Build" src="https://github.com/SwingTheVine/Wplace-BlueMarble/actions/workflows/build.yml/badge.svg"></a>
|
||||
|
|
|
|||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -7,7 +7,7 @@
|
|||
"devDependencies": {
|
||||
"esbuild": "^0.25.0"
|
||||
},
|
||||
"version": "0.36.2"
|
||||
"version": "0.39.2"
|
||||
},
|
||||
"node_modules/@esbuild/aix-ppc64": {
|
||||
"version": "0.25.8",
|
||||
|
|
@ -467,5 +467,5 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"version": "0.36.2"
|
||||
"version": "0.39.2"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "wplace-bluemarble",
|
||||
"version": "0.39.0",
|
||||
"version": "0.39.2",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "node build/build.js",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// ==UserScript==
|
||||
// @name Blue Marble
|
||||
// @namespace https://github.com/SwingTheVine/
|
||||
// @version 0.39.0
|
||||
// @version 0.39.2
|
||||
// @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
|
||||
|
|
|
|||
|
|
@ -26,9 +26,15 @@ export class ApiHandler {
|
|||
// Kills itself if the message was not intended for Blue Marble
|
||||
if (!(data && data.source === 'blue-marble')) {return;}
|
||||
|
||||
// Trims endpoint to the second to last non-number, non-null directoy.
|
||||
// E.g. "wplace.live/api/pixel/0/0?payload" -> "pixel"
|
||||
const endpointText = data.endpoint.split('?')[0].split('/').filter(s => s && isNaN(Number(s))).pop();
|
||||
|
||||
console.log(`Recieved message about "${endpointText}"`);
|
||||
|
||||
// Each case is something that Blue Marble can use from the fetch.
|
||||
// For instance, if the fetch was for "me", we can update the overlay stats
|
||||
switch (data.endpoint) {
|
||||
switch (endpointText) {
|
||||
case 'me':
|
||||
const nextLevelPixels = Math.ceil(Math.pow(Math.floor(data.jsonData?.level) * Math.pow(30, 0.65), (1/0.65)) - data.jsonData?.pixelsPainted); // Calculates pixels to the next level
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ inject(() => {
|
|||
|
||||
// Retrieves the endpoint name. Unknown endpoint = "ignore"
|
||||
let endpointName = ((args[0] instanceof Request) ? args[0]?.url : args[0]) || 'ignore';
|
||||
endpointName = endpointName.split('/').filter(Boolean).pop() || 'ignore';
|
||||
//endpointName = endpointName.split('/').filter(Boolean).pop() || 'ignore';
|
||||
|
||||
console.log(`Sending JSON message about endpoint "${endpointName}"`);
|
||||
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ export class Overlay {
|
|||
// Button array for bot
|
||||
containerAutomationButtons.appendChild(this.createButton('bm-button-start', 'Start'));
|
||||
containerAutomationButtons.appendChild(this.createButton('bm-button-pause', 'Pause', false));
|
||||
containerAutomationButtons.appendChild(this.createButton('bm-button-stop', 'Stop', false));
|
||||
containerAutomationButtons.appendChild(this.createButton('bm-button-stop', 'Stop'));
|
||||
|
||||
containerAutomation.appendChild(containerAutomationButtons); // Adds button container to automation container
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue