Enable Text Select and Copy

Enables text selection and copying on websites that block it using CSS or JavaScript.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Enable Text Select and Copy
// @namespace    RW5hYmxlIFRleHQgU2VsZWN0IGFuZCBDb3B5
// @version      1.0
// @description  Enables text selection and copying on websites that block it using CSS or JavaScript.
// @author       smed79
// @license      GPLv3
// @icon         https://i25.servimg.com/u/f25/11/94/21/24/select10.png
// @match        http://*/*
// @match        https://*/*
// @grant        none
// @esversion    11
// ==/UserScript==

(function() {
  'use strict';

  // CSS properties to enforce
  const props = [
    'user-select',
    '-webkit-user-select',
    '-moz-user-select',
    '-ms-user-select',
    '-khtml-user-select',
    '-o-user-select',
    '-webkit-touch-callout'
  ];

  // Inline event handlers to remove
  const eventsToRemove = [
    'onselectstart',
    'onmousedown',
    'oncontextmenu',
    'ondragstart'
  ];

  // Inject global CSS override
  const style = document.createElement('style');
  style.innerHTML = props.map(p => `* { ${p}: text !important; }`).join('\n');
  document.head.appendChild(style);

  // Apply fixes to all elements
  const applyFixes = el => {
    props.forEach(prop => {
      el.style?.setProperty?.(prop, 'text', 'important');
    });
    eventsToRemove.forEach(evt => {
      if (el[evt]) {
        el[evt] = null;
        el.setAttribute(evt, '');
      }
    });
  };

  // Initial pass
  document.querySelectorAll('*').forEach(applyFixes);

  // Observe future DOM changes
  const observer = new MutationObserver(mutations => {
    mutations.forEach(mutation => {
      mutation.addedNodes.forEach(node => {
        if (node.nodeType === 1) {
          applyFixes(node);
          node.querySelectorAll?.('*')?.forEach?.(applyFixes);
        }
      });
    });
  });

  observer.observe(document.body, { childList: true, subtree: true });

  // Re-enable default behaviors via event listeners
  const allowEvent = e => e.stopPropagation();
  ['selectstart', 'mousedown', 'contextmenu', 'dragstart'].forEach(evt => {
    document.addEventListener(evt, allowEvent, true);
  });
})();