home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************
-
- === 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 17-11-2005
-
- === Description of weather.js ===
-
- Here are the variables declared and the main functions.
-
-
- ***************************************************************************************/
-
- var SECURITY_ID = max_security_id
- var PLUGIN_NAME = "Weather"
-
- var alreadyShowingError = false
- window.onerror = ShowError
-
- function ShowError(msg,url,line){
- var d = new Date()
- var date = d.getHours().toString()+':'+d.getMinutes().toString()+':'+d.getSeconds().toString()
- if(!alreadyShowingError) external.get_tab(SECURITY_ID,external.cur_sel).window.status
- = 'Message: '+msg+' Line: '+line+' URL: '+url+' Date: '+date
- alreadyShowingError = true
- }
-
- checkIfIniFileExists()
-
- var activeLocation = readIni("Number")
- if(activeLocation=='')
- activeLocation = '1'
- var locationId = readIni("LocationCode"+activeLocation)
- var activeCityName = readIni("LocationTxt"+activeLocation,'? , ?')
- var units = readIni("units").replace(/1/,'Celcius').replace(/0/,'Fahrenheit')
- if(units=='')
- units = 'Celcius'
- var futdays = readIni("FutureDays",'8');
- var details = readIni("showDetails",'1')
- var design = readIni("design")
- var detlink = readIni("DetailsLink")
- var style = readIni("StyleName")
- var iconExtension = readIni("IconExtension")
- var fontsize = readIni("FontSize","MediumFonts.css")
- var type = readIni('Type','Summary').replace(/0/,'Summary').replace(/1/,'Future').replace(/2/,'Today')
- var showTodayDate = readIni('ShowDate','0')
- var compactDisplay = readIni('compactDisplay','1')
- var showWinAlways = readIni('showFloatingWindow','0')
- var numberOfCities = readIni('numberOfCities','3')
- var titleAlign = readIni('TitleAlign','left')
- var imageLocation = readIni('ImageSet','Type1_25')+'/'
- var use24Hours = readIni('24Hours','1')
- var disableTooltips = readIni('DisableTooltips','0')
- try{
- var interval = eval(readIni("Interval"));
- }
- catch(err){
- var interval = 9999
- }
- var QuantLength = readIni("QuantityLength",'2')
- if(QuantLength == 0)
- compact = 0
- else compact = 1
- var pluginfolder = external.m2_plugin_folder(SECURITY_ID,PLUGIN_NAME);
- var name = 'Weather'
- var languageFile = getCurrentLanguage()
- var cityTra = readFile("language/Language"+languageFile+".ini").toLowerCase().split('\r\n')
- var errorMsg1 = trans('WT_error')+'<br><a href="'+scriptURL+'" target=_blank>'+locationId+'</a><br>'+trans('WT_errorconn')
- var errorMsg2 = trans('WT_error')+'<br><a href="'+scriptURL+'" target=_blank>'+locationId+'</a><br>'+trans('WT_errorsupp')
- var errorMsgCached = '<b>'+trans('WT_noupdate')+'</b>'
- var topicMsg = '<span style="cursor:hand" title="'+trans("WT_ForumTopic")+
- '" onclick="window.open(\'http://forum.maxthon.com/forum/index.php?showtopic=22354\')">Weather 4.41</span>'
- if(units == 'Fahrenheit')
- var unitsSym = ['F', trans('WT_mph'), trans('WT_mile'), trans('WT_inches')]
- else var unitsSym = ['C', trans('WT_kmh'), trans('WT_km'), trans('WT_hPa')]
- var monthname = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
- var scriptURL,
- dataall = 0,
- couldNotLoad = false,
- goAnyway = false
- data = new Array()
- var smallWindow = ''
-
- try{
- objXMLHTTP = external.max_activex(SECURITY_ID,"Microsoft.XMLHTTP")
- } catch(err) {
- objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
- }
-
- //constants
-
- var IMG_LOCATION_MODDIALOG = readIni('imageLocationFloatingWindow','Type2_45/')
- var FONT_SIZE_MODDIALOG = 'SmallFonts.css'
- var WEBPAGE_SUM = 'http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid='
- var WEBPAGE_FUT = 'http://www.weather.com/weather/mpdwcr/tenday?locid='
- var WEBPAGE_TODAY = 'http://www.weather.com/weather/mpdwcr/dailydetails?locid='
- var WEBPAGE_LOCATION_SEARCH = 'http://xml.weather.com/search/search?where='
-
- document.write('<link href="style/'+style+'" rel="stylesheet" type="text/css">')
- document.write('<link href="style/'+fontsize+'" rel="stylesheet" type="text/css">')
- document.write('<style>.titleleft{text-align:'+titleAlign+' !important;}</style>')
-
- for(i=0;i<=numberOfCities;i++){
- eval('city'+i+' = readIni("LocationTxt'+i+'","? , ?")')
- }
-
- /*If no location is set */
-
- if(locationId == '') locationId = 'NLXX0016'
-
-
- function goAgain(dataall){
- top.dataall = dataall
- getDat()
- restart()
- showErrorMessage('')//remove old error messages
- }
-
- /*The data received from weather.com (summary)
-
- function makeWeatherObj() { this.swCity = "Hong Kong"; this.swSubDiv = ""; this.swCountry = "China"; this.swRegion = "Asia"; this.swTemp = "84"; this.swTempCel =
- Math.round((5/9)*(this.swTemp-32)); this.swCIcon = "27"; this.swWindS = "17"; this.swWindD = "SSW"; this.swBaro = "29.68"; this.swHumid = "79"; this.swReal = "94"; this.swUV = "0"; this.swVis =
- "6.21"; this.swLastUp = "06/18/2005 07:00:00"; this.swConText = "Mostly Cloudy"; this.swFore = "7|1|2|3|4| 06/18/2005|06/19/2005|06/20/2005|06/21/2005|06/22/2005| 38|38|38|38|38|
- 28|66|28|28|28| 88|89|89|89|87| 60|60|60|60|60| 47|47|47|47|47| 28|28|28|28|28| 82|82|82|81|80|"; this.swAcid = "ChXX0049"; }*/
-
- /*Show the last update of the weather.com data */
-
- function lastUpdateTime() {
- try{
- var text="<a href='"+detlink+
- locationId+"' target=_blank title='"+trans("WT_DetLinkTitle")+"'>"+trans("WT_DetLink")+"</a><br>"+
- trans("WT_Lastupdate");
- if(design==1) text+='<br>'
- text+=' '+updateTime
- document.all['lastUpdate'].innerHTML = text
- } catch(err){}
- }
-
- /*Change the weather forecast type (summary, 10-day future)*/
-
- function changeType(x){
- writeIni('Type',x)
- if(x == 'Summary') scriptURL = WEBPAGE_SUM+locationId
- else if(x == 'Future') scriptURL = WEBPAGE_FUT+locationId
- else if(x == 'Today') scriptURL = WEBPAGE_TODAY+locationId
- type = x
- goAnyway = true
- reloadPage()
- }
-
- /*Get the correct day */
-
- function getWeekday(n) {
- if(type== 'Summary') n--
- if(n<0) n+=7
- days = ["WT_Sunday","WT_Monday","WT_Tuesday","WT_Wednesday","WT_Thursday","WT_Friday","WT_Saturday"]
- q = trans(days[(n)])
- if(compact==1&&q.length>QuantLength+2) q='<span title="'+q+'">'+q.substring(0,QuantLength+2)+'</span>'
- return q
- }
-
- /*Save the state of the items (today/tomorrow/future) */
-
- function switchstate(item) {
- var key = item.replace(/title/gi,'Show')
- var x = readIni(key)
- if(x == 0) writeIni(key,1)
- else writeIni(key,0)
- ExpandCollapse(item);
- }
-
- /* Shows today's date */
-
- function showDate(x){
- var x=x.replace(/[^0-9,]*/g,'').split(',')
- if(type=='Today' || type=='Future'){
- var month = (eval(x[1])+1).toString()
- if(month.length==1) month='0'+month
- var year = x[0]
- var day = x[2]
- if(day.length==1) day = '0'+day
- }
- else{
- var month = x[0]
- var year = x[2]
- var day = x[1]
- }
- var date = readIni('TodaysDate')
- date = date.replace(/dd/g,day).replace(/mm/g,month).replace(/yyyy/g,year)
- date = date.replace(/yy/g,year.substring(2,4)).replace(/Month/gi,trans('WT_'+monthname[(eval(month)-1)]))
- top.dateToday = date
- }
-
-
- /* Expand/Collapse the items */
-
- function ExpandCollapse(item) {
- var key = item.replace(/title/gi,'Show')
- var x = readIni(key)
- var d = key.replace(/Show/gi,'').toLowerCase()
- if(document.all['title'+d]==null) return
- if(x == 0) {
- document.all['title'+d].src = "images/plus.gif";
- var d=document.all["content"+d]
- if(d[0]) d[0].style.display = "none";
- else d.style.display = "none";
- if(d[1]) d[1].style.display = "none";
- } else {
- document.all['title'+d].src = "images/minus.gif";
- var d=document.all["content"+d]
- if(d[0]) d[0].style.display = "block";
- else d.style.display = "block";
- if(d[1]) d[1].style.display = "block";
- }
- }
-
- /* Expand/Collapse the items on start */
-
- function setExpandCollapseStates() {
- ExpandCollapse("titlenow")
- ExpandCollapse("titletoday")
- ExpandCollapse("titlefuture")
- }
-
- /* Auto-Update the window */
-
- function setAutoUpdate () {
- if(interval==null||interval==9999||interval==0) return;
- else autoUpdateTimer = setTimeout("reloadPage()",1000*60*interval);
- }
-
- function showErrorMessage(message){
- document.all['error'].innerHTML = message
- if(message=='') document.all['error'].style.display='none'
- else document.all['error'].style.display='block'
- }
-
- /* start the retrieveHTML function (located in functionsWeather.js) */
-
- function reloadPage(){
- retrieveHTML(scriptURL)
- }
-
- /* Set the active tab to bold */
-
- function setFontWeight(){
- if(type == 'Future'){
- document.all['futu'].style.fontWeight = 'bold'
- document.all['Summ'].style.fontWeight = 'normal'
- document.all['Tod'].style.fontWeight = 'normal'
- }
- else if(type == 'Summary'){
- document.all['Summ'].style.fontWeight = 'bold'
- document.all['futu'].style.fontWeight = 'normal'
- document.all['Tod'].style.fontWeight = 'normal'
- }
- else if(type == 'Today'){
- document.all['Summ'].style.fontWeight = 'normal'
- document.all['futu'].style.fontWeight = 'normal'
- document.all['Tod'].style.fontWeight = 'bold'
- }
- if(numberOfCities!=1) {
- for(var i=1; i<=numberOfCities; i++){
- if(activeLocation!=i) eval('document.all["city'+i+'"].style.fontWeight = "normal"')
- else eval('document.all["city'+i+'"].style.fontWeight = "bold"')
- }
- }
- //Translate City + Country
- document.all['cityNameDisp'].innerHTML = transLoc(activeCityName)
-
- }
-
- /* Write the city tabs */
-
- function City() {
- var text = ''
- var d = Math.round(100/(eval(numberOfCities)+2))
- if(numberOfCities==1) return
- for(var x=1; x<=numberOfCities; x++){
- text+='<td class=center width="'+d+'%">'+
- '<a id="city'+x+'" href="javascript:ChangeCity('+x+')" '+
- ((activeLocation==x)?'style="font-weight:bold"':'')+
- ' title="'+transLoc(eval('city'+x))+'">'+x+'</a>'+
- '</td>'
- }
- document.write(text)
-
- /*document.write('<a id="city'+x+'" href="javascript:ChangeCity('+x+')" '+((activeLocation==x)?'style="font-weight:bold"':'')+
- ' title="'+transLoc(eval('city'+x))+'">'+x+'</a>')*/
- }
-
- /* Change city if the users clicks 1,2 or 3 */
-
- function ChangeCity(x) {
- writeIni('Number',x)
- activeLocation = x
- if(name=='Config') {
- if(readIni("LocationTxt"+activeLocation)!='')
- document.all['cityNameDisp'].innerHTML=transLoc(readIni("LocationTxt"+activeLocation))
- else document.all['cityNameDisp'].innerHTML='? , ?'
- locationId = readIni("LocationCode"+activeLocation)
-
- for(var i=1; i<=numberOfCities; i++){
- if(activeLocation!=i) eval('document.all["city'+i+'"].style.fontWeight = "normal"')
- else eval('document.all["city'+i+'"].style.fontWeight = "bold"')
- }
- }
- else {
- locationId = readIni("LocationCode"+x)
- if(locationId == '') {
- goConfig()
- document.all['cityNameDisp'].innerHTML='? , ?'
- setFontWeight()
- return
- }
-
- setScriptURL()
- goAnyway=true
- reloadPage()
- }
- }
-
- /* Is called when basic HTML page (weather.htm) finished loading
- this function will start the retrieveHTML function to recieve the weather info
- and set the right tab (in bold) + activeCityName on the HTML page*/
-
- function start(){
- if(languageFile=='0002'||languageFile=='0016') {
- document.body.style.direction='RTL'//set the text alignment for the Arabic and Hebrew languagefiles to right to left
- }
- setFontWeight()
- setScriptURL()
-
- retrieveHTML(scriptURL)
-
- //Blur all links when you click on them, makes everything a bit nicer.
- var allLinks = document.links
- for(var i=0; i<allLinks.length; i++){
- allLinks[i].onfocus=function(){
- this.blur()
- }
- }
-
- //if(disableTooltips == 1) {alert();disableTooltips()}
- }
-
-
- function setScriptURL(){
- if(type == 'Summary') scriptURL = WEBPAGE_SUM+locationId
- else if(type == 'Future') scriptURL = WEBPAGE_FUT+locationId
- else if(type == 'Today') scriptURL = WEBPAGE_TODAY+locationId
- }
-
- /* This function is started when all the data is recieved and loaded (by evaluate) */
-
- function restart(){
- errorMsg1 = trans('WT_error')+'!<br><a href="'+scriptURL+'" target=_blank>'+locationId+'</a><br>'+trans('WT_errorconn')
- errorMsg2 = trans('WT_error')+'!<br><a href="'+scriptURL+'" target=_blank>'+locationId+'</a><br>'+trans('WT_errorsupp')
-
- setFontWeight()
-
- //couldNotLoad is true when an error occures, so the weather data should not be showed, only an error message
- if(!couldNotLoad) {
- loadPage()
- setExpandCollapseStates()
- setAutoUpdate()
- lastUpdateTime()
- } else {
- document.all['mainBody'].innerHTML='<div class=error>'+errorMsg1+'</div>'
- document.all['lastUpdate'].innerHTML=''
- }
- if(disableTooltips == '1') removeTooltips()
- }
-
- function removeTooltips(){
- var allLinks = document.links
- for(var i=0; i<allLinks.length; i++){
- allLinks[i].title = ''
- }
- var allSpanTags = document.getElementsByTagName('span')
- for(var i=0; i<allSpanTags.length; i++){
- allSpanTags[i].title = ''
- }
- var allImages = document.getElementsByTagName('img')
- for(var i=0; i<allImages.length; i++){
- allImages[i].title = ''
- }
- var allTdTags = document.getElementsByTagName('td')
- for(var i=0; i<allTdTags.length; i++){
- allTdTags[i].title = ''
- }
- var allTrTags = document.getElementsByTagName('tr')
- for(var i=0; i<allTrTags.length; i++){
- allTrTags[i].title = ''
- }
- }
-
- /* Go to the configuration page */
-
- function goConfig(){
- showErrorMessage('')
- document.all['configu'].style.display = 'block'
- document.all['mainBody'].style.display = 'none'
- document.all['typelinks'].style.display = 'none'
- document.all['confTD'].disabled = false
- oldLastUpd=document.all['lastUpdate'].innerHTML
- document.all['lastUpdate'].innerHTML = ''
- document.all['configbox'].style.display = 'block'
- document.all['weatherbox'].style.display= 'none'
- document.all['icon1'].src = 'images/sun.gif'
- document.all['icon1'].parentElement.href= 'javascript:goWeather()'
- if(disableTooltips != '1')
- document.all['icon1'].title = trans('WT_Weather')
- document.all['icon2'].parentElement.href= 'javascript:location.reload()'
- readPara()
- if(top.autoUpdateTimer!=null) window.clearInterval(autoUpdateTimer)
- name = 'Config'
- //These 2 lines fix an IE bug. If the configuration is clipped and you go back to the weather data the scrollbar is gone, but the page is still small.
- document.body.style.overflow = 'hidden'
- document.body.style.overflow = 'auto'
- if(smallWindow&&smallWindow!='') smallWindow.window.close()
- }
-
- /* Go to the weather page */
-
- function goWeather(){
- if(locationId=='') goConfig()
- setScriptURL()
- clearRows(resultcontent)
- name = 'Weather'
- document.all['configu'].style.display = 'none'
- document.all['mainBody'].style.display = 'block'
- document.all['mainBody'].innerHTML = trans('WT_loading')
- document.all['typelinks'].style.display = 'block'
- document.all['confTD'].disabled = true
- document.all['lastUpdate'].innerHTML = oldLastUpd
- document.all['configbox'].style.display = 'none'
- document.all['weatherbox'].style.display= 'block'
- document.all['icon1'].src = 'images/config.gif'
- document.all['icon1'].parentElement.href= 'javascript:goConfig()'
- document.all['icon1'].title = trans('WT_Setup')
-
- //These 2 lines fix an IE bug. If the configuration is clipped and you go back to the weather data the scrollbar is gone, but the page is still small.
- document.body.style.overflow = 'hidden'
- document.body.style.overflow = 'auto'
-
- //setAutoUpdate()
- reloadPage()
- }
-
- function nothing(){
- return true
- }
-
- /* Get the Maxthon language, and save it (only the firstRun time you load the plugin, after that it will only load the saved language) */
-
- function getCurrentLanguage(){
- var firstRun = readIni("First")
- if(firstRun=='true') {
- try{
- var languageFile = external.max_language_id;
- }
- catch(err) {
- var languageFile=''
- }
- writeIni('First','false')
- if(external.m2_readIni(SECURITY_ID,PLUGIN_NAME,'/Language/Language'+languageFile+'.ini','Language','WT_Now','err')!='err')
- writeIni('Language',languageFile)
- else writeIni('Language','')
- }
- else var languageFile = readIni('Language')
- if(external.m2_readIni(SECURITY_ID,PLUGIN_NAME,'/Language/Language'+languageFile+'.ini','Language','WT_Now','err')=='err')
- languageFile=''
- return languageFile
- }
-
-
- /* Show the small window */
-
- function showFloatingWindow(){
- smallWindow = external.max_modelessDialog(SECURITY_ID,"script/Dialog.htm",window,"dialogTop:"+readIni('WinTop')+
- "px;dialogLeft:"+readIni('WinLeft')+"px;status:0;help:0;scroll:0;"+
- "resizable:1;dialogHeight:"+readIni('WinHeight')+";dialogWidth:"+readIni('WinWidth')+";center:0;",window);
- document.all['showWinLink'].innerHTML = trans('WT_CloseWin')
- document.all['showWinLink'].href = 'javascript:smallWindow.window.close()'
- }
-
-
- /* Save the window size/position */
-
- function saveCurrentPosition(x,y,z,a){
- writeIni('WinLeft', x-4)
- writeIni('WinTop', y-30)
- writeIni('WinHeight', z)
- writeIni('WinWidth', a)
- smallWindow = ''
- if(document.all['showWinLink']){
- document.all['showWinLink'].innerHTML= trans('WT_OpenWin')
- document.all['showWinLink'].href = 'javascript:showFloatingWindow()'
- }
- }
-
- /*Read/write files */
-
- function readFile(filename) {
- return external.readFile(SECURITY_ID,PLUGIN_NAME,filename)
- }
-
- function writeFile(filename,data) {
- external.writeFile(SECURITY_ID,PLUGIN_NAME,filename,data)
- }
-
- /*Read/Write Settings*/
-
- function readIni(Key, errorResponse) {
- if(errorResponse==null) errorResponse = ''
- returnValue = external.m2_readIni(SECURITY_ID,PLUGIN_NAME,"settings.ini","Settings", Key, 'error')
- if(returnValue == 'error') {
- var defaultFileValue = external.m2_readIni(SECURITY_ID,PLUGIN_NAME,"DefaultSettings.ini","Settings", Key, 'error')
- if(defaultFileValue == 'error')
- return errorResponse
- else {
- //alert(Key+returnValue+defaultFileValue)
- writeIni(Key, defaultFileValue)
- returnValue = defaultFileValue
- }
- }
- return returnValue
- }
-
- function writeIni(Key, Data) {
- external.m2_writeIni(SECURITY_ID,PLUGIN_NAME,"settings.ini","Settings", Key, Data+'')
- }
-
-
- function checkIfIniFileExists(){
- if(readIni('Number','error') != 'error') return
- var defaultSettingsFile = readFile('defaultSettings.ini')
- if(defaultSettingsFile && defaultSettingsFile != '')
- writeFile('settings.ini',defaultSettingsFile)
- }