anti-select-none - csdn.net

解除 CSDN code block 的 select 鎖定

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

  1. // ==UserScript==
  2. // @name anti-select-none - csdn.net
  3. // @namespace Violentmonkey Scripts
  4. // @match https://blog.csdn.net/*
  5. // @grant none
  6. // @version 1.1.0
  7. // @author Lofairy
  8. // @icon https://blog.csdn.net/favicon.ico
  9. // @description 解除 CSDN code block 的 select 鎖定
  10. // ==/UserScript==
  11.  
  12. /* jshint esversion:6 */
  13.  
  14. (function() {
  15. 'use strict';
  16. // console.info('init');
  17.  
  18. var observer = new MutationObserver(resetTimer);
  19. var timer = setTimeout(action, 3000, observer);
  20. observer.observe(document, {childList: true, subtree: true});
  21.  
  22. // reset timer every time something changes
  23. function resetTimer(changes, observer) {
  24. // console.info('timer');
  25. clearTimeout(timer);
  26. timer = setTimeout(action, 3000, observer);
  27. }
  28.  
  29. function action(observer) {
  30. let codeElemants = document.querySelectorAll('pre');
  31. if (codeElemants.length > 0) {
  32. observer.disconnect();
  33. // console.info('done');
  34. codeElemants.forEach(ele => {
  35. ele.children[0].style.userSelect = 'text';
  36. ele.children[0].style.webkitUserSelect = 'text';
  37. ele.children[1].remove();
  38. });
  39. }
  40. }
  41. })();