function callBackgroundNoReply(method,args,cb){if(chrome.runtime.sendMessage({method:method,args:args,noReply:!0,refreshActivePage:!0}),cb)return cb()}function callBackground(method,args,cb){chrome.runtime.sendMessage({method:method,args:args},(function(response){return null!=chrome.runtime.lastError?cb&&cb(chrome.runtime.lastError):response.error?cb&&cb(response.error):cb&&cb(null,response.result)}))}var requestInfoCallback=null;OmegaTargetPopup={getState:function(keys,cb){callBackground("getState",[keys],cb)},setState:function(name,value,cb){var newItem={};newItem[name]=value,callBackground("setState",[newItem],cb)},applyProfile:function(name,cb){callBackgroundNoReply("applyProfile",[name],cb)},openOptions:function(hash,cb){var options_url=chrome.runtime.getURL("options.html");console.log("open options....."),chrome.tabs.query({url:options_url},(function(tabs){if(!chrome.runtime.lastError&&tabs&&tabs.length>0){var props={active:!0};if(hash){var url=options_url+hash;props.url=url}chrome.tabs.update(tabs[0].id,props)}else chrome.tabs.create({url:options_url});if(cb)return cb()}))},getActivePageInfo:function(cb){chrome.tabs.query({active:!0,lastFocusedWindow:!0},(function(tabs){if(0===tabs.length||!tabs[0].pendingUrl&&!tabs[0].url)return cb();callBackground("getPageInfo",[{tabId:tabs[0].id,url:tabs[0].pendingUrl||tabs[0].url}],cb)}))},setDefaultProfile:function(profileName,defaultProfileName,cb){callBackgroundNoReply("setDefaultProfile",[profileName,defaultProfileName],cb)},addCondition:function(condition,profileName,cb){callBackground("addCondition",[condition,profileName],cb)},getTempRules:function(cb){callBackground("getTempRules",[],cb)},addTempRule:function(domain,profileName,toggle,cb){"function"==typeof toggle&&(cb=toggle,toggle=null),callBackgroundNoReply("addTempRule",[domain,profileName,toggle],cb)},openManage:function(domain,profileName,cb){chrome.tabs.create({url:"chrome://extensions/?id="+chrome.runtime.id},cb)},getMessage:chrome.i18n.getMessage.bind(chrome.i18n)};