That's no problem at all: I can provide you with destructive feedback if you would prefer that.(not sure I'm ready for constructive feedback).

That's no problem at all: I can provide you with destructive feedback if you would prefer that.(not sure I'm ready for constructive feedback).
That's kind of what I'm afraid ofrichmond62 wrote: ↑Wed Mar 19, 2025 2:46 pm That's no problem at all: I can provide you with destructive feedback if you would prefer that.![]()
Code: Select all
beep
Code: Select all
beep [number]
Code: Select all
// Handle load file command
if (script.startsWith('load ')) {
const expr = script.substring(5);
if (expr.startsWith('file'))
{
const theParam = expr.substring(5);
let element = document.getElementById('inputData');
if (element) {
console.log('File Input element does already exist!');
let result = inputData.click();
// Element exists, proceed with operations
let fileInput = document.getElementById('inputData').files[0];
console.log(fileInput);
fileInput = document.getElementById('inputData').files[0];
} else {
console.log('File Input element does not exist, creating it...');
// <input type="file" id="inputData" name="fileInput" accept="text/*">
const oxtInputFileDiv = document.createElement('div');
oxtInputFileDiv.setAttribute('style','display:none');
const inFileForm = document.createElement('form');
const inFileInput = document.createElement('input');
inFileInput.setAttribute('id','inputData');
inFileInput.setAttribute('type','file');
inFileInput.setAttribute('accept','text/*');
inFileForm.appendChild(inFileInput);
oxtInputFileDiv.appendChild(inFileForm);
document.body.appendChild(oxtInputFileDiv);
let result = inputData.click();
let fileInput = document.getElementById('inputData').files[0];
//const fileInput = document.getElementById('inputData');
// console.log( fileInput.files[0] );
}
let fileInput = document.getElementById('inputData').files[0];
console.log( fileInput );
// Read the file
let reader = new FileReader(fileInput);
reader.onloadend = () => {
this.it = reader.result;
console.log(reader.result);
// return this.it;
};
reader.onerror = () => {
showMessage("Error reading the file. Please try again.", "error");
};
let tResult = reader.readAsText( fileInput );
// const tResult = reader.readAsText( theFile,'UTF-8');
this.it = reader.result;
}
return this.it;
}
Code: Select all
load file
wait 1 -- give it a little time to load the file data
put it
This is essential if you want to localize your stacks into another language. The buttons and fields may change names but the ID will always be the same and work the same not matter what.I did extensive testing as I was trying to confuse it, but seems to pass all these tests:
See this is where something like an Electron web app-to-desktop app wrapper is needed. Electron has it's own file reading 'fs' (FileSystem) API that can be used which provides more traditional desktop app style file system access, like listing directories and like incremental reads writes to disks. The web file reader APIs doesn't do that stuff for security reasons. You get back file reference objects which have properties filled in with details about the file, but it's not a file, the API uses it to read in it's bytes from disk into memory before you can access any data from the file that it points to. It is a bit like a symbolic link I guess, or maybe a bit more like a File reference object seen in some other programming languages such as Objective C. The underlying disk I/O methods are opaque, abstracted away from calling code. What you get back with the file input method here is a FileList-array of File objects (https://developer.mozilla.org/en-US/docs/Web/API/File) which have details like name, byte size, MIME type, so then you pass these file-objects to the file reader to slurp up some data from the BLOB, it may be media such as an image format, and one can have it returned as the raw binary data, or text, or base64 encoded into a DataURL string for doing things with it.tperry2x wrote: ↑Wed Mar 19, 2025 8:00 pm Thanks Paul. That's a good point. So does using "load file" instead get around the browser CORS errors, or do you still have to modify headers and stuff to get that to work?
In theory, lets assume I was just loading and saving from a stacks subdirectory, would that work? We could even symlink / alias that 'stacks' folder in the wrapper to point to the user's documents folder in something called 'webstacks'?
Here's an overview of the FileReader API: https://developer.mozilla.org/en-US/doc ... FileReaderBinary Large Object. It represents raw, immutable, file-like data. Blobs can contain various types of data, including text, images, audio, and video. They are often used for handling large files and data streams in web applications.
The code for 'load file' is in a few posts back:
I didn't make a multi-base baseConvert equivalentbaseConvert(28,10,16) --1c, dec>hex
Code: Select all
// Handle hex function
const hexMatch = expr.match(/^hex\s*\(\s*(.+?)\s*\)$/i);
if (hexMatch) {
const [_, number] = hexMatch;
const numberValue = this.evaluateExpression(number);
const value = Number(numberValue);
if (isNaN(value)) {
throw new Error('hex: argument must be a number');
}
return value.toString(16);
}
Code: Select all
put hex(28) -- 1c
put hex(127) -- 7f
put hex(4294967295) -- ffffffff max value for a 32bit unsigned integer
put hex(18446744073709551615) -- ffffffffffffffff can't handle max value for a 64bit unsigned integer, fails
Code: Select all
// Handle dec function
const decMatch = expr.match(/^dec\s*\(\s*(.+?)\s*\)$/i);
if (decMatch) {
const [_, thehex] = decMatch;
return parseInt( thehex, 16);
}
Code: Select all
put dec(1c) -- 28 pass
put hex(18446744073709551615) -- 10000000000000000, should be ffffffffffffffff -- fail
put dec(ffffffffffffffff) -- 18446744073709552000, should be 18446744073709551615 -- fail
put hex(18446744073709552000) -- 10000000000000000
Code: Select all
put ceiling(33.25) into tResult -- outputs 34
put ceil(12.9) into tResult -- outputs 13
Code: Select all
put ceiling("abc")
Code: Select all
Error: ceiling: argument must be a number
Code: Select all
beep -- play an audible beep once
beep 4 -- beeps 4 times
Code: Select all
put floor(33.25) -- outputs 33
put floor(12.9) -- outputs 12
put floor(-3.7) -- outputs -4
Code: Select all
put geometricMean(10,20,25) -- outputs 17.1
put geometricMean(4,9) -- outputs 6
Code: Select all
put harmonicMean(10,20,25) -- outputs 15.79
put harmonicMean(4,9) -- outputs 5.54
Code: Select all
put median(10,20,30) -- outputs 20
put median(10,20,30,40) -- outputs 25
put median(5,1,3,2,4) -- outputs 3
Code: Select all
put max(10,20,30) -- outputs 30
put max(42,17,29) -- outputs 42
put max(-5,-10,-3) -- outputs -3
Code: Select all
put min(10,20,30) -- outputs 10
put min(42,17,29) -- outputs 17
put min(-5,-10,-3) -- outputs -10
Code: Select all
put round(12.5) -- outputs 13
put round(12.4) -- outputs 12
put round(-3.7) -- outputs -4
put statRound(10.5) -- outputs 10
put statRound(11.5) -- outputs 12
Users browsing this forum: No registered users and 9 guests