CSDN 复制代码

CSDN 复制代码,并自动高度

  1. // ==UserScript==
  2. // @name CSDN 复制代码
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description CSDN 复制代码,并自动高度
  6. // @author You
  7. // @match https://blog.csdn.net/*
  8. // @icon https://www.google.com/s2/favicons?domain=csdn.net
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. function resetHeight(it) {
  16. $('textarea').each((ind,it) => {
  17. it.style.height = it.scrollHeight + 'px';
  18. });
  19. }
  20. setInterval(() => {
  21. $('#article_content pre').each((ind,pre) => {
  22. $(pre).replaceWith(`<textarea style="width:100%;height: ${pre.offsetHeight}px;">${$(pre).find('code')[0].innerText}</textarea>`);
  23. resetHeight();
  24. });
  25. },1000);
  26. // Your code here...
  27. })();