Greasy Fork is available in English.

选中即复制

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

您查看的为 2020-09-04 提交的版本。查看 最新版本

// ==UserScript==
// @name         选中即复制
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  鼠标选中页面中的字符,自动复制进剪贴板
// @author       kakasearch
// @include      *://**/*
// @grant        unsafeWindow
// ==/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'); // 执行浏览器的复制命令
}

})();