anti-select-none - csdn.net

解除 CSDN code block 的 select 鎖定

Verze ze dne 19. 01. 2022. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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();
        });
      }
    }
  
})();