/* For Z-Blog erx_Weixin [ https://app.zblogcn.com/?id=15900 ] */

try {
	$(function(){
		var erxWeixinDom = `
<div class="erx-weixin-open erx-weixin-copy">
	<div class="erx-wx-box">
		<i class="erxwxiconfont erx-wx-icon-success"></i><h5>复制成功</h5>
		<div class="erx-wx-ow">
			<div class="erx-wx-ts">微信号: <em>86664722</em><br>外挂软件添加微信号</div>
			<a href="weixin://" class="erx-wx-close erx-wx-btn">我知道了</a><img src="http://hc.jgz99.com/zb_users/plugin/erx_Weixin/img/add_demo.gif" class="add-ez">		</div>
		<span class="erx-wx-close erxwxiconfont erx-wx-icon-close"></span>
	</div>
</div>
<div class="erx-weixin-ball erx-wx-show" title="外挂软件添加微信号" style="bottom:100px;" data-clipboard-text="86664722"><i class="erxwxiconfont erx-wx-icon-weixin"></i></div>
<div class="erx-weixin-bar erx-weixin-bot"><span class="erx-wx-txt">微信号：<em>86664722</em></span><span class="erx-wx-add erx-wx-show" data-clipboard-text="86664722"><i class="erxwxiconfont erx-wx-icon-weixin"></i>外挂软件添加微信号</span></div>
`, erxWeixinPath = "zb_users/plugin/erx_Weixin/";
		$("body").append(erxWeixinDom);
		if($(".erx-weixin-top").length){
			$("body").prepend('<div class="erx-weixin-blank"></div>');
		}
		if($(".erx-weixin-bot").length){
			$("body").append('<div class="erx-weixin-blank"></div>');
		}
		if($(".erx-wx-tel").length){
			var teldom = $(".erx-wx-tel").children("div"), telnum = teldom.html();
			teldom.html(telnum.replace(/\B(?=(\d{4})+(?!\d))/g, '-'));
			teldom.parent().click(function () {
				$(this).toggleClass("erxact");
			});
		}
		$(".erx-wx-close").click(function () {
			$(".erx-weixin-open").removeClass("erxact");
		});
		$.getScript(typeof(bloghost)=="undefined"?'/':bloghost+erxWeixinPath+"js/clipboard.min.js",function() {
			new ClipboardJS('.erx-wx-show, .erx-weixin-auto .erx-wx-btn').on('success', function(e) {
				$(".erx-weixin-copy").addClass("erxact");
				$(".erx-wx-ow .qrcode-ez").addClass("erxshow");
			}).on('error', function(e) {
				alert('\u590d\u5236\u5931\u8d25\uff01');
			});
		});
		$(".erx-weixin-insert .erx-wx-show").click(function () {
			$(".erx-wx-ow .qrcode-ez").removeClass("erxshow");
		});
		var erxWeixinAutoTimer, erxWeixinAuto_days = $(".erx-weixin-auto").attr("data-cookie")*1;
		erxWeixinAuto();
		$(".erx-wx-icon-close").click(function () {
			erxWeixinAuto();
		});
		$(".erx-weixin-auto .erx-wx-btn, .erx-wx-close.erx-wx-btn").click(function () {
			$(".erx-weixin-auto").removeClass("erxact");
			$(".erx-wx-ow .qrcode-ez").removeClass("erxshow");
			clearTimeout(erxWeixinAutoTimer);
			zbp.cookie.set("erxWeixinAuto", 1, erxWeixinAuto_days);
		});
		function erxWeixinAuto(){
			if($(".erx-weixin-auto").length){
				var atime = $(".erx-weixin-auto").attr("data-time")*1,
					cookie = zbp.cookie.get("erxWeixinAuto");
				if(cookie ==  null){
					erxWeixinAutoTimer = setTimeout(function() {
						if(!$(".erx-weixin-copy").hasClass("erxact")){
							$(".erx-weixin-auto").addClass("erxact");
							$(".erx-wx-ow .qrcode-ez").addClass("erxshow");
						}
					}, atime*1000);
				}
			}
		}
	});
} catch(e) {
	if(!window.jQuery && window.console && window.console.error){
		console.error("很遗憾，微信营销客服插件无法启用！原因是当前主题jQuery加载异常，可能缺失或不规范导致，建议联系主题作者修复或换用其它主题。");
	}
}
