选中即复制

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

  1. // ==UserScript==
  2. // @name 选中即复制
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description 鼠标选中页面中的字符,自动复制进剪贴板
  6. // @author kakasearch
  7. // @include *://*
  8. // @grant unsafeWindow
  9. // @grant GM_setClipboard
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. var text
  16. document.onclick = function() {
  17. if ( unsafeWindow.getSelection) {
  18. text = unsafeWindow.getSelection();
  19. } else if (document.selection) {
  20. text = document.selection.createRange();
  21. }
  22. // 放到粘贴板里,操作浏览器自身的API
  23. // console.log(text.toString());
  24. //document.execCommand('Copy'); // 执行浏览器的复制命令
  25. GM_setClipboard(text.toString()); //采用iamqiz提出的方案,主页地址:https://gf.qytechs.cn/zh-CN/users/380079-iamqiz
  26. }
  27.  
  28. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址