text: var RTBbg={content:undefined,version:undefined,clsid:"f18e345d-28f1-4a58-8020-60394612b46c",imgDir:"http://image.infoseek.rakuten.co.jp/content/toolbar-platform/chrome/image/client/",toolid:1,loginCheckTime:1000*60*30,loadTime:1000*3600*24,timeout:10000,messageReadTime:60*30*1000,opendTab:undefined,waitTime:300,waitCount:0,init:function(){$.ajaxSetup({timeout:this.timeout});this.checkLogin();this.changeIcon();this.setDefault();this.prepareLoad();if(localStorage.tbuid){this.getRtbSess(localStorage.tbuid)}this.checkVersion(RTBbg.getTgmCount)},setDefault:function(){if(localStorage.rtbAdded!=2){localStorage.rtbAdded=2;this._openTabs();chrome.tabs.create({url:"http://websearch.rakuten.co.jp/static/chrome/install.html"})}},_openTabs:function(){chrome.tabs.create({url:"http://websearch.rakuten.co.jp/"},function(a){RTBbg.opendTab=a.id;RTBbg._preCloseTab()})},_preCloseTab:function(){if(this.waitCount<this.waitTime&&this.opendTab!=null){chrome.tabs.sendMessage(RTBbg.opendTab,{method:"closeTab"},function(a){RTBbg._setTimeout(RTBbg._closeTab,null,3000)});this.waitCount++;RTBbg._setTimeout(RTBbg._preCloseTab,null,100)}else{RTBbg._closeTab()}},_closeTab:function(){if(RTBbg.opendTab!=null){chrome.tabs.remove(RTBbg.opendTab);RTBbg.opendTab=null}},getSubwindow:function(){if(localStorage.isRakutenAsDefault=="true"||!localStorage.isRakutenAsDefault){var a=1}else{if(localStorage.isRakutenAsDefault=="false"){var a=0}}RTBbg.popupUrl="http://websearch.rakuten.co.jp/extension/subwindow";RTBbg.popupUrl+="?sp="+a;RTBbg.popupUrl+="&version="+RTBbg.version;RTBbg.popupUrl+="&tbuid="+localStorage.tbuid;RTBbg.popupUrl+="&t=chrm";RTBbg.viewContent();this.checkLogin();this.getTgmCount()},getTgmCount:function(){var a=new Date();$.ajax({url:"http://msg.websearch.rakuten.co.jp/view/MsgApiGetMessageCount?version="+RTBbg.version+"&datetime="+a.getTime()+"&tuid="+localStorage.tbuid+"&callback=jQuery",type:"GET",success:function(b){b=(b.match(/\(([^\)]+)\)/)||[])[1];b=JSON.parse(b);localStorage.messageReadTime=a.getTime();if(b.header.status=="Success"){if(b.header.islogin&&b.body.messageCount>10){chrome.browserAction.setBadgeText({text:String("10+")});chrome.browserAction.setBadgeBackgroundColor({color:[100,100,100,255]})}else{if(b.header.islogin&&b.body.messageCount>0){chrome.browserAction.setBadgeText({text:String(b.body.messageCount)});chrome.browserAction.setBadgeBackgroundColor({color:[100,100,100,255]})}else{chrome.browserAction.setBadgeText({text:String("")})}}}else{chrome.browserAction.setBadgeText({text:String("")})}},error:function(b){chrome.browserAction.setBadgeText({text:String("")})}})},checkLogin:function(){$.ajax({url:"http://websearch.rakuten.co.jp/json/user",type:"GET",dataType:"json",success:function(a){var b=new Date();localStorage.loginCheckTime=b.getTime();if(a.status=="true"){localStorage.login="1";RTBbg.changeIcon()}else{if(a.status=="false"){localStorage.login="0";RTBbg.changeIcon()}}},error:function(a){}})},changeIcon:function(){if(localStorage.isRakutenAsDefault==="false"){if(localStorage.login==="1"){chrome.browserAction.setIcon({path:RTBbg.imgDir+"icon_login0.png"});localStorage.currentIcon="icon_login0.png"}else{chrome.browserAction.setIcon({path:RTBbg.imgDir+"icon_logout0.png"});localStorage.currentIcon="icon_logout0.png"}}else{if(localStorage.login==="1"){chrome.browserAction.setIcon({path:RTBbg.imgDir+"icon_login1.png"});localStorage.currentIcon="icon_login1.png"}else{chrome.browserAction.setIcon({path:RTBbg.imgDir+"icon_logout1.png"});localStorage.currentIcon="icon_logout1.png"}}},checkVersion:function(a){if(this.version){if(a){a()}}else{$.ajax({url:"manifest.json",type:"GET",success:function(b){RTBbg.version=b.match(/"version": "([^"]+)"/)[1];if(a){a()}},error:function(b){}})}},prepareLoad:function(){if(localStorage.uuid&&localStorage.tbuid){if(!localStorage.callLoad){this.checkVersion(this._callLoad)}else{try{var a=JSON.parse(localStorage.callLoad);if(a.time!==RTBbg._getDateString()){this.checkVersion(this._callLoad)}else{if(a.login=="0"&&localStorage.login=="1"){this.checkVersion(this._callLoad)}}}catch(b){delete localStorage.callLoad}}}},_callLoad:function(){if(localStorage.login=="1"){var a=1}else{var a=0}$.ajax({url:"http://xml2.toolbar.rakuten.ne.jp/",type:"GET",dataType:"JSON",data:{action:"load_extension",client:"chrome",m:localStorage.uuid,g:RTBbg.clsid,toolid:RTBbg.toolid,userid:localStorage.tbuid,v:RTBbg.version,login:a},success:function(b){var c={time:RTBbg._getDateString(),login:localStorage.login};localStorage.callLoad=JSON.stringify(c)},error:function(b){}})},_getDateString:function(){var a=new Date();yyyy=a.getFullYear();mm=a.getMonth()+1;dd=a.getDate();if(mm<10){mm="0"+mm}if(dd<10){dd="0"+dd}return yyyy+"/"+mm+"/"+dd},viewContent:function(){var a=chrome.extension.getURL("popup.html");var c=chrome.extension.getViews();for(var d=0;d<c.length;d++){var b=c[d];if(b.location.href==a){b.viewContent()}}},getRtbSess:function(a){$.ajax({url:"http://websearch.rakuten.co.jp/xml/user",type:"GET",dataType:"JSON",data:{tool_id:"1",userid:a},success:function(b){},error:function(b){}});this._setTimeout(RTBbg.checkLogin,null,1000);this._setTimeout(RTBbg.checkVersion,RTBbg.getTgmCount,1000)},_setTimeout:function(c,b,a){if(b){window.setTimeout(function(){c(b)},a)}else{window.setTimeout(function(){c()},a)}}};RTBbg.init();chrome.extension.onRequest.addListener(function(f,c,a){if(f.method=="default"){localStorage.isRakutenAsDefault=f.value}else{if(f.method=="getTbuid"){$.ajax({url:"http://xml2.toolbar.rakuten.ne.jp/",type:"GET",data:{action:f.action,client:f.client,m:f.m,g:f.g,toolid:f.toolid},success:function(h){if(h.match(/'userid':'(\d+)'/)){h=RegExp.$1;localStorage.tbuid=h;a({tbuid:h})}},})}else{if(f.method=="saveTbuid"){localStorage.tbuid=f.value}else{if(f.method=="checkLogin"){RTBbg.checkLogin();RTBbg.checkVersion(RTBbg.getTgmCount);if(localStorage.tbuid){RTBbg.getRtbSess(localStorage.tbuid)}}else{if(f.method=="checkLoginOnly"){RTBbg.checkLogin();RTBbg.checkVersion(RTBbg.getTgmCount)}else{if(f.method=="checkLoginTimer"){var b=new Date();if(!localStorage.loginCheckTime||b.getTime()-localStorage.loginCheckTime>RTBbg.loginCheckTime){RTBbg.checkLogin()}}else{if(f.method=="loaded"){RTBbg.changeIcon();RTBbg.prepareLoad();var b=new Date();if(!localStorage.messageReadTime||(b.getTime()-localStorage.messageReadTime)>RTBbg.messageReadTime){RTBbg.checkVersion(RTBbg.getTgmCount)}}else{if(f.method=="uuid"){localStorage.uuid=f.value}else{if(f.method=="deleteSpFlag"){delete localStorage.isRakutenAsDefault;RTBbg.checkLogin()}else{if(f.method=="messageListUpdate"){RTBbg.checkVersion(RTBbg.getTgmCount)}else{if(f.method=="opensetting"){chrome.tabs.create({url:"http://websearch.rakuten.co.jp/"});var g;var e;var d="chrome://chrome/settings/searchEngines";chrome.windows.create({url:d},function(j){g=j.id;for(var h=0;h<j.tabs.length;h++){if(j.tabs[h].url==d){e=j.tabs[h].id;break}}if(e){chrome.windows.getCurrent(function(i){if(i.id==g){chrome.tabs.update(e,{active:true});chrome.tabs.reload(e)}})}})}else{if(f.method=="getRtbSess"){RTBbg.getRtbSess(f.userid)}}}}}}}}}}}}});var TAGEME_URL="http://msg.websearch.rakuten.co.jp/view/html/clientframe_redirect.html";chrome.tabs.onCreated.addListener(function(a){var b=function(c){chrome.tabs.get(c,function(d){if(d.url==""){RTBbg._setTimeout(b,d.id,10)}else{if(d.url.indexOf(TAGEME_URL)!=-1){chrome.tabs.update(d.id,{active:true})}}})};b(a.id)});chrome.omnibox.onInputEntered.addListener(function(a){chrome.tabs.update({url:"http://websearch.rakuten.co.jp/Web?tool_id=1&ref=chext&qt="+a})});