CSDN复制

CSDN免登陆复制

当前为 2022-09-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name CSDN复制
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.1
  5. // @description CSDN免登陆复制
  6. // @author You
  7. // @match https://blog.csdn.net/*/article/details/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. // Your code here...
  16. const pre = document.getElementsByTagName('pre')
  17. const code = document.getElementsByTagName('code')
  18. for (let i = 0; i < pre.length; i++) {
  19. pre[i].setAttribute("style","user-select: auto !important")
  20. }
  21. for (let i = 0; i < code.length; i++) {
  22. code[i].setAttribute("style","user-select: auto !important")
  23. }
  24. window.addEventListener("copy", function (e) {
  25. let val = (window.getSelection().toString());
  26. e.preventDefault();
  27. e.clipboardData.setData("text/plain", val)
  28. });
  29. })();