您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Automatically copy selected text to clipboard and keep the selection
当前为
// ==UserScript== // @name Auto Copy Selected Text // @namespace http://tampermonkey.net/ // @version 1.5 // @description Automatically copy selected text to clipboard and keep the selection // @author liuweiqing // @match *://*/* // @grant none // @license MIT // @icon https://icons.iconarchive.com/icons/gartoon-team/gartoon-places/256/user-desktop-icon.png // ==/UserScript== (function () { ("use strict"); // 监听鼠标松开的事件 document.addEventListener("mouseup", () => { const selection = window.getSelection(); const selectedText = selection.toString(); if (selectedText) { const range = selection.getRangeAt(0); if (navigator.clipboard) { navigator.clipboard .writeText(selectedText) .then(() => { console.log("Text copied to clipboard:", selectedText); }) .catch((err) => { console.error("Failed to copy text to clipboard", err); }); } else { const tempElement = document.createElement("textarea"); tempElement.value = selectedText; document.body.appendChild(tempElement); tempElement.select(); try { document.execCommand("copy"); console.log("Text copied to clipboard:", selectedText); } catch (err) { console.error("Failed to copy text to clipboard", err); } document.body.removeChild(tempElement); } selection.removeAllRanges(); selection.addRange(range); } }); })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址