Type

在限制粘贴的网页优雅快速地粘贴内容。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Type
// @namespace    http://tampermonkey.net/
// @version      2025-08-17
// @description  在限制粘贴的网页优雅快速地粘贴内容。
// @author       xhze
// @match        *://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';


    let input = document.createElement('textarea');
    input.style="height: 70vh; width: 70vw; background-color: #f1f1f1; border: solid 2px white; border-radius: 1rem; padding: 3rem; position: absolute; "

    let submit = document.createElement('button');
    submit.style="height: 2.5rem; width: 5rem; background-color: #1f1f1f; border: solid 2px white; border-radius: 1rem; color: white; position: absolute; left: 0px; top: 0px; "
    submit.innerHTML = '完成'

    let span = document.createElement('span');
    span.style="color:red; font-size:5rem; position: absolute; left: 0px; top: 0px; "


    submit.onclick = async function() {
        let text = input.value;
        document.body.removeChild(div);
        isPasting=false;
        typeCharacter(text)
    }


    let div = document.createElement('div');

    div.appendChild(input)
    div.appendChild(submit)

    var isPasting = false;
    var inputElement = document.activeElement

    function handleKeyEvent(e) {
        if(e.ctrlKey &&e.shiftKey && e.key == '<') {
            console.log(e)
            inputElement = document.activeElement
            console.log(inputElement)
            document.body.appendChild(div);
            console.log('ctrl+shift+v');
            input.focus();
            isPasting = true;
        }
    }

    async function typeCharacter(text) {
        for(let index = 0;index<text.length;index++){
            inputElement.value += text[index];
            const event = new Event('input', { bubbles: true });
            inputElement.dispatchEvent(event);
            await sleep(1);
        }
    }

    function sleep(ms) {
        return new Promise((e,_)=>setTimeout(e,ms))
    }
    //let _ = window.onkeydown;
    //window.onkeydown = e=> {handleKeyEvent();_(e)};
    document.onkeydown = handleKeyEvent;
    // Your code here...
})();