var adsense = adsense; (function(){ var tbsEngine = !!window.tbsJs || !!window.qb_bridge; //获取广告HTML adsense = function(el,pos){ $.post('/index/Pagejs/s1.html',{ isajax:1, pos:pos, env:{ tbs:tbsEngine?1:0 } },function(json){ if(json.status != 0){ return; } if('html' in json.data){ el.html("
"+json.data.html+"
"); } },"json"); } //检测加载 var checkedAdShowTime = {}; adsense.checkedAdShow = function(reload,elId,time){ var time = time || 2000; time = time?time:2000; if(elId in checkedAdShowTime){ clearTimeout(checkedAdShowTime[elId]); } checkedAdShowTime[elId] = setTimeout(function(){ delete checkedAdShowTime[elId]; if($('#'+elId).find('*').length==0){ //没有加载成功 reload(elId); } },time); } var adReloadIndex = 10000; adsense.adPushReload = {}; //渲染广告 adsense.render = function(el,code,env,pos){ var reload = function(isLoadIndex,elId){ if(elId in checkedAdShowTime){ clearTimeout(checkedAdShowTime[elId]); delete checkedAdShowTime[elId]; } env.loadIndex = env.loadIndex || 0; env.loadIndex++; var q = {}; q[pos] = el; console.log(env); adsense.queue(q,env); } var adi = ++adReloadIndex; adsense.adPushReload[adi] = reload; code = code.replace('__reload__(','adsense.adPushReload['+adi+'](true,'); code = code.replace('__checkad__(','adsense.checkedAdShow(adsense.adPushReload['+adi+'],'); el.html("
"+code+"
"); }; //队列广告 adsense.queue = function(queue,env,callback){ var env = env || {}; env.tbs = tbsEngine?1:0; var callback = callback || function(){} taskQueue.add(function($next){ var posList = []; for(var i in queue){ posList.push(i); } $.post('/index/Pagejs/s2.html?&backintercept=backintercept&&r='+Math.random()+'&PHPSESSID='+getCookie('841534cee2087fb8'),{ isajax:1, pos:posList, env:env },function(json){ callback(); if(json.status != 0){ $next(); return; } for(var pos in json.data){ adsense.render(queue[pos],json.data[pos],$.extend({},env),pos); } $next(); },"json").error(function(){ callback(); $next(); }); }); } var queues = []; adsense.queueAjaxRun = function(){ var obj = queues.length > 0 ? queues[0] : false; if(obj){ adsense.queue(obj.queue,obj.env,function(){ queues.shift(); adsense.queueAjaxRun(); }); } } adsense.queueAjax = function(queue,env){ adsense.queue(queue,env); } //信息流 adsense.informationflow = function(pos,env){ var env = env || {}; env.tbs = tbsEngine?1:0; var ads = []; //初始化信息流 this.init = function(callback){ $.post('/index/Pagejs/s2.html?&backintercept=backintercept&&r='+Math.random()+'&PHPSESSID='+getCookie('841534cee2087fb8'),{ isajax:1, pos:[pos], env:$.extend({informationflow:1},env) },function(json){ if(json.status == 0){ ads = pos in json.data?json.data[pos]:[]; callback(true); }else{ callback(false); } },"json").error(function(){ callback(false); }); } var getCode = function(){ var index = Math.floor(Math.random() * ads.length); index = index<0?0:index; index = index>=ads.length?ads.length-1:index; return ads[index]; } //渲染 this.render = function($el){ if(ads.length > 0){ var code = getCode(); code = code.replace(/__var_random__/g,'abc'+(Math.floor(Math.random() * 9999999)+1000000)); adsense.render($el,code,$.extend({},env),pos); } } } //验证是否显示广告 adsense.check = function(callback){ taskQueue.add(function($next){ var env = env || {}; env.tbs = tbsEngine?1:0; $.post("/index/Pagejs/checkadrule.html?&backintercept=backintercept&"+'&isajax=1&PHPSESSID='+getCookie('841534cee2087fb8'),{env:env},function(json){ if(json.status == 0 && typeof callback == "function"){ callback(); } $next(); },"json").error(function(){ $next(); }); }); } //跳转 adsense.tourl = function(url){ window.location = url; } //弹窗倒计时 var fullwindowDjs = function(djs){djs.remove();return; var t = 5; djs.text(t+'s'); var time = setInterval(function(){ t--; if(t<=0){ djs.remove(); clearInterval(time); return; } djs.text(t+'s'); },1000); } //全窗口显示 adsense.fullWindow = function(url,closeEvent){ if(url.indexOf('http://') != 0 && url.indexOf('https://') != 0){ var $win = $(window); html += ""; $("body").append(html); }else{ var html = "
"; html += ""; html += ""; html += "
"; html = $(html); var $win = $(window); html.width($win.width()); html.height($win.height()); html.find("iframe").css({ height:'100%', width:'100%', background:"url(/static/index/images/loading-2.gif) no-repeat center center" }); html.find('img').on('click',function(){ html.remove(); if(typeof closeEvent == "function"){ closeEvent(); } }); $("body").append(html); fullwindowDjs(html.find('.djs')); } } //关闭 adsense.fullWindow.close = function(){ $(".adsense-fullWindow").remove(); } adsense.alertFullWindow = { close:function(){ $(".adsense-alertFullWindow").remove(); return false; }, show:function(html){ html = '
'+html+'
'; $('body').append(html); fullwindowDjs($('body .adsense-alertFullWindow').last().find('.djs')); if(document.URL.indexOf('__debug__')<=0){ //3秒后开启回收 setTimeout(function(){ var time = setInterval(function(){ console.log(1); if($(".adsense-alertFullWindow .window iframe").length <= 0 && $(".adsense-alertFullWindow .window .iframe").length <= 0){ clearInterval(time); adsense.alertFullWindow.close(); } },60); },6000); } } } //广告点击事件 adsense.clickEvent = function(guid,callback){ taskQueue.add(function($next){ $.post("/index/Pagejs/adclickevent.html?&backintercept=backintercept&"+'&isajax=1&PHPSESSID='+getCookie('841534cee2087fb8'),{guid:guid},function(json){ if(typeof callback == "function"){ callback(json); } $next(); },"josn").error(function(){ $next(); }); }); } //广告曝光事件 adsense.showEventQueue = []; adsense.showEventTime = []; adsense.showEvent = function(guid){ adsense.showEventQueue.push(guid); if(!!adsense.showEventTime){ clearTimeout(adsense.showEventTime); adsense.showEventTime = false; } adsense.showEventTime = setTimeout(function(){ var queue = adsense.showEventQueue; adsense.showEventQueue = []; adsense.showEventTime = false; if(queue.length>0){ taskQueue.add(function($next){ $.post("/index/Pagejs/adshowevent.html?&backintercept=backintercept&"+'&isajax=1&PHPSESSID='+getCookie('841534cee2087fb8'),{guid:queue},function(json){ if(typeof callback == "function"){ callback(json); } $next(); },"josn").error(function(){ $next(); }); }); } },300); } //广告失败事件 adsense.errorEvent = function(){ } if(typeof adsense.onload == "function"){ adsense.onload(); } })();