Selection and Copying Restorer

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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