Custom Commands Dropdown

Add a dropdown of custom commands to a page

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name:en         Custom Commands Dropdown
// @name Custom Commands Dropdown
// @namespace    pl.4as.chatgpt
// @version      0.2
// @description Add a dropdown of custom commands to a page
// @description:en  Add a dropdown of custom commands to a page
// @author       Description009
// @match *://chat.openai.com/*
// @grant        none
// @license MIT
// ==/UserScript==

"use strict";

(function () {
  "use strict";
  console.log("CCD loading...");

  // This function will add our custom commands dropdown
  function addCustomCommandsDropdown() {
    // Get the textarea by ID
    const textareaElement = document.getElementById("prompt-textarea");

    // If the textarea exists, proceed to add the dropdown
    if (textareaElement) {
      // Create the select element
              var select_id=document.getElementById('commands')
      if (select_id){console.log('menu is loaded')}else{
      const select = document.createElement("select");
      select.name = "Commands";
      select.id = "commands";
      select.style.borderTop = "none";
      select.className =
        "m-0 w-full resize-none border-0 bg-transparent py-[10px] pr-10 focus:ring-0 focus-visible:ring-0 dark:bg-transparent md:py-4 md:pr-12 gizmo:md:py-3.5 pl-12 gizmo:pl-10 md:pl-[46px] gizmo:md:pl-[55px]";

      // List of commands for autocomplete
      const commands = [
        "Select Command",
        "myfiles_browser.search",
        "myfiles_browser.open_url",
        "myfiles_browser.back",
        "myfiles_browser.scroll",
        "myfiles_browser.quote_lines",
        "browser.search",
        "browser.click",
        "browser.back",
        "browser.scroll",
        "browser.open_url",
        "browser.quote_lines",
        // ... add any other commands here if necessary
      ];

      // Populate the select element with options
      commands.forEach((command) => {
        const option = document.createElement("option");
        option.value = command;
        option.textContent = command;
        option.style.backgroundColor = "#343541";
        option.style.borderBottom = "none";
        select.appendChild(option);
      });

      // Insert the select element before the textarea
      textareaElement.parentNode.insertBefore(select, textareaElement);

      // Event listener for select change
      select.addEventListener("change", function () {
        const selectedOption = select.options[select.selectedIndex].value;
        textareaElement.value += selectedOption + "();\n";
      });
      }
      console.log("Custom commands dropdown added.");
    } else {
      console.error("Textarea not found.");
    };
   setTimeout(addCustomCommandsDropdown,2000);console.log('Run function');
  }

  // Inject our addCustomCommandsDropdown function into the page
  function injectFunction(fn) {
    const script = document.createElement("script");
    script.text = `(${fn.toString()})();`;
      script.id = 'CustomCommand'
    document.body.appendChild(script);
    console.log("Code injected using injectionFunc");
  }

  // Wait 10 seconds after the page loads before injecting the dropdown
  setTimeout(function () {
    injectFunction(addCustomCommandsDropdown);
  }, 1000); // 1 seconds expressed in milliseconds
})();