mirror of
https://github.com/SwingTheVine/Wplace-BlueMarble.git
synced 2026-03-11 17:15:38 +00:00
Fixed obfuscation bugs in build.js
This commit is contained in:
parent
0fd6b73b6d
commit
884c4ea018
11 changed files with 211 additions and 42 deletions
|
|
@ -1,14 +1,24 @@
|
|||
/** Builds the userscript using esbuild.
|
||||
* This is for compiling all of the source files into a single userscript file.
|
||||
* This also compiles all CSS files into a single CSS file.
|
||||
* This will:
|
||||
* 1. Update the package version across the entire project
|
||||
* 2. Bundle the JS files into one file
|
||||
* 3. Bundle the CSS files into one file
|
||||
* 4. Compress & obfuscate the bundled JS file
|
||||
* 5. Create a sourcemap
|
||||
* @since 0.0.6
|
||||
*/
|
||||
|
||||
// ES Module imports
|
||||
import esbuild from 'esbuild';
|
||||
import fs from 'fs';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
// Tries to bump the minor version
|
||||
import { createRequire } from 'module';
|
||||
const require = createRequire(import.meta.url);
|
||||
// CommonJS imports (require)
|
||||
const terser = require('terser');
|
||||
|
||||
// Tries to bump the version
|
||||
try {
|
||||
const update = execSync('node build/update-version.js', { stdio: 'inherit' });
|
||||
console.log('Version updated in meta file successfully');
|
||||
|
|
@ -34,14 +44,55 @@ esbuild.build({
|
|||
});
|
||||
|
||||
// Compiles the JS files
|
||||
esbuild.build({
|
||||
entryPoints: ['src/main.js'],
|
||||
bundle: true,
|
||||
outfile: 'dist/BlueMarble.user.js',
|
||||
format: 'iife',
|
||||
banner: {
|
||||
js: metaContent
|
||||
},
|
||||
legalComments: 'inline',
|
||||
minify: true
|
||||
const resultEsbuild = await esbuild.build({
|
||||
entryPoints: ['src/main.js'], // "Infect" the files from this point (it spreads from this "patient 0")
|
||||
bundle: true, // Should the code be bundled?
|
||||
outfile: 'dist/BlueMarble.user.js', // The file the bundled code is exported to
|
||||
format: 'iife', // What format the bundler bundles the code into
|
||||
drop: process.env?.GITHUB_ACTIONS ? ['console', 'debugger'] : [], // Tells esbuild to remove console and debug logs if this file is run in a GitHub (Actions) Workflow
|
||||
target: 'es2020', // What is the minimum version/year that should be supported? When omited, it attempts to support backwards compatability with legacy browsers
|
||||
platform: 'browser', // The platform the bundled code will be operating on
|
||||
sourcemap: true, // Should a sourcemap be generated?
|
||||
legalComments: 'inline', // What level of legal comments are preserved? (Hard: none, Soft: inline)
|
||||
minify: false, // Should the code be minified?
|
||||
write: false // Should we write the outfile?
|
||||
}).catch(() => process.exit(1));
|
||||
|
||||
// Retrieves the JS file and map file
|
||||
const resultEsbuildJS = resultEsbuild.outputFiles.find(file => file.path.endsWith('.js'));
|
||||
const resultEsbuildMap = resultEsbuild.outputFiles.find(file => file.path.endsWith('.js.map'));
|
||||
|
||||
// Obfuscates the JS file
|
||||
const resultTerser = await terser.minify(resultEsbuildJS.text, {
|
||||
sourceMap: {
|
||||
content: resultEsbuildMap.text, // esbuild sourcemap
|
||||
filename: 'dist/BlueMarble.user.js', // The file to make a sourcemap for
|
||||
url: 'dist/BlueMarble.user.js.map' // The sourcemap to be made
|
||||
},
|
||||
mangle: {
|
||||
toplevel: true, // Obfuscate top-level class/function names
|
||||
keep_classnames: false, // Should class names be preserved?
|
||||
keep_fnames: false, // Should function names be preserved?
|
||||
reserved: [], // List of keywords to preserve
|
||||
properties: {
|
||||
// regex: /.*/, // Yes, I am aware I should be using a RegEx. Yes, like you, I am also suprised the userscript still functions
|
||||
keep_quoted: true, // Should names in quotes be preserved?
|
||||
reserved: [] // What properties should be preserved?
|
||||
},
|
||||
},
|
||||
compress: {
|
||||
dead_code: true, // Should unreachable code be removed?
|
||||
drop_console: true, // Should console code be removed?
|
||||
drop_debugger: true, // SHould debugger code be removed?
|
||||
passes: 2 // Number of times the compression algorithm runs
|
||||
},
|
||||
format: {
|
||||
comments: 'some' // Save legal comments
|
||||
}
|
||||
});
|
||||
|
||||
// Creates the sourcemap file
|
||||
fs.writeFileSync('dist/BlueMarble.user.js.map', resultTerser.map, 'utf8');
|
||||
|
||||
// Adds the banner
|
||||
fs.writeFileSync('dist/BlueMarble.user.js', metaContent + resultTerser.code, 'utf8');
|
||||
2
dist/BlueMarble.user.css
vendored
2
dist/BlueMarble.user.css
vendored
|
|
@ -1 +1 @@
|
|||
#bm-overlay{position:fixed;background-color:#153063e6;color:#fff;padding:10px;border-radius:8px;z-index:9000}div#bm-overlay{font-family:Roboto Mono,Courier New,Monaco,DejaVu Sans Mono,monospace,Arial;letter-spacing:.05em}#bm-bar-drag{margin-bottom:.5em;background:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="5" height="5"><circle cx="3" cy="3" r="1.5" fill="CornflowerBlue" /></svg>') repeat;cursor:grab;width:100%;height:1em}#bm-bar-drag.dragging{cursor:grabbing}#bm-contain-header{margin-bottom:.5em}#bm-overlay img{display:inline-block;height:2.5em;margin-right:1ch;vertical-align:middle}#bm-overlay h1{display:inline-block;font-size:x-large;font-weight:700;vertical-align:middle}#bm-contain-automation input[type=checkbox]{vertical-align:middle;margin-right:.5ch}#bm-contain-automation label{margin-right:.5ch}.bm-help{border:white 1px solid;height:1.25em;width:1.25em;margin-top:2px;text-align:center;line-height:1.25em;padding:0!important}#bm-button-coords{vertical-align:middle}#bm-button-coords svg{width:50%;margin:0 auto;fill:#111}#bm-contain-coords input[type=number]{appearance:auto;-moz-appearance:textfield;width:5.5ch;margin-left:1ch;background-color:#0003;padding:0 .5ch;font-size:small}#bm-contain-coords input[type=number]::-webkit-outer-spin-button,#bm-contain-coords input[type=number]::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}#bm-contain-buttons{display:flex;flex-direction:row;flex-wrap:wrap;align-content:center;justify-content:center;align-items:center;gap:1ch}div:has(>#bm-input-file-template)>button{width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}#bm-output-status{font-size:small;background-color:#0003;padding:0 .5ch;height:3.75em;width:100%}#bm-contain-userinfo,#bm-contain-automation,#bm-contain-coords,#bm-contain-buttons,div:has(>#bm-input-file-template),#bm-output-status{margin-top:.5em}#bm-overlay button{background-color:#144eb9;border-radius:1em;padding:0 .75ch}#bm-overlay button:hover,#bm-overlay button:focus-visible{background-color:#1061e5}#bm-overlay button:active,#bm-overlay button:disabled{background-color:#2e97ff}#bm-overlay button:disabled{text-decoration:line-through}
|
||||
#bm-overlay{position:fixed;background-color:#153063e6;color:#fff;padding:10px;border-radius:8px;z-index:9000}div#bm-overlay{font-family:Roboto Mono,Courier New,Monaco,DejaVu Sans Mono,monospace,Arial;letter-spacing:.05em}#bm-bar-drag{margin-bottom:.5em;background:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="5" height="5"><circle cx="3" cy="3" r="1.5" fill="CornflowerBlue" /></svg>') repeat;cursor:grab;width:100%;height:1em}#bm-bar-drag.dragging{cursor:grabbing}#bm-contain-header{margin-bottom:.5em}#bm-overlay img{display:inline-block;height:2.5em;margin-right:1ch;vertical-align:middle}#bm-overlay h1{display:inline-block;font-size:x-large;font-weight:700;vertical-align:middle}#bm-contain-automation input[type=checkbox]{vertical-align:middle;margin-right:.5ch}#bm-contain-automation label{margin-right:.5ch}.bm-help{border:white 1px solid;height:1.5em;width:1.5em;margin-top:2px;text-align:center;line-height:1em;padding:0!important}#bm-button-coords{vertical-align:middle}#bm-button-coords svg{width:50%;margin:0 auto;fill:#111}#bm-contain-coords input[type=number]{appearance:auto;-moz-appearance:textfield;width:5.5ch;margin-left:1ch;background-color:#0003;padding:0 .5ch;font-size:small}#bm-contain-coords input[type=number]::-webkit-outer-spin-button,#bm-contain-coords input[type=number]::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}#bm-contain-buttons{display:flex;flex-direction:row;flex-wrap:wrap;align-content:center;justify-content:center;align-items:center;gap:1ch}div:has(>#bm-input-file-template)>button{width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}#bm-output-status{font-size:small;background-color:#0003;padding:0 .5ch;height:3.75em;width:100%}#bm-contain-userinfo,#bm-contain-automation,#bm-contain-coords,#bm-contain-buttons,div:has(>#bm-input-file-template),#bm-output-status{margin-top:.5em}#bm-overlay button{background-color:#144eb9;border-radius:1em;padding:0 .75ch}#bm-overlay button:hover,#bm-overlay button:focus-visible{background-color:#1061e5}#bm-overlay button:active,#bm-overlay button:disabled{background-color:#2e97ff}#bm-overlay button:disabled{text-decoration:line-through}
|
||||
|
|
|
|||
7
dist/BlueMarble.user.js
vendored
7
dist/BlueMarble.user.js
vendored
File diff suppressed because one or more lines are too long
1
dist/BlueMarble.user.js.map
vendored
Normal file
1
dist/BlueMarble.user.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -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-35hrs_30mins-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-152-black?style=flat"></a>
|
||||
<a href="" target="_blank"><img alt="Total Patches" src="https://img.shields.io/badge/Total_Patches-178-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>
|
||||
|
|
|
|||
120
package-lock.json
generated
120
package-lock.json
generated
|
|
@ -1,13 +1,16 @@
|
|||
{
|
||||
"name": "Wplace-BlueMarble",
|
||||
"name": "wplace-bluemarble",
|
||||
"version": "0.46.26",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wplace-bluemarble",
|
||||
"version": "0.46.26",
|
||||
"devDependencies": {
|
||||
"esbuild": "^0.25.0"
|
||||
},
|
||||
"version": "0.44.4"
|
||||
"esbuild": "^0.25.0",
|
||||
"terser": "^5.43.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/aix-ppc64": {
|
||||
"version": "0.25.8",
|
||||
|
|
@ -425,6 +428,75 @@
|
|||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/@jridgewell/gen-mapping": {
|
||||
"version": "0.3.12",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.12.tgz",
|
||||
"integrity": "sha512-OuLGC46TjB5BbN1dH8JULVVZY4WTdkF7tV9Ys6wLL1rubZnCMstOhNHueU5bLCrnRuDhKPDM4g6sw4Bel5Gzqg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@jridgewell/sourcemap-codec": "^1.5.0",
|
||||
"@jridgewell/trace-mapping": "^0.3.24"
|
||||
}
|
||||
},
|
||||
"node_modules/@jridgewell/resolve-uri": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz",
|
||||
"integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@jridgewell/source-map": {
|
||||
"version": "0.3.10",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.10.tgz",
|
||||
"integrity": "sha512-0pPkgz9dY+bijgistcTTJ5mR+ocqRXLuhXHYdzoMmmoJ2C9S46RCm2GMUbatPEUK9Yjy26IrAy8D/M00lLkv+Q==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@jridgewell/gen-mapping": "^0.3.5",
|
||||
"@jridgewell/trace-mapping": "^0.3.25"
|
||||
}
|
||||
},
|
||||
"node_modules/@jridgewell/sourcemap-codec": {
|
||||
"version": "1.5.4",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.4.tgz",
|
||||
"integrity": "sha512-VT2+G1VQs/9oz078bLrYbecdZKs912zQlkelYpuf+SXF+QvZDYJlbx/LSx+meSAwdDFnF8FVXW92AVjjkVmgFw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@jridgewell/trace-mapping": {
|
||||
"version": "0.3.29",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.29.tgz",
|
||||
"integrity": "sha512-uw6guiW/gcAGPDhLmd77/6lW8QLeiV5RUTsAX46Db6oLhGaVj4lhnPwb184s1bkc8kdVg/+h988dro8GRDpmYQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@jridgewell/resolve-uri": "^3.1.0",
|
||||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||
}
|
||||
},
|
||||
"node_modules/acorn": {
|
||||
"version": "8.15.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz",
|
||||
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer-from": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
|
||||
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/commander": {
|
||||
"version": "2.20.3",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
|
||||
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.8.tgz",
|
||||
|
|
@ -465,7 +537,43 @@
|
|||
"@esbuild/win32-ia32": "0.25.8",
|
||||
"@esbuild/win32-x64": "0.25.8"
|
||||
}
|
||||
},
|
||||
"node_modules/source-map": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/source-map-support": {
|
||||
"version": "0.5.21",
|
||||
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz",
|
||||
"integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"buffer-from": "^1.0.0",
|
||||
"source-map": "^0.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/terser": {
|
||||
"version": "5.43.1",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-5.43.1.tgz",
|
||||
"integrity": "sha512-+6erLbBm0+LROX2sPXlUYx/ux5PyE9K/a92Wrt6oA+WDAoFTdpHE5tCYCI5PNzq2y8df4rA+QgHLJuR4jNymsg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@jridgewell/source-map": "^0.3.3",
|
||||
"acorn": "^8.14.0",
|
||||
"commander": "^2.20.0",
|
||||
"source-map-support": "~0.5.20"
|
||||
},
|
||||
"bin": {
|
||||
"terser": "bin/terser"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
}
|
||||
},
|
||||
"version": "0.44.4"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
{
|
||||
"name": "wplace-bluemarble",
|
||||
"version": "0.46.0",
|
||||
"version": "0.46.26",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "node build/build.js",
|
||||
"patch": "node build/patch.js && npm run build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"esbuild": "^0.25.0"
|
||||
"esbuild": "^0.25.0",
|
||||
"terser": "^5.43.1"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// ==UserScript==
|
||||
// @name Blue Marble
|
||||
// @namespace https://github.com/SwingTheVine/
|
||||
// @version 0.46.0
|
||||
// @version 0.46.26
|
||||
// @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
|
||||
|
|
@ -19,3 +19,4 @@
|
|||
|
||||
// Wplace --> https://wplace.live
|
||||
// License --> https://www.mozilla.org/en-US/MPL/2.0/
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ export default class ApiHandler {
|
|||
|
||||
/** Determines if the spontaneously recieved response is something we want.
|
||||
* Otherwise, we can ignore it.
|
||||
* Note: Due to aggressive compression, make your calls like `data['jsonData']['name']` instead of `data.jsonData.name`
|
||||
*
|
||||
* @param {Overlay} overlay - The Overlay class instance
|
||||
* @since 0.11.1
|
||||
*/
|
||||
|
|
@ -28,13 +30,14 @@ export default class ApiHandler {
|
|||
window.addEventListener('message', (event) => {
|
||||
|
||||
const data = event.data; // The data of the message
|
||||
const dataJSON = data['jsonData']; // The JSON response, if any
|
||||
|
||||
// Kills itself if the message was not intended for Blue Marble
|
||||
if (!(data && data.source === 'blue-marble')) {return;}
|
||||
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();
|
||||
const endpointText = data['endpoint'].split('?')[0].split('/').filter(s => s && isNaN(Number(s))).pop();
|
||||
|
||||
console.log(`Recieved message about "${endpointText}"`);
|
||||
|
||||
|
|
@ -45,23 +48,27 @@ export default class ApiHandler {
|
|||
case 'me': // Request to retrieve user data
|
||||
|
||||
// If the game can not retrieve the userdata...
|
||||
if (data.jsonData?.status && data.jsonData?.status?.toString()[0] != '2') {
|
||||
if (dataJSON['status'] && dataJSON['status']?.toString()[0] != '2') {
|
||||
// The server is probably down (NOT a 2xx status)
|
||||
|
||||
overlay.handleDisplayError(`The game is down!\nCould not fetch userdata.`);
|
||||
return; // Kills itself before attempting to display null userdata
|
||||
}
|
||||
|
||||
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
|
||||
const nextLevelPixels = Math.ceil(Math.pow(Math.floor(dataJSON['level']) * Math.pow(30, 0.65), (1/0.65)) - dataJSON['pixelsPainted']); // Calculates pixels to the next level
|
||||
|
||||
overlay.updateInnerHTML('bm-user-name', `Username: <b>${Utils.escapeHTML(data.jsonData?.name)}</b>`); // Updates the text content of the username field
|
||||
overlay.updateInnerHTML('bm-user-droplets', `Droplets: <b>${new Intl.NumberFormat().format(data.jsonData?.droplets)}</b>`); // Updates the text content of the droplets field
|
||||
const clog = console.log;
|
||||
clog(dataJSON);
|
||||
clog(dataJSON?.droplets);
|
||||
|
||||
overlay.updateInnerHTML('bm-user-name', `Username: <b>${Utils.escapeHTML(dataJSON['name'])}</b>`); // Updates the text content of the username field
|
||||
overlay.updateInnerHTML('bm-user-droplets', `Droplets: <b>${new Intl.NumberFormat().format(dataJSON['droplets'])}</b>`); // Updates the text content of the droplets field
|
||||
overlay.updateInnerHTML('bm-user-nextlevel', `Next level in <b>${new Intl.NumberFormat().format(nextLevelPixels)}</b> pixel${nextLevelPixels == 1 ? '' : 's'}`); // Updates the text content of the next level field
|
||||
break;
|
||||
|
||||
case 'pixel': // Request to retrieve pixel data
|
||||
const coordsTile = data.endpoint.split('?')[0].split('/').filter(s => s && !isNaN(Number(s))); // Retrieves the tile coords as [x, y]
|
||||
const payloadExtractor = new URLSearchParams(data.endpoint.split('?')[1]); // Declares a new payload deconstructor and passes in the fetch request payload
|
||||
const coordsTile = data['endpoint'].split('?')[0].split('/').filter(s => s && !isNaN(Number(s))); // Retrieves the tile coords as [x, y]
|
||||
const payloadExtractor = new URLSearchParams(data['endpoint'].split('?')[1]); // Declares a new payload deconstructor and passes in the fetch request payload
|
||||
const coordsPixel = [payloadExtractor.get('x'), payloadExtractor.get('y')]; // Retrieves the deconstructed pixel coords from the payload
|
||||
this.coordsTilePixel = [...coordsTile, ...coordsPixel]; // Combines the two arrays such that [x, y, x, y]
|
||||
const displayTP = this.coordsHandler.serverTPtoDisplayTP(coordsTile, coordsPixel);
|
||||
|
|
@ -91,7 +98,7 @@ export default class ApiHandler {
|
|||
break;
|
||||
|
||||
case 'robots': // Request to retrieve what script types are allowed
|
||||
this.disableAll = data.jsonData?.userscript?.toString().toLowerCase() == 'false'; // Disables Blue Marble if site owner wants userscripts disabled
|
||||
this.disableAll = dataJSON['userscript']?.toString().toLowerCase() == 'false'; // Disables Blue Marble if site owner wants userscripts disabled
|
||||
break;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,11 +73,11 @@ div#bm-overlay {
|
|||
/* Question Mark button */
|
||||
.bm-help {
|
||||
border: white 1px solid;
|
||||
height: 1.25em;
|
||||
width: 1.25em;
|
||||
height: 1.5em;
|
||||
width: 1.5em;
|
||||
margin-top: 2px;
|
||||
text-align: center;
|
||||
line-height: 1.25em;
|
||||
line-height: 1em;
|
||||
padding: 0 !important; /* Overrides the padding in "#bm-overlay button" */
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -591,7 +591,8 @@ export default class Overlay {
|
|||
* @since 0.41.6
|
||||
*/
|
||||
handleDisplayError(text) {
|
||||
console.error(`${this.name}: ${text}`); // Outputs something like "ScriptName: text" as an error to the console
|
||||
const consoleError = console.error; // Idk anymore...
|
||||
consoleError(`${this.name}: ${text}`); // Outputs something like "ScriptName: text" as an error to the console
|
||||
this.updateInnerHTML(this.outputStatusId, 'Error: ' + text, true);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue