选中即复制

鼠标选中页面中的字符,自动复制进剪贴板

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         选中即复制
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  鼠标选中页面中的字符,自动复制进剪贴板
// @author       kakasearch
// @include      *://*
// @grant        unsafeWindow
// @grant        GM_setClipboard
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    var text
    document.onclick = function() {
        if ( unsafeWindow.getSelection) {
            text = unsafeWindow.getSelection();
        } else if (document.selection) {
            text = document.selection.createRange();
        }
        // 放到粘贴板里,操作浏览器自身的API
        // console.log(text.toString());
        //document.execCommand('Copy'); // 执行浏览器的复制命令
        GM_setClipboard(text.toString()); //采用iamqiz提出的方案,主页地址:https://greasyfork.org/zh-CN/users/380079-iamqiz
    }

})();