SAP AI Playground | Trigger Button Click on Cmd/Ctrl-Enter

Click the button with ID btnChat when the user presses Cmd-Enter or Ctrl-Enter

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         SAP AI Playground | Trigger Button Click on Cmd/Ctrl-Enter
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Click the button with ID btnChat when the user presses Cmd-Enter or Ctrl-Enter
// @author       ChatGPT, tddschn
// @match        https://ai-playground.cfapps.sap.hana.ondemand.com/index.html
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function triggerButtonClick(e) {
        // Check if the pressed key is Enter and either Cmd or Ctrl is also pressed
        if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
            const button = document.getElementById("btnChat");
            if (button) {
                button.click();
            }
        }
    }

    // Add the event listener to the document
    document.addEventListener('keydown', triggerButtonClick);
})();