Greasy Fork

Greasy Fork is available in English.

解除所有输入框和多行文本框复制限制

允许在所有输入框和多行文本框中选中和复制内容,密码框聚焦时可复制

当前为 2025-05-06 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         解除所有输入框和多行文本框复制限制
// @namespace    MilesTurner
// @version      1.0.0
// @description  允许在所有输入框和多行文本框中选中和复制内容,密码框聚焦时可复制
// @author       Miles Turner
// @match        *://*/*
// @icon         https://www.greasyfork.org/static/icon256.png
// @license      MIT
// @homepageURL  http://greasyfork.icu/zh-CN/scripts/000000
// @supportURL   http://greasyfork.icu/zh-CN/scripts/000000/feedback
// @run-at       document-end
// @grant        none
// ==/UserScript==
"use strict";

// 解除所有输入框和多行文本框的选中和复制限制,并处理密码框
function unlockAllInputFields(root=document) {
    root.querySelectorAll('input, textarea').forEach(el => {
        el.style.userSelect = 'text';
        el.style.webkitUserSelect = 'text';
        el.style.mozUserSelect = 'text';
        el.style.msUserSelect = 'text';
        el.style.cursor = 'text';

        // 对密码框特殊处理:聚焦时变为text,失焦时还原
        if (el.tagName.toLowerCase() === 'input' && el.type === 'password') {
            if (!el._unlockCopyHandler) {
                el._unlockCopyHandler = true;
                el.addEventListener('focus', function() {
                    el.setAttribute('data-old-type', el.type);
                    el.type = 'text';
                });
                el.addEventListener('blur', function() {
                    if (el.getAttribute('data-old-type')) {
                        el.type = el.getAttribute('data-old-type');
                        el.removeAttribute('data-old-type');
                    }
                });
            }
        }
    });
}

// 初始解除
unlockAllInputFields();

// 动态内容支持
const observer = new MutationObserver(mutations => {
    for (const m of mutations) {
        for (const node of m.addedNodes) {
            if (node.nodeType === 1) {
                unlockAllInputFields(node);
            }
        }
    }
});
observer.observe(document.body, {childList: true, subtree: true});

// 解除右键菜单限制
document.addEventListener('contextmenu', event => {
    event.stopImmediatePropagation();
}, true);