chrome.extension.onRequest.addListener(function(n,t,i){switch(n.type){case"addMonitor":handleAddMonitor(n,i);break;case"removeMonitor":i(handleRemoveMonitor(n));break;case"updateErrorStatus":i(handleUpdateErrorStatus(n));break;case"receiveBargain":(new TimerManager).getTimer("bargain").start();break;case"refuseBargain":(new TimerManager).getTimer("bargain").halt()}});chrome.extension.onConnect.addListener(function(n){switch(n.name){case"retryMonitor":n.onMessage.addListener(function(t){(new FlightMonitorBox).get(t.flightId).flight.getData(config.monitor.retryTimes,!0,function(){delete(new FlightMonitorBox).get(t.flightId).error;(new FlightMonitorBox).persistenceOne(t.flightId);n.postMessage({flightId:t.flightId});handleUpdateErrorStatus()},function(i){(new FlightMonitorBox).get(t.flightId).error=i;(new FlightMonitorBox).persistenceOne(t.flightId);n.postMessage({flightId:t.flightId,error:i})})})}});var handleAddMonitor=function(n,t){var i=FlightFactory.getFromId(n.flightId),r=n.monitor;i.getData(!0,!0,function(){r.time=Util.date.now();r.lastTime=r.time;(new FlightMonitorBox).add(i,r,n.lastShowedPrice).persistence();Util.updateIcon("icons/icon_16.png");(new TimerManager).getTimer("flip").start();(new TimerManager).addTimer(getFlightTimer(n.flightId));(new TimerManager).getTimer(n.flightId).start();$.post("http://api.liebao.cn/flight-extension/qunar/?c=follow_qunar",{from:i.query.from,to:i.query.to,start:Util.date.format(i.query.date[0]),end:Util.date.format(i.query.date[1])});t({status:0})},function(){(new FlightMonitorBox).remove(n.flightId).persistence();t({status:1,error:e})})},handleRemoveMonitor=function(n){return(new FlightMonitorBox).remove(n.flightId).persistence(),(new FlightMonitorBox).getCount()<=0&&(Util.updateIcon("icons/gray.png"),(new TimerManager).getTimer("flip").halt()),(new TimerManager).deleteTimer(n.flightId),handleUpdateErrorStatus(n)},handleUpdateErrorStatus=function(){var n=!1,t=(new FlightMonitorBox).getAll(),i;for(i in t)if(t[i].error!==undefined){n=!0;break}return n===!1?chrome.browserAction.setBadgeText({text:""}):chrome.browserAction.setBadgeText({text:"!"}),{status:n?1:0}}