通用function

try to take over the world!

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/395074/765652/%E9%80%9A%E7%94%A8function.js

  1. function copy(value) {
  2. let transfer = document.createElement('input');
  3. document.body.appendChild(transfer);
  4. transfer.value = value; // 这里表示想要复制的内容
  5. //transfer.focus();
  6. transfer.select();
  7. if (document.execCommand('copy')) {
  8. document.execCommand('copy');
  9. }
  10. //transfer.blur();
  11. console.log('复制成功:',value);
  12. document.body.removeChild(transfer);
  13. }
  14.  
  15. //copy图片到剪切板
  16. function copyImage(img=''){
  17. img = img || document.getElementsByTagName('img')[0];
  18. if(img == undefined){
  19. console.log('img not exits');
  20. return ;
  21. }
  22. img.removeAttribute('alt');
  23. var range = document.createRange();
  24. range.selectNode(img);
  25. window.getSelection().removeAllRanges();
  26. window.getSelection().addRange(range);
  27. document.execCommand("Copy");
  28. window.getSelection().removeAllRanges();
  29. console.log('复制成功:',img.src);
  30. }
  31.  

QingJ © 2025

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