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 >
Wrap
Text File
|
2005-11-13
|
6KB
|
189 lines
/*************************************************************************************
=== Weather 4.41 ===
By Neo101
Previous versions by crino, Arkim, mdlist, seidenj and Tara
Created for Maxthon Tabbed Browser (www.maxthon.com)
=== License ===
Please contact Neo10 on forum.maxthon.com or www.neo101.nl if you would like to make any changes!
This plugin is for Maxthon only. You are not allowed to use it for any other program without permission.
Do not remove these comments/credits.
You are allowed to use/copy the icons. I did not create them.
Copyright 2005
Last modified 08-10-2005
=== Description of getData.js ===
Here are the fuctions that get the weather Data (using HTTP Request)
***************************************************************************************/
/* Set the correct source for the weather information
type 0 = summary, type 1 = 10 day future */
function getDat(){
couldNotLoad=false
data=new Array()
activeCityName = readIni("LocationTxt"+activeLocation,'? , ?')
if(type=='Summary'){ //Sum mode
scriptURL = WEBPAGE_SUM+locationId
dataUnits = 'Fahrenheit'
sNow = "WT_Now"
if(dataall==0) dataall = readFile('cache/summary'+locationId+'.txt')
if(dataall&&dataall!=''&&dataall!=0) {
try{
eval(dataall.replace(/.*?(function makeWeatherObj.*?}).*/i,'$1').replace(/makeWeatherObj/,'top.makeWeatherObj'))
}
catch(err){ alert('Script error! If you are using Proximitron, disable the popup filter.')}
}
else couldNotLoad=true
}
else if (type=='Future'){ //Future mode
scriptURL = WEBPAGE_FUT+locationId
if(dataall==0) dataall=readFile('cache/10daycache'+locationId+'.txt')
if(dataall==null||dataall=='') {
document.all['mainBody'].innerHTML=trans('WT_loading')
couldNotLoad=true
}
else {
dataall=dataall.split('\n')
a=0
for(var i=0;i<dataall.length;i++){
var b=dataall[i]
if(b.search(/new mpdFDObj\(new Date\(/gi)!=-1) {
eval(b.replace(/mpdData\['dayf'\].day\[([0-9])\]/g,'data[$1]'))
a++
if(a==10) break;
} else if(b.search(/new mpdLocObj/gi)!=-1) {
loc2=b.replace(/.*?new mpdLocObj\((.*)/gi,'$1')
var tmp=loc2.split(',')
showDate(tmp[5]+','+tmp[6]+','+tmp[7])
loc2=tmp[3]+', '+tmp[4]
} else if(b.search(/new mpdFObj/gi)!=-1) {
dat=b.replace(/.*?new mpdFObj\((.*)/gi,'$1')
dat=setClock(dat.split(',')[1])
} else if(b.search(/new mpdHeadObj/gi)!=-1){
dataUnits=b.replace(/.*new mpdHeadObj\('(.)'.*/gi,'$1').replace(/C/gi,'Celcius').replace(/F/gi,'Fahrenheit')
}
}
}
} else if(type=='Today'){ //Today mode
scriptURL = WEBPAGE_TODAY+locationId
if(dataall==0) dataall = readFile('cache/today'+locationId+'.txt')
if(dataall==null||dataall=='') {
document.all['mainBody'].innerHTML=trans('WT_loading')
couldNotLoad = true
}
else {
dataall = dataall.split('\n')
a = 0
sNow = "WT_Today"
for(var i=0; i<dataall.length; i++){
var b=dataall[i]
if(b.search(/new mpdHMHrObj\(new Date\(/gi)!=-1) {
eval(b.replace(/mpdData\['HMhour'\].hour\['([0-9])'\]/gi,'data[$1]'))
a++
} else if(b.search(/new mpdLocObj/gi)!=-1) {
loc2=b.replace(/.*?new mpdLocObj\((.*)/i,'$1')
var tmp=loc2.split(',')
showDate(tmp[5]+','+tmp[6]+','+tmp[7])
loc2=tmp[3]+', '+tmp[4]
} else if(b.search(/new mpdFObj/i)!=-1) {
dat=b.replace(/.*?new mpdFObj\((.*)/i,'$1').replace(/Last Updated /i,'')
dat=setClock(dat.split(',')[2])
} else if(b.search(/new mpdHeadObj/gi)!=-1){
dataUnits=b.replace(/.*new mpdHeadObj\('(.)'.*/i,'$1').replace(/C/i,'Celcius').replace(/F/i,'Fahrenheit')
} else if(b.search(/mpdClimoSunRiseSetObj/gi)!=-1){
var q=b.replace(/.*?mpdClimoSunRiseSetObj\((.*)\).*/i,'$1').replace(/PM/g,
trans('WT_PM')).replace(/AM/g,trans('WT_AM'))
sunUp=setClockSun(q.split(',')[0].replace(/'/g,''))
sunDown=setClockSun(q.split(',')[1].replace(/'/g,''))
} else if(b.search(/mpdFDPObj/i)!=-1){
eval(b.replace(/mpdData\['dayPartFcst'\].day\[0\]/gi,'tempData'))
}
}
}
}
}
function evaluate(dataall,x){
if(name == 'Weather'){
if(dataall==0) {
top.dataall=0
getDat()
restart()
showErrorMessage(errorMsgCached+' <a href="'+scriptURL+'" target=_blank>x</a>')
}
else if(type=='Summary'&&dataall.search(/makeWeatherObj/gi)!=-1) {
writeFile('cache/summary'+locationId+'.txt',dataall)
goAgain(dataall)
}
else if(type=='Future'&&dataall.search(/new mpdFDObj/gi)!=-1) {
writeFile('cache/10daycache'+locationId+'.txt',dataall)
goAgain(dataall)
}
else if(type=='Today'&&dataall.search(/new/gi)!=-1){
writeFile('cache/today'+locationId+'.txt',dataall)
goAgain(dataall)
}
else {
top.dataall=0
getDat()
restart()
showErrorMessage(errorMsgCached+' <a href="'+scriptURL+'" target=_blank>x</a>')
}
}
else{
if(dataall==0) {
clearRows(resultcontent)
addRow(resultcontent,trans('WT_ConnectionSearchErr'))
return
}
cities = xmlParse(dataall)
if(cities.length==0||cities[0][0].search(/location provided|unknown error/gi)!=-1) {
clearRows(resultcontent)
addRow(resultcontent,trans("WT_Noresult"));
} else {
clearRows(resultcontent)
addRow(resultcontent,"<B>"+trans("WT_Find1")+" "+cities.length+"<BR>"+trans("WT_Find2")+"</B>")
for(var i=0; i<cities.length; i++) {
rowHTML="<input class=radio type=radio "+((cities.length==1)?'checked':'')+
" id=list"+i+" name=listcities value="+cities[i][1]+
"><label for=list"+i+"> "+transLoc(cities[i][0])+"</label>"
addRow(resultcontent,rowHTML)
}
addRow(resultcontent,"<input class=button type=button value="+trans("WT_Confirm")+" onClick=confirmcity()>")
}
}
}
/* Get HTML Content */
function retrieveHTML(sURL) {
try{
objXMLHTTP.open("GET", sURL, true);
objXMLHTTP.onreadystatechange = getHTML
objXMLHTTP.send();
} catch(err){alert()
evaluate(0)
}
}
/* This function will be called if the updated weather page is loaded */
function getHTML() {
if(objXMLHTTP && objXMLHTTP.readyState==4 && objXMLHTTP.status==200) {
evaluate(objXMLHTTP.responseText)
//delete objXMLHTTP
}
else if(objXMLHTTP && objXMLHTTP.readyState==4 && objXMLHTTP.status!=200)
evaluate(0)
}