(ok)ueditor 复制微信文章图片因防盗链不显示

作者: wxfeng 分类: web前端 发布时间: 2017-04-01 00:00


/**

 * 将如下代码添加进ueditor.all.js即可

 * 微信图片引用插件,解决复制进UEditor的微信图片防盗链的问题
 * @file
 * @since 1.4.3
 */
UE.plugin.register('wximage'function (){
    
    var u = baidu;
    var a = this
      , c = u.editor.ui
      , b = u.editor.dom.domUtils;
    
    function strip_stack_span(html) {
        var docObj = $('<div>' + html + '</div>');
        docObj.find('li,colgroup,a').each(function() {
            if ($.trim($(this).text()) == "" && $(this).find('img').size() == 0) {
                $(this).remove();
            }
        }
        );
        var has_secspan = false;
        do 
        {
            has_secspan = false;
            docObj.find('span:has(span)').each(function(i) {
                var innerobj = $(this).find('> span');
                if (innerobj.size() > 1) {
                    $(this).find('span').each(function() {
                        if ($.trim($(this).text()) == "") {
                            $(this).replaceWith($(this).html());
                        }
                    }
                    )
                    return;
                } 
                else if (innerobj.size() == 0) {
                    return;
                }
                if ($.trim($(this).text()) == $.trim(innerobj.text())) {
                    has_secspan = true;
                    var style = $(this).attr('style');
                    var innserstyle = innerobj.attr('style');
                    var newStyle = '';
                    if (style && style != "") {
                        newStyle += ';' + style;
                    }
                    if (innserstyle && innserstyle != "") {
                        newStyle += ';' + innserstyle;
                    }
                    var new_html = '';
                    $(this).find('> *').each(function() {
                        if (this.tagName == "SPAN") {
                            new_html += $(innerobj).html();
                        } 
                        else {
                            new_html += $(this).prop('outerHTML');
                        }
                    }
                    );
                    $(this).attr('style'newStyle).html(new_html);
                }
            }
            );
        } while (has_secspan);return docObj.html();
    }
    
    a.addListener("beforepaste"function(bcg) {
        b = c.html;
        "function" == typeof strip_stack_span && (b = strip_stack_span(b));
        b = $("<div>" + b + "</div>");
        b.find("img").each(function() {
            var a = ""
              , a = this.src && "" != this.src ? this.src : 
            $(this).attr("data-src");
            $(this).removeAttr("data-src");
            "undefined" == typeof a || "" == a ? $(this).remove() : (a = a.replace(/http:\/\/mmbiz.qpic.cn/g"http://read.html5.qq.com/image?src=forum&q=5&r=0&imgflag=7&imageUrl=http://mmbiz.qpic.cn"),
            a = a.replace(/https:\/\/mmbiz.qpic.cn/g"http://read.html5.qq.com/image?src=forum&q=5&r=0&imgflag=7&imageUrl=https://mmbiz.qpic.cn"),
            a = a.replace(/http:\/\/mmbiz.qlogo.cn/g"http://read.html5.qq.com/image?src=forum&q=5&r=0&imgflag=7&imageUrl=http://mmbiz.qlogo.cn"),
            a = a.replace(/&wxfrom=\d+/g""),
            a = a.replace(/wxfrom=\d+/g""),
            a = a.replace(/&wx_lazy=\d+/g""),
            a = a.replace(/wx_lazy=\d+/g""),
            a = a.replace(/&tp=[a-z]+/g""),
            a = a.replace(/tp=[a-z]+/g""),
            a = a.replace(/\?&/g"?"),
            $(this).attr("src"a),
            $(this).attr("_src"a))
        }
        );
        c.html = b.html()
    }
    );  
});

在展示图片的网页头部加入如下代码:

    <meta name="referrer" content="never">

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注