Selection and Copying Restorer

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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