anti-select-none - csdn.net

解除 CSDN code block 的 select 鎖定

Stan na 19-01-2022. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        anti-select-none - csdn.net
// @namespace   Violentmonkey Scripts
// @match       https://blog.csdn.net/*
// @grant       none
// @version     1.0.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[name=code]');
      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();
        });
      }
    }
  
})();