mirror of
https://github.com/ForkAwesome/Fork-Awesome.git
synced 2024-12-27 14:01:32 +08:00
1 line
20 KiB
JavaScript
1 line
20 KiB
JavaScript
|
var _bsa={init:function(format,zoneKey,segment,options){var options=typeof options!=='undefined'?options:false;var srv=document.createElement('script');srv.id='_bsa_srv-'+zoneKey;srv.type='text/javascript';srv.src=(options&&options.path)?options.path:'//srv.buysellads.com/ads/'+zoneKey+'.json';srv.src=this.appendQueryString(srv.src,'callback','_bsa_go');if(segment)srv.src=this.appendQueryString(srv.src,'segment',segment);if(options&&this.isset(options.ip))srv.src=this.appendQueryString(srv.src,'forwardedip',options.ip);if(!this.isset(window['_bsa_queue']))window['_bsa_queue']=[];if(options&&!this.isset(options.platforms)||!this.isset(options))options.platforms=['desktop','mobile'];if(_bsa[format].readyToInit!=false||(options&&options.testMode)||!_bsa.objExists(zoneKey))window['_bsa_queue'].push([format,zoneKey,segment,options]);if(_bsa[format].readyToInit!=false&&!options.testMode){srv.src+=this.frequencyCap();if(_bsa.objExists(zoneKey))document.getElementsByTagName('head')[0].appendChild(srv)}else if((options&&options.testMode)||!_bsa.objExists(zoneKey))_bsa_go(_bsa[format].testData);else _bsa[format](zoneKey,segment,options)},frequencyCap:function(){var day=_bsa.getCookie('_bsap_daycap'),life=_bsa.getCookie('_bsap_lifecap'),day=this.isset(day)?day.split(';')[0].split(','):[],life=this.isset(life)?life.split(';')[0].split(','):[];if(day.length||life.length){var freqcap=[];for(var i=0;i<day.length;i++){var adspot=day[i];for(var found=-1,find=0;find<freqcap.length&&found==-1;find++)if(freqcap[find][0]==adspot)found=find;if(found==-1)freqcap.push([adspot,1,0]);else freqcap[found][1]++}for(var i=0;i<life.length;i++){var adspot=day[i];for(var found=-1,find=0;find<freqcap.length&&found==-1;find++)if(freqcap[find][0]==adspot)found=find;if(found==-1)freqcap.push([adspot,0,1]);else freqcap[found][2]++}for(var i=0;i<freqcap.length;i++)freqcap[i]=freqcap[i][0]+':'+freqcap[i][1]+','+freqcap[i][2]}if(freqcap&&freqcap.length)return'&freqcap='+encodeURIComponent(freqcap.join(';'));else return''},appendQueryString:function(url,name,value){var re=new RegExp('([?&]'+name+'=)[^&]+','');function add(sep){url+=sep+name+'='+encodeURIComponent(value)}function change(){url=url.replace(re,'$1'+encodeURIComponent(value))}if(url.indexOf('?')===-1){add('?')}else{if(re.test(url)){change()}else{add('&')}}return url},clearQueue:function(){window['_bsa_queue'].shift()},link:function(link){var l=link.split('?encredirect='),time=Date.now()/1000|0,fulllink;if(typeof l[1]!='undefined')fulllink=l[0]+'?segment='+window['_bsa_queue'][2]+';&encredirect='+encodeURIComponent(l[1]);else if(l[0].search('srv.buysellads.com')>0)fulllink=l[0]+'?segment='+window['_bsa_queue'][2]+';';else fulllink=l[0];fulllink=fulllink.replace('[publisher]',window['_bsa_queue'][2]);fulllink=fulllink.replace('[timestamp]',time);return fulllink},drop:function(output,target,elType,idName){var div=document.createElement(elType);div.id=idName;div.innerHTML=output;if(!this.isset(target))where='body';for(i=0;i<document.querySelectorAll(target).length;i++)document.querySelectorAll(target)[i].appendChild(div)},hide:function(e){if(document.getElementById(e)){this.removeClass(document.getElementById(e),'_bsa_show');this.addClass(document.getElementById(e),'_bsa_hide')}},show:function(e){if(document.getElementById(e)){this.removeClass(document.getElementById(e),'_bsa_hide');this.addClass(document.getElementById(e),'_bsa_show')}},close:function(e){this.hide(e);if(this.isset(_bsa.setCookie))_bsa.setCookie(e,'hide',1)},hasClass:function(el,name){return new RegExp('(\\s|^)'+name+'(\\s|$)').test(el.className)},addClass:function(el,name){if(!this.hasClass(el,name))el.className+=(el.className?' ':'')+name},removeClass:function(el,name){if(this.hasClass(el,name))el.className=el.className.replace(new RegExp('(\\s|^)'+name+'(\\s|$)'),' ').replace(/^\s+|\s+$/g,'')},removeEl:function(el){if(typeof el!=='undefined'&&el!=null)el.parentNode.removeChild(el)},isHex:function(c){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(c)},isMobile:function(){var check=false;(function(a){if(/(android|bb\d+|meego).+mobile|a
|