Skip to content
TheChatArchiveThe Chat Archive
Geminigemini-2.0-flash-001· GoogleHugging Face LMArena Human Preference 140K

I added 2 custom buttons to load dump from file. I want to make individual confirmation…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-3-5-sonnet-20241022’s answer.
  1. User

    I added 2 custom buttons to load dump from file. I want to make individual confirmation message for two of them for k10 "k10", for k7 "k7". How to do that?? it is inav-configurator here is snippets.

    cli.js ('.tab-cli .load-k10').on('click', function (event) { event.preventDefault(); let previewArea = ("#snippetpreviewcontent textarea#preview"); const filePath = path.join(__dirname, '..', '.dump', 'k10.txt'); function executeSnippet() { const commands = previewArea.val(); executeCommands(commands); self.GUI.snippetPreviewWindow.close(); (′.cli−preloader′).toggleClass(′active′);('.cli-preloader').toggleClass('active'); ('.backdrop .window .wrapper').css({ 'opacity': '0', 'user-select': 'none', '-webkit-user-select': 'none', '-moz-user-select': 'none', '-ms-user-select': 'none', 'pointer-events': 'none' }); (′.tab−cli.copy′).attr(′disabled′,true);('.tab-cli .copy').attr('disabled', true); ('.tab-cli .copy').prop('disabled', true); $('.tab-cli .copy').hide(); }

            function previewCommandsK(result) {
                $(previewArea).css({'display': 'none'});
                previewArea.val(result);
                self.GUI.snippetPreviewWindow = new jBox("Modal", {
                    id: "snippetPreviewWindow",
                    theme: "NoticeFancy",
                    addClass: "RoiDark",
                    width: 'auto',
                    height: 'auto',
                    closeButton: 'title',
                    animation: false,
                    isolateScroll: false,
                    title: i18n.getMessage("cliConfirmSnippetDialogTitle"),
                    content: $('#snippetpreviewcontent'),
                    onCreated: () => $("#snippetpreviewcontent a.confirm").on('click', executeSnippet),
                });
                self.GUI.snippetPreviewWindow.open();
            }
    

    ...... } }); } }); } });

    cli.html

        <div class="btn save_btn pull-right">
            <a class="cliDocsBtn" href="#" i18n="cliDocsBtn" target="_blank"></a>
            <a class="load" href="#" i18n="cliLoadFromFileBtn"></a>
            <a style="display:none !important;" class="save" href="#" i18n="cliSaveToFileBtn"></a>
            <a class="copy" href="#" i18n="cliCopyToClipboardBtn"></a>            
            <a class="clear" href="#" i18n="cliClearOutputHistoryBtn"></a>     
            <a class="diffall" href="#" i18n="cliDiffAllBtn"></a>  
            <a class="load-k7" href="#">K7</a>
            <a class="load-k10" href="#">K10</a>
        </div>
    </div>
    
    <!-- Snippet preview dialog -->
    <div id="snippetpreviewcontent" style="display: none">
        <div class="note">
            <div class="note_spacer">
                <p i18n="cliConfirmSnippetNote"></p>
            </div>
        </div>
        <textarea id="preview" cols="120" rows="20"></textarea>
        <div class="default_btn">
            <a class="confirm" href="#" i18n="cliConfirmSnippetBtn"></a>
        </div>
    </div>
    
  2. Gemini Assistant

    OK. The core of the problem is that you're using the same previewCommandsK and executeSnippet functions for both the k7 and k10 buttons. You need to create separate, slightly modified versions of these functions for each button's confirmation message.

    Here's how you can modify your cli.js file:

    $('.tab-cli .load-k10').on('click', function (event) {
        event.preventDefault();
        let previewArea = $("#snippetpreviewcontent textarea#preview");
        const filePath = path.join(__dirname, '..', '.dump', 'k10.txt');
    
        function executeSnippetK10() {  // Modified function for K10
            const commands = previewArea.val();
            executeCommands(commands);
            self.GUI.snippetPreviewWindow.close();
            $('.cli-preloader').toggleClass('active');
            $('.backdrop .window .wrapper').css({
                'opacity': '0',
                'user-select': 'none',
                '-webkit-user-select': 'none',
                '-moz-user-select': 'none',
                '-ms-user-select': 'none',
                'pointer-events': 'none'
            });
            $('.tab-cli .copy').attr('disabled', true);
            $('.tab-cli .copy').prop('disabled', true);
            $('.tab-cli .copy').hide();
        }
    
        function previewCommandsK10(result) {  // Modified function for K10
            $(previewArea).css({'display': 'none'});
            previewArea.val(result);
            self.GUI.snippetPreviewWindow = new jBox("Modal", {
                id: "snippetPreviewWindow",
                theme: "NoticeFancy",
                addClass: "RoiDark",
                width: 'auto',
                height: 'auto',
                closeButton: 'title',
                animation: false,
                isolateScroll: false,
                title: i18n.getMessage("cliConfirmSnippetDialogTitle") + " - K10", // Add specific title
                content: $('#snippetpreviewcontent'),
                onCreated: () => $("#snippetpreviewcontent a.confirm").on('click', executeSnippetK10), // Call K10 execute function
            });
            self.GUI.snippetPreviewWindow.open();
        }
    
        fs.readFile(filePath, 'utf8', (err, result) => {
            if (err) {
                console.error(err);
                GUI.log(i18n.getMessage("cliLoadFromFileError") + ": " + err.message);
            } else {
                previewCommandsK10(result);
            }
        });
    });
    
    $('.tab-cli .load-k7').on('click', function (event) {
        event.preventDefault();
        let previewArea = $("#snippetpreviewcontent textarea#preview");
        const filePath = path.join(__dirname, '..', '.dump', 'k7.txt');
    
        function executeSnippetK7() {  // Modified function for K7
            const commands = previewArea.val();
            executeCommands(commands);
            self.GUI.snippetPreviewWindow.close();
            $('.cli-preloader').toggleClass('active');
            $('.backdrop .window .wrapper').css({
                'opacity': '0',
                'user-select': 'none',
                '-webkit-user-select': 'none',
                '-moz-user-select': '-none',
                'pointer-events': 'none'
            });
            $('.tab-cli .copy').attr('disabled', true);
            $('.tab-cli .copy').prop('disabled', true);
            $('.tab-cli .copy').hide();
        }
    
        function previewCommandsK7(result) {  // Modified function for K7
            $(previewArea).css({'display': 'none'});
            previewArea.val(result);
            self.GUI.snippetPreviewWindow = new jBox("Modal", {
                id: "snippetPreviewWindow",
                theme: "NoticeFancy",
                addClass: "RoiDark",
                width: 'auto',
                height: 'auto',
                closeButton: 'title',
                animation: false,
                isolateScroll: false,
                title: i18n.getMessage("cliConfirmSnippetDialogTitle") + " - K7", // Add specific title
                content: $('#snippetpreviewcontent'),
                onCreated: () => $("#snippetpreviewcontent a.confirm").on('click', executeSnippetK7), // Call K7 execute function
            });
            self.GUI.snippetPreviewWindow.open();
        }
    
        fs.readFile(filePath, 'utf8', (err, result) => {
            if (err) {
                console.error(err);
                GUI.log(i18n.getMessage("cliLoadFromFileError") + ": " + err.message);
            } else {
                previewCommandsK7(result);
            }
        });
    });
    

    Key changes and explanation:

    1. Separate Functions: We've created executeSnippetK10, previewCommandsK10, executeSnippetK7, and previewCommandsK7. This is crucial because now each button click uses its own functions. You need this separation to customize the title and the execution path.

    2. Specific Titles: The title property of the jBox modal is now customized:

      • title: i18n.getMessage("cliConfirmSnippetDialogTitle") + " - K10"
      • title: i18n.getMessage("cliConfirmSnippetDialogTitle") + " - K7" This appends " - K10" or " - K7" to your existing title, providing clear differentiation. Make sure the cliConfirmSnippetDialogTitle message is defined in your i18n system.
    3. Correct Execution: The onCreated handler in each previewCommandsK* function now calls the corresponding executeSnippetK* function:

      • onCreated: () => $("#snippetpreviewcontent a.confirm").on('click', executeSnippetK10)
      • onCreated: () => $("#snippetpreviewcontent a.confirm").on('click', executeSnippetK7) This is critical. It ensures that when the user clicks the "confirm" button in the preview, the correct snippet execution function is triggered.
    4. File paths: Adjusted filepath to k7.txt for 'k7' load button.

    Important Considerations:

    • i18n: Ensure cliConfirmSnippetDialogTitle is defined in your i18n translation files. If it's not, the titles might look odd. You probably already have this defined, but double-check.
    • Error Handling: The fs.readFile calls include basic error handling. You might want to make this more robust, perhaps displaying a more user-friendly error message in the UI.
    • Code Duplication: The executeSnippetK* functions are very similar. You could potentially refactor to reduce duplication if you wanted to make the common parts a single function and pass a parameter to differentiate (e.g., a "K10" or "K7" identifier). However, for clarity and maintainability, keeping them separate as above is often preferred.

    With these changes, when you click the "K10" button, you should see a confirmation dialog with "K10" in the title and the correct dump will be loaded. Similarly, for the "K7" button. Remember to test thoroughly!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.