home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 February / Gamestar_81_2006-02_dvd.iso / Programy / mcombo152.exe / Plugin / Weather / script / getData.js < prev    next >
Text File  |  2005-11-13  |  6KB  |  189 lines

  1. /*************************************************************************************
  2.  
  3. === Weather 4.41 ===
  4.  
  5. By Neo101
  6. Previous versions by crino, Arkim, mdlist, seidenj and Tara
  7. Created for Maxthon Tabbed Browser (www.maxthon.com)
  8.  
  9. === License ===
  10.  
  11. Please contact Neo10 on forum.maxthon.com or www.neo101.nl if you would like to make any changes!
  12. This plugin is for Maxthon only. You are not allowed to use it for any other program without permission.
  13. Do not remove these comments/credits.
  14. You are allowed to use/copy the icons. I did not create them.
  15.  
  16. Copyright 2005
  17.  
  18. Last modified 08-10-2005
  19.  
  20. === Description of getData.js ===
  21.  
  22. Here are the fuctions that get the weather Data (using HTTP Request)
  23.  
  24.  
  25. ***************************************************************************************/
  26.  
  27. /* Set the correct source for the weather information
  28. type 0 = summary, type 1 = 10 day future */
  29.  
  30. function getDat(){
  31.     couldNotLoad=false
  32.     data=new Array()
  33.     activeCityName = readIni("LocationTxt"+activeLocation,'? , ?')
  34.     if(type=='Summary'){ //Sum mode
  35.         scriptURL   = WEBPAGE_SUM+locationId
  36.         dataUnits = 'Fahrenheit'
  37.         sNow        = "WT_Now"
  38.         if(dataall==0) dataall = readFile('cache/summary'+locationId+'.txt')
  39.         if(dataall&&dataall!=''&&dataall!=0) {
  40.             try{
  41.                 eval(dataall.replace(/.*?(function makeWeatherObj.*?}).*/i,'$1').replace(/makeWeatherObj/,'top.makeWeatherObj'))
  42.             }
  43.             catch(err){ alert('Script error! If you are using Proximitron, disable the popup filter.')}
  44.         }
  45.         else couldNotLoad=true
  46.     }
  47.     else if (type=='Future'){ //Future mode
  48.         scriptURL = WEBPAGE_FUT+locationId
  49.         if(dataall==0) dataall=readFile('cache/10daycache'+locationId+'.txt')
  50.         if(dataall==null||dataall=='') {
  51.             document.all['mainBody'].innerHTML=trans('WT_loading')
  52.             couldNotLoad=true
  53.         }
  54.         else {
  55.             dataall=dataall.split('\n')
  56.             a=0
  57.             for(var i=0;i<dataall.length;i++){
  58.                 var b=dataall[i]
  59.                 if(b.search(/new mpdFDObj\(new Date\(/gi)!=-1) {
  60.                     eval(b.replace(/mpdData\['dayf'\].day\[([0-9])\]/g,'data[$1]'))
  61.                     a++
  62.                     if(a==10) break;
  63.                 } else if(b.search(/new mpdLocObj/gi)!=-1) {
  64.                     loc2=b.replace(/.*?new mpdLocObj\((.*)/gi,'$1')
  65.                     var tmp=loc2.split(',')
  66.                     showDate(tmp[5]+','+tmp[6]+','+tmp[7])
  67.                     loc2=tmp[3]+', '+tmp[4]
  68.                 } else if(b.search(/new mpdFObj/gi)!=-1) {
  69.                     dat=b.replace(/.*?new mpdFObj\((.*)/gi,'$1')
  70.                     dat=setClock(dat.split(',')[1])
  71.                 } else if(b.search(/new mpdHeadObj/gi)!=-1){
  72.                     dataUnits=b.replace(/.*new mpdHeadObj\('(.)'.*/gi,'$1').replace(/C/gi,'Celcius').replace(/F/gi,'Fahrenheit')
  73.                 }
  74.             }
  75.         }
  76.     } else if(type=='Today'){ //Today mode
  77.         scriptURL = WEBPAGE_TODAY+locationId
  78.         if(dataall==0) dataall = readFile('cache/today'+locationId+'.txt')
  79.         if(dataall==null||dataall=='') {
  80.             document.all['mainBody'].innerHTML=trans('WT_loading')
  81.             couldNotLoad = true
  82.         }
  83.         else {
  84.             dataall    = dataall.split('\n')
  85.             a        = 0
  86.             sNow    = "WT_Today"
  87.             for(var i=0; i<dataall.length; i++){
  88.                 var b=dataall[i]
  89.                 if(b.search(/new mpdHMHrObj\(new Date\(/gi)!=-1) {
  90.                     eval(b.replace(/mpdData\['HMhour'\].hour\['([0-9])'\]/gi,'data[$1]'))
  91.                     a++
  92.                 } else if(b.search(/new mpdLocObj/gi)!=-1) {
  93.                     loc2=b.replace(/.*?new mpdLocObj\((.*)/i,'$1')
  94.                     var tmp=loc2.split(',')
  95.                     showDate(tmp[5]+','+tmp[6]+','+tmp[7])
  96.                     loc2=tmp[3]+', '+tmp[4]
  97.                 } else if(b.search(/new mpdFObj/i)!=-1) {
  98.                     dat=b.replace(/.*?new mpdFObj\((.*)/i,'$1').replace(/Last Updated /i,'')
  99.                     dat=setClock(dat.split(',')[2])
  100.                 } else if(b.search(/new mpdHeadObj/gi)!=-1){
  101.                     dataUnits=b.replace(/.*new mpdHeadObj\('(.)'.*/i,'$1').replace(/C/i,'Celcius').replace(/F/i,'Fahrenheit')
  102.                 } else if(b.search(/mpdClimoSunRiseSetObj/gi)!=-1){
  103.                     var q=b.replace(/.*?mpdClimoSunRiseSetObj\((.*)\).*/i,'$1').replace(/PM/g,
  104.                         trans('WT_PM')).replace(/AM/g,trans('WT_AM'))
  105.                     sunUp=setClockSun(q.split(',')[0].replace(/'/g,''))
  106.                     sunDown=setClockSun(q.split(',')[1].replace(/'/g,''))
  107.                 } else if(b.search(/mpdFDPObj/i)!=-1){
  108.                     eval(b.replace(/mpdData\['dayPartFcst'\].day\[0\]/gi,'tempData'))
  109.                 }
  110.             }
  111.         }
  112.     }
  113. }
  114.  
  115. function evaluate(dataall,x){
  116.     if(name == 'Weather'){
  117.         if(dataall==0) {
  118.             top.dataall=0
  119.             getDat()
  120.             restart()
  121.             showErrorMessage(errorMsgCached+' <a href="'+scriptURL+'" target=_blank>x</a>')
  122.         }
  123.         else if(type=='Summary'&&dataall.search(/makeWeatherObj/gi)!=-1) {
  124.                 writeFile('cache/summary'+locationId+'.txt',dataall)
  125.                 goAgain(dataall)
  126.         }
  127.         else if(type=='Future'&&dataall.search(/new mpdFDObj/gi)!=-1) {
  128.                 writeFile('cache/10daycache'+locationId+'.txt',dataall)
  129.                 goAgain(dataall)
  130.         }
  131.         else if(type=='Today'&&dataall.search(/new/gi)!=-1){
  132.                 writeFile('cache/today'+locationId+'.txt',dataall)
  133.                 goAgain(dataall)
  134.         }
  135.         else {
  136.             top.dataall=0
  137.             getDat()
  138.             restart()
  139.             showErrorMessage(errorMsgCached+' <a href="'+scriptURL+'" target=_blank>x</a>')
  140.         }
  141.     }
  142.     else{
  143.         if(dataall==0) {
  144.             clearRows(resultcontent)
  145.             addRow(resultcontent,trans('WT_ConnectionSearchErr'))    
  146.             return
  147.         }
  148.         cities = xmlParse(dataall)
  149.         if(cities.length==0||cities[0][0].search(/location provided|unknown error/gi)!=-1) {
  150.             clearRows(resultcontent)
  151.             addRow(resultcontent,trans("WT_Noresult"));        
  152.         } else {
  153.             clearRows(resultcontent)
  154.             addRow(resultcontent,"<B>"+trans("WT_Find1")+" "+cities.length+"<BR>"+trans("WT_Find2")+"</B>")
  155.             for(var i=0; i<cities.length; i++) {
  156.                 rowHTML="<input class=radio type=radio "+((cities.length==1)?'checked':'')+
  157.                         " id=list"+i+" name=listcities value="+cities[i][1]+
  158.                         "><label for=list"+i+"> "+transLoc(cities[i][0])+"</label>"
  159.                 addRow(resultcontent,rowHTML)            
  160.             }
  161.             addRow(resultcontent,"<input class=button type=button value="+trans("WT_Confirm")+" onClick=confirmcity()>")
  162.         }
  163.     }
  164. }
  165.  
  166. /* Get HTML Content */
  167.  
  168. function retrieveHTML(sURL) {
  169.     try{
  170.         
  171.         objXMLHTTP.open("GET", sURL, true);
  172.         objXMLHTTP.onreadystatechange = getHTML
  173.         objXMLHTTP.send();
  174.     } catch(err){alert()
  175.         evaluate(0) 
  176.     }
  177. }
  178.  
  179. /* This function will be called if the updated weather page is loaded */
  180.  
  181. function getHTML() {
  182.     if(objXMLHTTP && objXMLHTTP.readyState==4 && objXMLHTTP.status==200) {
  183.         evaluate(objXMLHTTP.responseText)
  184.         //delete objXMLHTTP
  185.     }
  186.     else if(objXMLHTTP && objXMLHTTP.readyState==4 && objXMLHTTP.status!=200)
  187.         evaluate(0)
  188. }
  189.