网上大学右键弹出复制

先选择文字,然后单击鼠标右键,即可复制选择的文字,成功无提示,失败则有提示!

  1. // ==UserScript==
  2. // @name 网上大学右键弹出复制
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description 先选择文字,然后单击鼠标右键,即可复制选择的文字,成功无提示,失败则有提示!
  6. // @description:zh 更新为全网通用http
  7. // @description:zh 更新为全网通用https
  8. // @author You
  9. // @include http://*/*
  10. // @include https://*/*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Your code here...
  18. document.onmousedown = function(e){
  19. var e2 = e || window.event
  20. if(e2.button == "2"){
  21. //alert(selectText());
  22. var oInput = document.createElement('input');
  23. // 把文字放进input中,供复制
  24. oInput.value = selectText();
  25. document.body.appendChild(oInput);
  26. // 选中创建的input
  27. oInput.select();
  28. // 执行复制方法, 该方法返回bool类型的结果,告诉我们是否复制成功
  29. var copyResult = document.execCommand('copy')
  30. // 操作中完成后 从Dom中删除创建的input
  31. document.body.removeChild(oInput)
  32. // 根据返回的复制结果 给用户不同的提示
  33. if (copyResult) {
  34. //alert('DDL已复制到粘贴板')
  35. } else {
  36. alert('复制失败')
  37. }
  38. }
  39. }
  40. function selectText(){
  41. if(document.Selection){
  42. //ie浏览器
  43. return document.selection.createRange().text;
  44. }else{
  45. //标准浏览器
  46. return window.getSelection().toString();
  47. }
  48. }
  49. })();

QingJ © 2025

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