Insert Predefined Text

Inserts predefined text into a text box when the user presses enter or clicks okay

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

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

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

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

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

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

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

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

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

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

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

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

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

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

```javascript
// ==UserScript==
// @name         Insert Predefined Text
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Inserts predefined text into a text box when the user presses enter or clicks okay
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Set the predefined text here
    var predefinedText = "This is the predefined text.";

    // Add an event listener for keydown events
    document.addEventListener('keydown', function(event) {
        // Check if the key pressed was enter
        if (event.key === 'Enter') {
            // Get the active element (the one currently selected by the cursor)
            var activeElement = document.activeElement;

            // Check if the active element is a text box
            if (activeElement.tagName === 'TEXTAREA' || (activeElement.tagName === 'INPUT' && activeElement.type === 'text')) {
                // Insert the predefined text into the text box with a space before it
                activeElement.value += ' ' + predefinedText;
            }
        }
    });
})();
```