Greasy Fork

Copy Enabler

Disable all copy restriction in Chrome.

目前为 2020-05-18 提交的版本。查看 最新版本

// ==UserScript==
// @name         Copy Enabler
// @namespace    https://tautcony.xyz/
// @license      GPL version 3
// @encoding     utf-8
// @version      0.1
// @description  Disable all copy restriction in Chrome.
// @date         2020/05/18
// @modified     2020/05/18
// @author       TautCony
// @include      *
// @grant        none
// ==/UserScript==


function copyEnabler(curr_window) {
    const eventArr = ['contextmenu', 'dragstart', 'mouseup', 'mousedown', 'mousemove', 'copy', 'cut', 'beforecopy', 'selectstart', 'select', 'keydown'];
    function runScript(curr_window) {
        let _jq_ = curr_window.jQuery || curr_window.$j;
        if (typeof _jq_ !== "undefined" && _jq_.toString().includes("[Command Line API]")) {
            _jq_ = undefined;
        }
        if (typeof _jq_ === "undefined") {
            console.warn("No jQuery found");
        }
        const unbind = function (ele) {
            let listeners = {};
            if (typeof getEventListeners === "function") {
                listeners = getEventListeners(ele);
                /* if (Object.keys(listeners).length > 0) console.log(listeners); */
            }
            for (const evt of eventArr) {
                ele['on' + evt] = null;
                if (_jq_) {
                    const jq_ele = _jq_(ele);
                    if (jq_ele.off) jq_ele.off(evt); else if (jq_ele.unbind) jq_ele.unbind(evt);
                }
                if (ele.style && ele.style.userSelect === 'none') ele.style.userSelect = 'text';
                if (listeners[evt]) {
                    for (const handler of listeners[evt]) {
                        ele.removeEventListener(evt, handler.listener, handler.useCapture);
                    }
                }
                try {
                    if (/frame/i.test(ele.tagName)) {
                        if (ele.src.startsWith(curr_window.location.origin)) {
                            runScript(ele.contentWindow);
                        }
                    }
                } catch (err) {
                    console.error(err);
                }
            }
        };
        [curr_window, curr_window.document].forEach(unbind);
        Array.from(curr_window.document.all).filter(ele => ele.nodeType === Node.ELEMENT_NODE).forEach(unbind);
        (function utanet() {
            const img = document.querySelector('#flash_area>img');
            if (img && img.style) img.style.display = 'none';
        })();
    }
    runScript(curr_window);
}

window.copyEnabler = copyEnabler;
window.ce = () => copyEnabler(window);