anti-select-none - csdn.net

解除 CSDN code block 的 select 鎖定

As of 27.01.2022. See апошняя версія.

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!)

// ==UserScript==
// @name        anti-select-none - csdn.net
// @namespace   Violentmonkey Scripts
// @match       https://blog.csdn.net/*
// @grant       none
// @version     1.1.0
// @author      Lofairy
// @icon        https://blog.csdn.net/favicon.ico
// @description 解除 CSDN code block 的 select 鎖定
// ==/UserScript==

/* jshint esversion:6 */

(function() {
    'use strict';
    // console.info('init');

    var observer = new MutationObserver(resetTimer);
    var timer = setTimeout(action, 3000, observer);
    observer.observe(document, {childList: true, subtree: true});

    // reset timer every time something changes
    function resetTimer(changes, observer) {
        // console.info('timer');
        clearTimeout(timer);
        timer = setTimeout(action, 3000, observer);
    }

    function action(observer) {
      let codeElemants = document.querySelectorAll('pre');
      if (codeElemants.length > 0) {
        observer.disconnect();
        // console.info('done');
        codeElemants.forEach(ele => {
            ele.children[0].style.userSelect = 'text';
            ele.children[0].style.webkitUserSelect = 'text';
            ele.children[1].remove();
        });
      }
    }
  
})();