/* |-------------------------------------------------------------------------- | SkyCaiji (蓝天采集器) |-------------------------------------------------------------------------- | Copyright (c) 2018 https://www.skycaiji.com All rights reserved. |-------------------------------------------------------------------------- | 使用协议 https://www.skycaiji.com/licenses |-------------------------------------------------------------------------- */ 'use strict';function SkycaijiCpatternBrowser(){this.consoleId='#skycaiji_console';this.config=null;this.bdNum=0;this.bdNumMax=11} SkycaijiCpatternBrowser.prototype={constructor:SkycaijiCpatternBrowser,init:function(config){var $_o=this;$_o.config=config?config:{};$('#skycaiji_wrapper').attr('skycaiji-console',$($_o.consoleId).prop('outerHTML'));$('#skycaiji_tpl').remove();$('body').append('');$('#skycaiji_tpl').val($('#skycaiji_wrapper').prop("outerHTML"));$('#skycaiji_wrapper').remove();$('*').unbind('click').bind('click',function(){var tagName=$(this).prop('tagName').toLowerCase();if(tagName=='body'||tagName=='html'){return!1} $(this).data('skycaiji-click',$(this).data('skycaiji-click')?0:1);var xpaths=$_o.get_xpaths(this);$($_o.consoleId).remove();$('#skycaiji_wrapper').append($('#skycaiji_wrapper').attr('skycaiji-console'));$($_o.consoleId).show();if(xpaths.xpath){$($_o.consoleId).find('[skycaiji-id="xpath"]').val(xpaths.xpath);if(!xpaths.listXpath){$_o.show_xpath_ele($($_o.consoleId+' [skycaiji-id="show-xpath"]'),xpaths.xpath,$(this).data('skycaiji-click'))}} if(xpaths.listXpath){$($_o.consoleId+' [skycaiji-id="listXpath"]').val(xpaths.listXpath);$($_o.consoleId+' [skycaiji-id="listXpath"]').parents('.skycaiji-block').eq(0).show();$($_o.consoleId+' [skycaiji-id="box-listXpath"]').removeClass('skycaiji-b-c-i');if(xpaths.listXpaths&&xpaths.listXpaths.length>1){var lxSlt=$($_o.consoleId+' [skycaiji-id="listXpaths"]');var sltOptions='';for(var i=xpaths.listXpaths.length-1;i>=0;i--){var lxOption=document.createElement('option');lxOption.value=xpaths.listXpaths[i];lxOption.text=xpaths.listXpaths[i];lxSlt.append(lxOption)} lxSlt.val(xpaths.listXpath);$($_o.consoleId+' [skycaiji-id="box-listXpath"]').addClass('skycaiji-b-c-i');lxSlt.show()} $_o.show_xpath_ele($($_o.consoleId+' [skycaiji-id="show-listXpath"]'),xpaths.listXpath,$(this).data('skycaiji-click'))}else{$($_o.consoleId+' [skycaiji-id="listXpath"]').parents('.skycaiji-block').eq(0).hide()} return!1});$('*').bind('mouseenter',function(e){$(this).addClass('skycaiji_bg')});$('*').bind('mouseout',function(){$(this).removeClass('skycaiji_bg')});$('body').on('mouseover','#skycaiji_tips',function(){$(this).stop().fadeIn().css('box-shadow','2px 2px 2px #999')});$('body').on('mouseleave','#skycaiji_tips',function(){if($(this).find('.skycaiji-close').length<=0){$(this).fadeOut(3000)}});$('body').on('click','#skycaiji_tips .skycaiji-close',function(){$('#skycaiji_tips').hide()});$('body').on('click',$_o.consoleId+' .skycaiji-close',function(){$($_o.consoleId).hide()});$('body').on('click',$_o.consoleId+' [skycaiji-id="show-xpath"]',function(){$_o.show_xpath_ele(this,$($_o.consoleId+' [skycaiji-id="xpath"]').val())});$('body').on('click',$_o.consoleId+' [skycaiji-id="show-listXpath"]',function(){$_o.show_xpath_ele(this,$($_o.consoleId+' [skycaiji-id="listXpath"]').val())});$('body').on('click',$_o.consoleId+' [skycaiji-id="xpath"]',function(){$_o.copy_val(this)});$('body').on('click',$_o.consoleId+' [skycaiji-id="listXpath"]',function(){$_o.copy_val(this)});$('body').on('change',$_o.consoleId+' [skycaiji-id="listXpaths"]',function(){var val=$(this).val();if(val){$($_o.consoleId+' [skycaiji-id="listXpath"]').val(val)}});$('body').on('click',$_o.consoleId+' [skycaiji-id="obj-clear"]',function(){$_o.clear_skycaiji_style()});$('body').on('click',$_o.consoleId+' [skycaiji-id="obj-parent"]',function(){var xpath=$($_o.consoleId+' [skycaiji-id="xpath"]').val();var csspath=$_o.xpath2csspath(xpath);if($(csspath).parent().length>0){$(csspath).parent().eq(0).click()}else{$_o.tips('没有了',1500)}});$('body').on('click',$_o.consoleId+' [skycaiji-id="obj-child"]',function(){var xpath=$($_o.consoleId+' [skycaiji-id="xpath"]').val();var csspath=$_o.xpath2csspath(xpath);if($(csspath).children().length>0){$(csspath).children().eq(0).click()}else{$_o.tips('没有了',1500)}});$('body').on('click',$_o.consoleId+' [skycaiji-id="obj-prop"]',function(){var xpath=$($_o.consoleId+' [skycaiji-id="xpath"]').val();var csspath=$_o.xpath2csspath(xpath);var props=['outerHtml','innerHtml','text','value','id','class','name','href','src','title','alt'];var propVals={};if($(csspath).length>0){for(var i in props){var prop=props[i];var propVal='';if(prop=='innerHtml'||prop=='outerHtml'){if(prop=='innerHtml'){propVal=$(csspath).html()}else{propVal=$(csspath).prop('outerHTML')} propVal=propVal?propVal:'';var regClass=/(class\s*=\s*[\'\"][^\'\"]*?)\s*skycaiji[\w+\-]*/i;var mclass=null;while(mclass=propVal.match(regClass)){propVal=propVal.replace(regClass,mclass[1])} propVal=propVal.replace(/\s*class\s*=\s*[\'\"]\s*[\'\"]/ig,'')}else if(prop=='text'){propVal=$(csspath).text()}else if(prop=='value'){propVal=$(csspath).val()}else if(prop=='class'){propVal=$(csspath).prop('class');propVal=propVal.replace(/\s*skycaiji[\w+\-]*/ig,'').replace(/(^\s*)|(\s*$)/g,'')}else if(prop=='src'||prop=='href'){propVal=$(csspath).attr(prop)}else{propVal=$(csspath).prop(prop)} propVal=propVal?propVal:'';propVals[prop]=propVal} $.each($(csspath)[0].attributes,function(){if(typeof(propVals[this.name])=='undefined'||propVals[this.name]==null){propVals[this.name]=this.value?this.value:''}});if(propVals){var html='';for(var i in propVals){if(propVals[i]){html+='