You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1 lines
4.1 KiB

!function(){var e={mix:function(e,n){for(var i in n)e[i]=n[i];return e},adapter:function(e,n){for(var i in e)void 0!=n[i]&&(e[i]=n[i]);return e},param:function(e,n){for(var i=[],r=0;r<e.length;r++){var t=e[r];i.push(t+"="+encodeURIComponent(n[t]))}return i},jsonp:function(e){var n=document.getElementsByTagName("head")[0]||document.body,i=document.createElement("script");i.charset=document.charset||document.characterSet||"gb2312",i.src=e;try{n.appendChild(i)}catch(r){}}},n=function(e){this.setConfig(e),this.initWrap(),this.renderWordNum=0,this.frequencyCache={},this.requestUrl=location.protocol+"//entry.baidu.com/rp/bwordcom",this.reqParamWhiteList=["di","user","page_url","logid","title"],this.request()};n.prototype={wraps:[],setConfig:function(n){this.config=e.adapter({di:"",id:[],blueclass:["baidu-blue-word"],user:"",logid:"111",isMobile:!0,title:document.title,page_url:location.href,ignore:"baidu-blue-word-no",frequency:3,maxword:20},n),this.config.id="string"==typeof this.config.id?this.config.id.split(","):this.config.id,this.config.blueclass="string"==typeof this.config.blueclass?this.config.blueclass.split(","):this.config.blueclass},initWrap:function(){for(var e=0;e<this.config.id.length;e++){var n=document.getElementById(this.config.id[e]);n&&this.wraps.push(n)}for(var i=0;i<this.config.blueclass.length;i++){var r=document.querySelectorAll("."+this.config.blueclass[i]);if(r&&r.length>0)for(var t=0;t<r.length;t++)this.wraps.push(r[t])}},request:function(){var n=this,i=e.param(n.reqParamWhiteList,n.config),r="baidu_bw_"+ +new Date;i.push("jsonp="+r),window[r]=function(e){n.response(e);try{delete window[r]}catch(i){}},e.jsonp(n.requestUrl+"?"+i.join("&"))},response:function(e){try{if(0===e.err_no&&e.word_list&&e.word_list.length>0){var n=e.word_list;n=n.splice(0,Math.min(n.length,this.config.maxword)),this.paraminfo=e.param_info,this.render(n)}}catch(i){window.console&&console.log(i)}},render:function(e){for(var n,i=[],r=0,t=e.length;t>r;r++)n=e[r].word,this.frequencyCache[n]=0,i.push(n);for(var o=0;o<this.wraps.length;o++)this.blueword(this.wraps[o],i);this.renderWordNum>0&&this.sendLog({fm:"show",r_type:"render",total_num:i.length,render_num:this.renderWordNum,bwords:JSON.stringify(this.frequencyCache)})},blueword:function(e,n){if(e.nodeType===Node.ELEMENT_NODE){if("A"!==e.nodeName&&e.hasChildNodes())for(var i,r=e.childNodes,t=0;i=r[t++];)this.hasClassName(i,this.config.ignore)||this.blueword(i,n)}else if(e.nodeType===Node.TEXT_NODE){var o=this.filter(e.nodeValue),s=e.parentNode,a=this,c=new RegExp(n.join("|"),"gi");c.test(o)&&(o=o.replace(c,function(e){var n=e.toLowerCase();return a.frequencyCache[n]||(a.frequencyCache[n]=0),a.renderWordNum>=a.config.maxword?e:a.frequencyCache[n]<a.config.frequency?(a.frequencyCache[n]++,a.renderWordNum++,'<a href="'+a.getHref(e)+'" target="_blank">'+e+"</a>"):e}));try{var d=document.createElement("div"),r=d.childNodes;d.innerHTML=o;for(var l=0,h=r.length;h>l;l++){var u=r[l].cloneNode(!0);u.nodeType===Node.ELEMENT_NODE&&(u.onclick=function(){a.sendLog({fm:"click",r_type:"link",r_wd:this.innerHTML})}),s.insertBefore(u,e)}s.removeChild(e)}catch(f){}}},hasClassName:function(e,n){return void 0==e.className||"string"==typeof e.className&&-1===e.className.indexOf(n)?!1:!0},filter:function(e){return e.replace(/</gi,"&lt;").replace(/>/gi,"&gt;")},getHref:function(e){var n=this.paraminfo,i=[];return this.config.isMobile?(n.r_from&&i.push("from="+n.r_from),n.sa&&i.push("sa="+n.sa),"https://m.baidu.com/s?word="+encodeURIComponent(e)+"&"+i.join("&")):(n.r_tn&&i.push("tn="+n.r_tn),n.rsv_dl&&i.push("rsv_dl="+n.rsv_dl),"https://www.baidu.com/s?wd="+encodeURIComponent(e)+"&"+i.join("&"))},sendLog:function(n){var i="//entry.baidu.com/rp/v.gif?",r=e.mix({r_sp:"bword",user:this.config.user,logid:this.config.logid,di:this.config.di,id:this.config.id.join("|"),blueclass:this.config.blueclass.join("|"),page_url:encodeURIComponent(this.config.page_url),title:this.config.title,r_qid:this.paraminfo.r_qid,r_t:+new Date},n),t=[];for(var o in r)r.hasOwnProperty(o)&&t.push(o+"="+r[o]);var s=new Image;s.src=i+t.join("&"),s.onload=s.onerror=function(){s.onload=s.onerror=null,s=null}}},new n(window.baidu_blueword||{})}();