复制粘贴代码净化

代码剪贴板净化,解决复制代码旁边出现序号的问题

  1. // ==UserScript==
  2. // @name 复制粘贴代码净化
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description 代码剪贴板净化,解决复制代码旁边出现序号的问题
  6. // @author Stu-Van
  7. // @match *://*.zhihu.com/*
  8. // @match *://*.jianshu.com/*
  9. // @match *://*.csdn.net/*
  10. // @match *://*.nowcoder.com/*
  11. // @match *://*.juejin.im/*
  12. // @match *://*.juejin.cn/*
  13. // @license GPL-3.0 License
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. function clearText() {
  19. var clipPromise = navigator.clipboard.readText();
  20. var aa = [];
  21. clipPromise.then(function (clipText) {
  22. var lines = clipText.split("\n");
  23. var num = lines.length.toString().length;
  24. for (var index = 0; index < lines.length; index++) {
  25. var element = lines[index];
  26. var indexof = element.indexOf((index + 1));
  27. if (indexof != -1) {
  28. aa[index] = element.substring(num, element.length);
  29. }else{
  30. aa[index]=element;
  31. }
  32. }
  33. }).then(function (data) {
  34. writecontent(aa.join("\n"))
  35. });
  36. }
  37. function writecontent(aa){
  38. navigator.clipboard.writeText(aa).then(() => {
  39. console.log('复制成功')
  40. }).catch(() => {
  41. const e = document.createElement('textarea')
  42. document.body.appendChild(e)
  43. e.innerHTML = aa;
  44. e.select();
  45. if (document.execCommand('copy')) {
  46. document.execCommand('copy');
  47. }
  48. document.body.removeChild(e)
  49. console.log('复制成功')
  50. })
  51. }
  52.  
  53. document.addEventListener('copy',clearText)
  54. })();

QingJ © 2025

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