• Replacing a text string to execute JS code directly

    From Nightfox@VERT/DIGDIST to Digital Man on Wednesday, January 29, 2025 12:39:52
    Hi DM,

    In the strings from text.dat, I know you can use @EXEC:..@ to have it run a JS or Baja module, but is there a way to have it directly execute a block of JS code instead of executing a file? In my most recent update to DDMsgReader, it replaces the AreYouThere string with an empty string so that the contents of the screen aren't affected, but I was also thinking of having it execute some JS code so that I'd have some more control on where the string is displayed, etc. I could have it execute a separate .js with @EXEC@, but I'm not sure I'd want to add a separate .js just for that. I'm wondering if there's a way to have it directly execute a block of JS code when used with bbs.replace_text()?

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
  • From Digital Man@VERT to Nightfox on Wednesday, January 29, 2025 13:15:38
    Re: Replacing a text string to execute JS code directly
    By: Nightfox to Digital Man on Wed Jan 29 2025 12:39 pm

    Hi DM,

    In the strings from text.dat, I know you can use @exec:..@ to have it run a JS or Baja module, but is there a way to have it directly execute a block of JS code instead of executing a file? In my most recent update to DDMsgReader, it replaces the AreYouThere string with an empty string so that the contents of the screen aren't affected, but I was also thinking of having it execute some JS code so that I'd have some more control on where the string is displayed, etc. I could have it execute a separate .js with @EXEC@, but I'm not sure I'd want to add a separate .js just for that. I'm wondering if there's a way to have it directly execute a block of JS code when used with bbs.replace_text()?

    Not exactly as @-codes are pretty restrictive as to the contents (e.g. no space characters), so it'be pretty hard to put a code block within an @-code. One possibility is to define a JS property with a getter function and then you can invoke that getter function with the JS:propname @-code: https://wiki.synchro.net/custom:atcodes#external_content
    --
    digital man (rob)

    Synchronet/BBS Terminology Definition #45:
    IMAP = Internet Message Access Protocol
    Norco, CA WX: 57.0øF, 60.0% humidity, 5 mph W wind, 0.00 inches rain/24hrs

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Digital Man@VERT to Nightfox on Wednesday, January 29, 2025 14:43:52
    Re: Replacing a text string to execute JS code directly
    By: Digital Man to Nightfox on Wed Jan 29 2025 01:15 pm

    Re: Replacing a text string to execute JS code directly
    By: Nightfox to Digital Man on Wed Jan 29 2025 12:39 pm

    Hi DM,

    In the strings from text.dat, I know you can use @exec:..@ to have it run a JS or Baja module, but is there a way to have it directly execute a block of JS code instead of executing a file? In my most recent update to DDMsgReader, it replaces the AreYouThere string with an empty string so that the contents of the screen aren't affected, but I was also thinking of having it execute some JS code so that I'd have some more control on where the string is displayed, etc. I could have it execute a separate .js with @EXEC@, but I'm not sure I'd want to add a separate .js just for that. I'm wondering if there's a way to have it directly execute a block of JS code when used with bbs.replace_text()?

    Not exactly as @-codes are pretty restrictive as to the contents (e.g. no space characters), so it'be pretty hard to put a code block within an @-code. One possibility is to define a JS property with a getter function and then you can invoke that getter function with the JS:propname @-code: https://wiki.synchro.net/custom:atcodes#external_content

    Here's an example:

    Object.defineProperty(js.global, "prop", {
    get : function () {
    return "hello, world";
    }
    });

    bbs.replace_text("Pause", "@JS:" + "prop@"); // @-code split for posting console.pause(); // will invoke the global 'prop' getter function

    In this example, the "prop" getter function could do more stuff and just return an empty string if that's what's desired.
    --
    digital man (rob)

    Synchronet "Real Fact" #37:
    Synchronet's Windows Control Panel is built with Borland C++ Builder
    Norco, CA WX: 59.7øF, 54.0% humidity, 1 mph SW wind, 0.00 inches rain/24hrs
    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Nightfox@VERT/DIGDIST to Digital Man on Wednesday, January 29, 2025 16:20:30
    Re: Replacing a text string to execute JS code directly
    By: Digital Man to Nightfox on Wed Jan 29 2025 02:43 pm

    Not exactly as @-codes are pretty restrictive as to the contents (e.g. no
    space characters), so it'be pretty hard to put a code block within an
    @-code. One possibility is to define a JS property with a getter function
    and then you can invoke that getter function with the JS:propname @-code:
    https://wiki.synchro.net/custom:atcodes#external_content

    Here's an example:

    Object.defineProperty(js.global, "prop", {
    get : function () {
    return "hello, world";
    }
    });

    bbs.replace_text("Pause", "@JS:" + "prop@"); // @-code split for posting console.pause(); // will invoke the global 'prop' getter function

    In this example, the "prop" getter function could do more stuff and just return an empty string if that's what's desired. --

    That's working. Thanks for the response and the example.

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
  • From Nightfox@VERT/DIGDIST to Digital Man on Friday, February 07, 2025 16:52:51
    Re: Replacing a text string to execute JS code directly
    By: Digital Man to Nightfox on Wed Jan 29 2025 02:43 pm

    Object.defineProperty(js.global, "prop", {
    get : function () {
    return "hello, world";
    }
    });

    bbs.replace_text("Pause", "@JS:" + "prop@"); // @-code split for posting

    I'm following this pattern to replace AreYouThere, and it seems like after the get function executes and returns, it seems like something wonky is going on with screen refreshing. With DDMsgReader, it seems there is a bit of scrolling on the screen and/or something wonky is going on with cursor movement via cursor.gotoxy(). Within the get function though, I've used cursor.gotoxy() and output a message, that worked as expected.

    I tried updating my get function to just return ""; and did a test with DDMsgReader. Before the the timeout warning, I had the user account looking at the message reading screen in DDMsgReader:

    http://www.digitaldistortionbbs.com:81/synchronet_stuff/reading1.png

    I waited for the configured amount of time, and after the get() was called for AreYouThere (returning ""), I pressed the down arrow, which should scroll the message down one line, and the screen was then as follows:

    http://www.digitaldistortionbbs.com:81/synchronet_stuff/reading_AfterAYT_AD.png

    If the getter is returning an empty string, I'm not sure what's causing the display to become messy. This does not happen if I replace AreYouThere with a simple empty string as follows:

    bbs.replace_text(AreYouThere, "");

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
  • From Digital Man@VERT to Nightfox on Friday, February 07, 2025 21:26:09
    Re: Replacing a text string to execute JS code directly
    By: Nightfox to Digital Man on Fri Feb 07 2025 04:52 pm

    Re: Replacing a text string to execute JS code directly
    By: Digital Man to Nightfox on Wed Jan 29 2025 02:43 pm

    Object.defineProperty(js.global, "prop", {
    get : function () {
    return "hello, world";
    }
    });

    bbs.replace_text("Pause", "@JS:" + "prop@"); // @-code split for posting

    I'm following this pattern to replace AreYouThere, and it seems like after the get function executes and returns, it seems like something wonky is going on with screen refreshing. With DDMsgReader, it seems there is a bit of scrolling on the screen and/or something wonky is going on with cursor movement via cursor.gotoxy(). Within the get function though, I've used cursor.gotoxy() and output a message, that worked as expected.

    I tried updating my get function to just return ""; and did a test with DDMsgReader. Before the the timeout warning, I had the user account looking at the message reading screen in DDMsgReader:

    http://www.digitaldistortionbbs.com:81/synchronet_stuff/reading1.png

    I waited for the configured amount of time, and after the get() was called for AreYouThere (returning ""), I pressed the down arrow, which should scroll the message down one line, and the screen was then as follows:

    http://www.digitaldistortionbbs.com:81/synchronet_stuff/reading_AfterAYT_AD. png

    If the getter is returning an empty string, I'm not sure what's causing the display to become messy. This does not happen if I replace AreYouThere with a simple empty string as follows:

    bbs.replace_text(AreYouThere, "");

    Probably because of this logic in the getkey():

    if ((sys_status & SS_USERON) && *text[AreYouThere] != '\0') {
    attr(LIGHTGRAY);
    carriage_return();
    cleartoeol();
    restoreline();
    }

    So you'll probably want to bbs.replaceText(AreYouThere, "") in the getter, so you don't have this carriage-return, CLR-TO-EOL and restore line stuff going on.
    --
    digital man (rob)

    Synchronet/BBS Terminology Definition #43:
    IBM437 = Code Page 437 (so-called IBM Extended ASCII)
    Norco, CA WX: 51.9øF, 93.0% humidity, 3 mph W wind, 0.13 inches rain/24hrs
    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Nightfox@VERT/DIGDIST to Digital Man on Saturday, February 08, 2025 10:02:35
    Re: Replacing a text string to execute JS code directly
    By: Digital Man to Nightfox on Fri Feb 07 2025 09:26 pm

    If the getter is returning an empty string, I'm not sure what's causing
    the display to become messy. This does not happen if I replace
    AreYouThere with a simple empty string as follows:

    bbs.replace_text(AreYouThere, "");

    Probably because of this logic in the getkey():

    if ((sys_status & SS_USERON) && *text[AreYouThere] != '\0') {
    attr(LIGHTGRAY);
    carriage_return();
    cleartoeol();
    restoreline();
    }

    So you'll probably want to bbs.replaceText(AreYouThere, "") in the getter, so you don't have this carriage-return, CLR-TO-EOL and restore line stuff going on.

    That works. Thanks!

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com