Greasy Fork

Greasy Fork is available in English.

Easy Input

模拟键盘输入实现文本粘贴。

当前为 2024-10-21 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Easy Input
// @namespace    zarttic
// @version      3.2
// @description  模拟键盘输入实现文本粘贴。
// @author       zarttic
// @run-at       document-start
// @license      ISC
// @grant        none
// @match       *://*.*.*/*
// ==/UserScript==

(function() {
  'use strict';

  // 创建一个按钮
  const button = document.createElement('button');
  button.innerText = '👉一键粘贴👈';
  button.style.position = 'fixed';
  button.style.bottom = '10px';
  button.style.right = '10px';
  button.style.zIndex = '1000';
  button.style.padding = '10px';
  button.style.backgroundColor = '#4CAF50';
  button.style.color = 'white';
  button.style.border = 'none';
  button.style.borderRadius = '5px';
  button.style.cursor = 'pointer';

  // 添加按钮到页面
  document.body.appendChild(button);

  // 监听按钮点击事件
  button.addEventListener('click', async () => {
    const text = prompt('请输入要粘贴的文本:');
    if (text) {
      simulateInput(text);
    }
  });

  // 模拟输入函数
  function simulateInput(text) {
    const inputField = document.activeElement;
    if (inputField && (inputField.tagName === 'INPUT' || inputField.tagName === 'TEXTAREA')) {
      inputField.value = text;
      const event = new Event('input', { bubbles: true });
      inputField.dispatchEvent(event);
    }
  }
})();