您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Inserts predefined text into a text box when the user presses enter or clicks okay
- ```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;
- }
- }
- });
- })();
- ```