A Universal Script to Re-Enable the Selection and Copying

Enables select, right-click, copy and drag on pages that disable them.

Fra og med 06.06.2021. Se den nyeste version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         A Universal Script to Re-Enable the Selection and Copying
// @version      1.2.9
// @description  Enables select, right-click, copy and drag on pages that disable them.
// @include      /^https?\:\/\//
// @grant        none
// @run-at       document-start
// @namespace https://greatest.deepsurf.us/users/371179
// ==/UserScript==
"use strict";
(function() {
    var wasRun = false;

    var cssStyle = '*, body *, div, span, body *::before, body *::after, *:hover, *:link, *:visited, *:active , *[style], *[class]{' +
        '-webkit-touch-callout: text !important; -webkit-user-select: text !important; ' +
        '-khtml-user-select: text !important; -moz-user-select: text !important; ' +
        '-ms-user-select: text !important; user-select: text !important;}' +
        'html body *:hover>img[class][src], html body *:hover>img[style][src]{' +
        'pointer-events:auto;' +
        '}';

    function enableSelectClickCopy() {

        var mKey = 'dqzadwpujtct';
        var enabledSCC = '___enabledSCC_' + mKey + '___';
        var nonFalseFunc = '___nff_' + mKey + '___';
        var rvSCC = '___returnValue_' + mKey + '___';

        if (window[enabledSCC]) return;
        window[enabledSCC] = true;

        Event.prototype.preventDefault = (function(f) {
            var eys = ['copy', 'contextmenu', 'select', 'selectstart', 'dragstart', 'beforecopy'];
            return function() {
                if (eys.indexOf(this.type) >= 0) return;
                return f.apply(this);
            }
        })(Event.prototype.preventDefault);

        var exs = ['copy', 'contextmenu', 'select', 'selectstart', 'dragstart', 'beforecopy'];
        Object.defineProperty(Event.prototype, "returnValue", {

            get() {
                return rvSCC in this ? this[rvSCC] : true;
            },
            set(newValue) {
                if (exs.indexOf(this.type) < 0 && newValue === false) this.preventDefault();
                this[rvSCC] = newValue;
            },
            enumerable: true,
            configurable: true
        });

        var ezs = ['copy', 'contextmenu', 'select', 'selectstart', 'dragstart', 'beforecopy'];
        var eventsCount = ezs.length;

        function universaler(originalFunc) {
            return function wrapFunction(ev) {
                var pName = 'on' + ev.type;
                var func = this[pName];
                if (typeof func == 'function' && func.name == 'wrapFunction') {
                    var res = originalFunc.apply(this, arguments);
                    if (res !== false) {
                        originalFunc[nonFalseFunc] = true;
                        this[pName] = originalFunc;
                        return res;
                    }
                }
            }
        }

        function disableAll(event) {
            var elmNode = event.target
            while (elmNode && elmNode.nodeType > 0) {
                var pName = 'on' + event.type
                var f = elmNode[pName];
                if (f && f[nonFalseFunc] !== true) {
                    var nf = universaler(f);
                    nf[nonFalseFunc] = true;
                    elmNode[pName] = nf;
                }
                elmNode = elmNode.parentNode;
            }
        }


        for (var i = 0; i < eventsCount; i++) {
            var event = ezs[i];
            document.addEventListener(event, disableAll, true);
        }


    }

    function loadedHandler() {
        if (wasRun) return;
        wasRun = true;
        console.log("Select-click-copy Enabler");
        try {
            document.removeEventListener('beforescriptexecute', loadedHandler, true);
            document.removeEventListener('beforeload', loadedHandler, true);
            document.removeEventListener('DOMContentLoaded', loadedHandler, true);
        } catch (e) {}
        appendScript(document);

    }

    function isDocumentObj(x) {
        return x && x.nodeType == 9
    }


    function isHTMLElementObj(x) {
        return x && x.nodeType == 1
    }

    function makeScriptElm(documentObject) {
        if (!isDocumentObj(documentObject)) return null;
        var s = documentObject.createElement('script');
        s.type = 'text/javascript';
        s.innerHTML = '(' + enableSelectClickCopy.toString() + ')()';
        return s
    }

    function appendScript(documentObject) {
        try {
            if (!isDocumentObj(documentObject)) return;
            var container = documentObject.head || documentObject.body;
            if (container) container.appendChild(makeScriptElm(documentObject));
        } catch (e) {}
    }


    function appendCssEnabler(container) {
        if (!isHTMLElementObj(container)) return;
        try {
            var css = document.createElement('style');
            css.type = 'text/css';
            css.innerHTML = cssStyle;
            container.appendChild(css);
        } catch (e) {}
    }

    wasRun = false;

    if (document != null) {

        try {
            enableSelectClickCopy(); //try direct call
        } catch (e) {}

        try {
            if ('onbeforescriptexecute' in document) {
                //for firefox
                document.addEventListener('beforescriptexecute', loadedHandler, true);
            } else {
                //for chrome and opera
                document.addEventListener('beforeload', loadedHandler, true);
            }

        } catch (e) {}

        function onReady() {

            //in case all previous efforts fail
            try {
                loadedHandler();
            } catch (e) {}

            appendCssEnabler(document.documentElement || document.body);
        }

        if (document.readyState !== 'loading') {
            onReady();
        } else {
            document.addEventListener('DOMContentLoaded', onReady);
        }


    }
})();