Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #29585

    EmEditor v23 added a web browser feature. With ChatGPT.jsee, there is no need to switch to an external browser, making it much more convenient.

    Due to the potential for changes in the format of ChatGPT results in the future or issues such as high demand and operational disruptions,
    After some study, I referred to ChatGPT.jsee, modified it to be usable for Bard as an alternative, added commonly used custom prompts, and also further modified ChatGPT.jsee.

    This allows users to select text in the left window of EmEditor, press the custom macro button above, and the right window will display the AI’s responses, such as explanations of the content, syntax checks, and translations of the selected text, and more. I really enjoy this way of text editing with EmEditor and AI.

    Additionally, since the automatic sending is not always successful, a 100-millisecond wait was added to ensure that the text can be automatically sent.
    Here is the modified .jsee file.

    #language = "V8"
    #async = "on"
    #tooltip="Bard Explain"
    // This macro retrieves Bard search results using a word at the cursor or the selection. 
    // It demonstrates the use of the WebBar object and the "web" keyword to 
    // access the Document Object Model (DOM) using the EmEditor's Web Browser. It requires
    // EmEditor v23.0 or later.
    // Disclaimer: The format of Bard results may change at any time in the future, which
    // could affect the functionality of this macro. The macro is intended solely to demonstrate 
    // the new features of EmEditor v23.0.
    const sURL = "";
    var prompts = "Explain the following content:\n";
    if( !WebBar.Visible ) {
    	// use "WebBar" to open the URL using the EmEditor's Web Browser
    	WebBar.Open( sURL );
    	alert( "Please run this macro again" );
    if( !web.window.location.href.startsWith( sURL ) ) {
    	web.window.location.href = sURL;
    	alert( "Please run this macro again" );
    if( document.selection.IsEmpty ) {
    if( !document.selection.IsEmpty ) {
    	var elem = web.document.querySelector('.ql-editor.textarea>p');
    	if( elem == null ) {
    		alert( "Cannot find search box" );
    	elem.textContent = prompts + document.selection.Text;
    	// Simulate input to refresh UI
    	elem.dispatchEvent( new Event( 'input', { bubbles: true } ) );
    	// The following lines to submit the text automatically
    	setTimeout(function() {
    		var elemBtn = web.document.querySelector('.send-button');
    		if (elemBtn) {
    			elemBtn.dispatchEvent(new MouseEvent('click', { bubbles: true }));
    		} else {
    			alert("Cannot find button element");
    	}, 100);

    Screenshot in use.
    Screenshot in use.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.