(function(){chrome.extension.onRequest.addListener(function(n){switch(n.ticketEvent){case"login":Storage.remove("mid8BusPop");break;case"refresh":var i=parseInt(n.times,10),t=(new Date).getTime();t>=config.adv.mid8range[0]&&t<config.adv.mid8range[1]&&i>=config.adv.ticketTimes&&Storage.get("mid8BusPop")===null&&(Storage.set("mid8BusPop",t),Storage.set("showStage",{name:"advBusTicket"}),Util.popup(),setTimeout(function(){var n=Storage.get("showStage");n&&JSON.parse(n).name=="advBusTicket"&&Storage.remove("showStage")},5e3))}});var n={},i=/http(s)?:\/\/(.*?\.)?12306.cn(\/.*?)?$/i,t=function(n){return n.url&&i.test(n.url)};chrome.windows.getAll({populate:!0},function(i){for(var u,f,e=function(t){if(n[t]&&(delete n[t],Object.keys(n).length===0)){var i=(new Date).getTime();i<config.adv.mid8range[0]||i>=config.adv.mid8range[1]||i-parseInt(Storage.getWithDefault("mid8PresentPop",10))<config.adv.presentInterval||(Storage.set("mid8PresentPop",i),Storage.set("showStage",{name:"advPresent"}),Util.popup(),setTimeout(function(){var n=Storage.get("showStage");n&&JSON.parse(n).name=="advPresent"&&Storage.remove("showStage")},5e3))}},r=i.length-1;r>=0;r--)for(f=i[r].id,u=i[r].tabs.length-1;u>=0;u--)t(i[r].tabs[u])&&(n[i[r].tabs[u].id]=f);chrome.tabs.onCreated.addListener(function(i){t(i)&&(n[i.id]=i.windowId)});chrome.tabs.onUpdated.addListener(function(i,r,u){t(u)?n[i]=u.windowId:e(i)});chrome.tabs.onRemoved.addListener(function(n){e(n)})})})()