Selection and Copying Restorer

Unlock right-click, remove restrictions on copy, cut, select text, right-click menu, text copying, text selection, image right-click

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

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

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                Selection and Copying Restorer
// @version             0.4
// @description         Unlock right-click, remove restrictions on copy, cut, select text, right-click menu, text copying, text selection, image right-click
// @namespace           https://greasyfork.org/users/1300060
// @author              AstralRift
// @run-at              document-end
// @match               *://*/*
// @grant               GM_registerMenuCommand
// @grant               GM_unregisterMenuCommand
// @grant               GM.setValue
// @grant               GM.getValue
// @grant               GM_addValueChangeListener
// @grant               unsafeWindow
// @license             MIT
// ==/UserScript==

(function() {
    'use strict';

    function unlockTextSelection() {
        const style = document.createElement('style');
        style.textContent = `
            * {
                user-select: text !important;
                -webkit-user-select: text !important;
                -moz-user-select: text !important;
            }
        `;
        document.head.appendChild(style);
    }

    function hasCopyRestrictions() {
        const testElement = document.createElement('div');
        testElement.style.userSelect = 'none';
        document.body.appendChild(testElement);
        const userSelect = getComputedStyle(testElement).userSelect;
        document.body.removeChild(testElement);

        if (userSelect === 'none') return true;

        const events = ['contextmenu', 'copy', 'cut', 'selectstart'];
        const isBlocked = events.some(event => {
            let blocked = false;
            document.addEventListener(event, function tempListener(e) {
                e.stopImmediatePropagation();
                blocked = true;
                document.removeEventListener(event, tempListener, true);
            }, true);

            const evt = new Event(event, { bubbles: true, cancelable: true });
            document.dispatchEvent(evt);
            return blocked;
        });

        return isBlocked;
    }

    function stopEventPropagation(event) {
        event.stopPropagation();
    }

    function stopEventDefault(event) {
        event.preventDefault();
    }

    function toggleEnabled() {
        GM.getValue('enabled', true).then(enabled => {
            enabled = !enabled;
            GM.setValue('enabled', enabled).then(() => {
                location.reload();
            });
        });
    }

    GM_registerMenuCommand('Toggle Selection and Copying Restorer', toggleEnabled);

    GM.getValue('enabled', true).then(enabled => {
        if (enabled && hasCopyRestrictions()) {
            unlockTextSelection();

            const eventOptions = { capture: true, passive: true };
            const eventOptionsNoPassive = { capture: true };

            document.addEventListener('contextmenu', stopEventPropagation, eventOptions);
            document.addEventListener('copy', stopEventDefault, eventOptionsNoPassive);
            document.addEventListener('cut', stopEventDefault, eventOptionsNoPassive);
        }
    });
})();