home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GameStar 2006 February
/
Gamestar_81_2006-02_dvd.iso
/
Programy
/
mcombo152.exe
/
Plugin
/
Weather
/
script
/
convert.js
< prev
next >
Wrap
Text File
|
2005-11-13
|
9KB
|
249 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 14-11-2005
=== Description of convert.js ===
Here are the function that convert units and that translate words
***************************************************************************************/
/* Data from the 10-day forecast
new Date('2005','5','8','0','0','0'),'Tonight','N/A','9','7','27','Mostly Cloudy','14','West Northwest','WNW','0', '74'
data, day , high temp, low temp, ?UV? , icon, weather type, wind speed , wind direction, wind directen short, Precipitation, ?humidity?
*/
/*this function is for the emulation of the data from weather.com (for 10-day forecast), it's stored in an array now*/
function mpdFDObj(a,b,c,d,e,f,g,h,i,j,k,l) {
m = trans('WT_'+monthname[a.getMonth()])+' '+a.getDate()
a = a.getDay()
return [a,b,c,d,e,f,g,h,i,j,k,l,m]
}
/* Data from today's forecast
new Date('2005','7','6','15','0','0'),'11','Light Rain','16','16','80','13','81','From WNW 29 km/h'
data, icon ,weather type, temp, feel like temp, percip , dew point (whatever that is...), humid, wind direction , speed
*/
/*this function is for the emulation of the data from weather.com (for today's weather), it's stored in an array now*/
function mpdHMHrObj(a,b,c,d,e,f,g,h,i) {
a = a.getHours()
if(use24Hours!=1 && a>12) {
a = a-12
k = ' '+trans('WT_PM')
}
else if(use24Hours!=1) k = ' '+trans('WT_AM')
else k = ':00'
var t = i.replace(/From /i,'').split(' ')
i = t[0]
j = t[1]
return [a,b,c,d,e,f,g,h,i,j,k]
}
/* for today/tonight weather
new Date('2005','7','6','0','0','0'),'Today','18','11','5 Moderate','11','Showers','29','West Northwest','WNW','90', '84', '11', 'Showers', '24', 'Northwest', 'NW', '80', '90'); //19 items
new Date('2005','7','6','0','0','0'),'Tonight','21','12','6 High','30','Partly Cloudy','11','West Northwest','WNW','10', '74', '26', 'Cloudy', '11', 'West Northwest', 'WNW', '20', '82');
data, day, temp day, temp night, UV, icon, weather type, wind speed, wind direction, wind dir short, precip, humid, icon, weather type, wind speed, wind direction, wind dir short, percip, humid
todayData= temp day0, UV1, icon2, weather type3, wind speed4, wind direction5, wind dir short6, precip7, humid8,
tonightData= temp night0, ico1n, weather type2, wind speed3, wind direction4, wind dir shor5t, percip6, humid7
*/
function mpdFDPObj(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) {
if(e&&e.search(/ /)!=-1) e = e.split(' ')[0]
todayData = [c,e,f,g,h,i,j,k,l]
tonightData = [d,m,n,o,p,q,r,s]
}
/*Convert Units*/
function transUnit(value,name) {
if(value=='' || value=='N/A' || value==undefined) return 'N/A '
if(dataUnits==units && name!='temp') return Math.round(value)
else if(dataUnits == units) return Math.round(value)+"°"+unitsSym[0]
var returnvalue=''
if(dataUnits=="Fahrenheit" && units=="Celcius") {
switch (name) {
case "temp": returnvalue = ((5/9)*(value-32)); break;
case "wind": returnvalue = (value*1.609334); break;
case "pres": returnvalue = value*33.86389; break;
case "visb": if(value == 999) return "INF ";
else returnvalue = value*1.609334; break;
}
}
else {
switch (name) {
case "temp": returnvalue = (value*1.8)+32; break;
case "wind": returnvalue = (value/1.609334); break;
case "pres": returnvalue = value/33.86389; break;
case "visb": if(value == 999) return "INF ";
else returnvalue = value/1.609334; break;
}
}
returnvalue = Math.round(returnvalue);
if(name=="temp") return returnvalue+"°"+unitsSym[0]
else return returnvalue
}
/* Sets the update time, with AM/PM / 24h conversion*/
function setClock(x){
if(type=='Future' || type=='Today') {
x = x.replace(/'/g,'')
var timeZone= x.replace(/.*?M /g,'')
var time = x.replace(timeZone,'')
if(time.search(/PM/)!=-1 && use24Hours==1){
var y = time.split(':')
if(y[0] == 12) y[0] = 0
time = (eval(y[0])+12)+':'+y[1].replace(/PM/,'')
} else if(time.search(/AM/)!=-1 && use24Hours==1) {
time = time.replace(/AM/,'')
}
} else{
var zone = eval(readIni("TimeZone"))
var dst = eval(readIni("DSTtime"))
var time = x.substring(0,5)
var hour = eval(time.split(':')[0])
var yhour= ((hour) + (zone) + (dst) + 6);
if(yhour < 0) yhour = yhour+24;
if(yhour >= 24) yhour = yhour-24;
if(use24Hours==0) {
if(yhour<=12) q = 'AM'
else {
yhour -= 12
q = 'PM'
}
} else q = ''
if(yhour <= 9) yhour = "0"+yhour;
if(zone>0) zone = '+'+zone
else if(zone==0) zone = ''
var timeZone = "GMT"+zone+""
time = ' '+yhour+':'+time.split(':')[1]+' '+q
}
//Remove the next line if you don't like the short TimeZone
if(timeZone.search(/Local|GMT/)==-1) timeZone = timeZone.replace(/[^A-Z]*/g,'')
updateTime = time.replace(/PM/g,trans('WT_PM')).replace(/AM/g,trans('WT_AM'))+' '+
timeZone.replace(/local time/gi,trans('WT_LocalTime'))
}
/* Convert Sun UP/Down to 12h/24h */
function setClockSun(time){
if(use24Hours==0) {
return time
} else{
if(time.search(/PM/)!=-1){
var y=time.split(':')
time=(eval(y[0])+12)+':'+y[1].replace(/ PM/,'')
} else if(time.search(/AM/)!=-1) time=time.replace(/ AM/,'')
return time
}
}
/* Translation */
function trans(WTwords, addChar) {
var text = external.m2_readIni(SECURITY_ID, PLUGIN_NAME,"/language/Language"+languageFile+".ini","Language", WTwords, '')
if(text=='') text = external.m2_readIni(SECURITY_ID, PLUGIN_NAME,"/language/Language.ini","Language", WTwords, 'error')
if(addChar && compact==1) {
if(text.length > QuantLength) text = '<span title="'+text+'">'+text.substring(0,QuantLength)+'</span>'
}
if(addChar) text += ': '
return text
}
function translate(WTwords) {
var tr = external.m2_readIni(SECURITY_ID, PLUGIN_NAME,"/language/Language"+languageFile+".ini","Language", WTwords, '')
if(tr=='') tr = external.m2_readIni(SECURITY_ID, PLUGIN_NAME,"/language/Language.ini","Language", WTwords, 'error')
if(tr=='error') tr = WTwords.replace(/WT_/gi,'')
document.write(tr)
}
/* Translate weather types */
function transW(x) {
var w = external.m2_readIni(SECURITY_ID, PLUGIN_NAME,"/language/Language"+languageFile+".ini","WeatherTypes",'WF_'+x, '')
if(w.search(/\S{20}/)>=0) w = w.substring(0,10)+'<br>'+w.substring(11)
if(w=='') return x
else return w
}
/* Translate wind directions */
function transWind(x,y){
var d=x.replace(/N/g,trans('WT_North_Short')).replace(/S/g,trans('WT_South_Short')).
replace(/W/g,trans('WT_west_short')).replace(/E/g,trans('WT_East_Short')).replace(/CALM/g,trans('WT_Calm'))
if(y&&d.length==1) d = ' '+d
else if(y&&d.length==2) d = ' '+d
return d
}
function transWind2(x){
return x.replace(/North/gi,trans('WT_North')).replace(/South/gi,trans('WT_South')).
replace(/West/gi,trans('WT_west')).replace(/East/gi,trans('WT_East')).replace(/CALM/gi,trans('WT_Calm'))
}
function transWind3(x){
return x.replace(/N/g,trans('WT_North')).replace(/S/g,trans('WT_South')).
replace(/W/g,trans('WT_west')).replace(/E/g,trans('WT_East')).replace(/CALM/,trans('WT_Calm'))
}
/* Translate the cities+countries */
function transLoc(x){
try{
var country = x.split(',')[1]
var countryTransl = trans('WT_'+country.replace(/^ /,''))
var city = x.split(',')[0]
var cityTransl = trans('WT_'+city.replace(/^ /,''))
if(countryTransl && countryTransl!='' && countryTransl!='error') x = x.replace(country,' '+countryTransl)
if(cityTransl && cityTransl!='' && cityTransl!='error') x = x.replace(city,' '+cityTransl)
}
catch(err){}
return x
}
/* Translate the cities reverse (for the search, in config) */
function transCity(x,y){
try{
for(i=0; i<cityTra.length; i++){
if(cityTra[i].search(x)!=-1){
var q=cityTra[i].replace(/WT_/i,'').split('=')
if(y&&q[0].search(x)==0) return q[1]
else if(q[1].search(x)==0) return q[0]
}
}
return x
}
catch(err) {
return x
}
}