Author Topic: bit off JavaScript  (Read 854 times)

0 Members and 1 Guest are viewing this topic.

Offline dazza

  • Member
  • *
  • Posts: 46
bit off JavaScript
« on: February 01, 2022, 08:13:35 AM »
f
« Last Edit: February 01, 2022, 12:06:52 PM by saratogaWX »

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 8714
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: bit off JavaScript
« Reply #1 on: February 01, 2022, 12:06:28 PM »
I'm not sure what you are asking/commenting on, but that JavaScript is from Version 1.3 09/02/2011 by David Jamieson specifically for Cumulus.  The script makes extensive use of jQuery to do its work, so any page that uses it, would need a jQuery <script> reference before that script is called.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline dazza

  • Member
  • *
  • Posts: 46
Re: bit off JavaScript
« Reply #2 on: February 02, 2022, 05:14:44 AM »
sorry but yh im looking for something like this but with UV etc as my last way work but then it was a litty bug but with my bran i cant get my head around this to work it out!!!! and ive tried so many way to get this working

in the index
 <td><span id="uvword"></span></td>

Code: [Select]

// Set all Rawdata IDs to their values
$("#temp").html(rawdata[2]);
$("#forecastnumber").html(rawdata[48])
$("#uvword").html(rawdata[43])

var uvword = rawdata[43];
   if (UV <= 0) {
       uvword = langUVWords[0];
   } else if (UV < 3) {
       uvword = "<span style=\"border: solid 1px; color: black; background-color: #A4CE6a;\">&nbsp;"+langUVWords[1]+"&nbsp;</span>";
   } else if (UV < 6.0) {
       uvword = "<span style=\"border: solid 1px; color: black; background-color: #FBEE09;\">&nbsp;"+langUVWords[2]+"&nbsp;</span>";
   } else if (UV < 8) {
       uvword =  "<span style=\"border: solid 1px; color: black; background-color: #FD9125;\">&nbsp;"+langUVWords[3]+"&nbsp;</span>";
   } else if (UV < 11) {
       uvword =  "<span style=\"border: solid 1px; color: #FFFFFF; background-color: #F63F37;\">&nbsp;"+langUVWords[4]+"&nbsp;</span>";
   } else {
       uvword =  "<span style=\"border: solid 1px; color: black; background-color: #9999FF;\">&nbsp;"+langUVWords[5]+"&nbsp;</span>";
   }
   return uvword;

}

var langUVWords = new Array (
 "None", "Low", "Medium", "High",
 "Very&nbsp;High", /* be sure to include &nbsp; for space */
 "Extreme" );
}



and my realtimereader.js is what ive adapt the code from ajaxCUwx.js any tips for where have i gone wrong please


Code: [Select]
//
// by David A Jamieson
// daj@findmyinbox.co.uk
//
// Version 1.2 - 12 Jan 2010
//
//
//
// Version 1.3 09/02/2011
//
//
// Edit the next three lines.  The first to note the location of your cumulus realtime.txt file on your web server
// the second line notes how often to refresh the display in seconds. 
var realtime_location="realtime.txt";
var realtime_location_extras="realtimeextras.txt";
var davis_stats_extras="davis_stats.txt";
var update_seconds=15;
var tick_counter=0;
var first_run=1;
setInterval('getlivedata()', 20);
function getlivedata() {
if (tick_counter <= 0) {

// READ REALTIME FILE
//
// Note: The realtime.txt file and parse it using a space
 var d = new Date();
 var realdata = $.ajax({url: realtime_location + "?" + d.getTime(), async: false, dataType: "html" }).responseText;
 var realdataextras = $.ajax({url: realtime_location_extras + "?" + d.getTime(), async: false, dataType: "html" }).responseText;
 var vp2stats = $.ajax({url: davis_stats_extras + "?" + d.getTime(), async: false, dataType: "html" }).responseText;



// if (realdataextras.indexOf(realtime_location_extras) == -1 ) {    // Removed temporarily for HTML strange characters
 var rawdataextras=realdataextras.split("~");
// if (realdata.indexOf(realtime_location) == -1 ) {     // Removed temporarily for HTML strange characters
 var rawdata=realdata.split(' ');
 
// if (davis_stats.indexOf(realtime_location_extras) == -1 ) {    // Removed temporarily for HTML strange characters
 var vp2stats=vp2stats.split("-");

// Set all davisvp2stats IDs to their values
$("#wsforecast").html(vp2stats[6])



// Set all Rawdata IDs to their values
$("#temp").html(rawdata[2]);
$("#forecastnumber").html(rawdata[48])
$("#uvword").html(rawdata[43])

var uvword = rawdata[43];
   if (UV <= 0) {
       uvword = langUVWords[0];
   } else if (UV < 3) {
       uvword = "<span style=\"border: solid 1px; color: black; background-color: #A4CE6a;\">&nbsp;"+langUVWords[1]+"&nbsp;</span>";
   } else if (UV < 6.0) {
       uvword = "<span style=\"border: solid 1px; color: black; background-color: #FBEE09;\">&nbsp;"+langUVWords[2]+"&nbsp;</span>";
   } else if (UV < 8) {
       uvword =  "<span style=\"border: solid 1px; color: black; background-color: #FD9125;\">&nbsp;"+langUVWords[3]+"&nbsp;</span>";
   } else if (UV < 11) {
       uvword =  "<span style=\"border: solid 1px; color: #FFFFFF; background-color: #F63F37;\">&nbsp;"+langUVWords[4]+"&nbsp;</span>";
   } else {
       uvword =  "<span style=\"border: solid 1px; color: black; background-color: #9999FF;\">&nbsp;"+langUVWords[5]+"&nbsp;</span>";
   }
   return uvword;

}

var langUVWords = new Array (
 "None", "Low", "Medium", "High",
 "Very&nbsp;High", /* be sure to include &nbsp; for space */
 "Extreme" );
}






 // Set all IDs to their values
$("#tempTH").html(rawdataextras[0]);
$("#TtempTH").html(rawdataextras[1]);
$("#tempTL").html(rawdataextras[2]);
$("#TtempTL").html(rawdataextras[3]);
$("#apptempTH").html(rawdataextras[4]);
$("#TapptempTH").html(rawdataextras[5]);
$("#apptempTL").html(rawdataextras[6]);
$("#TapptempTL").html(rawdataextras[7]);
$("#feelslikeTH").html(rawdataextras[8]);
$("#TfeelslikeTH").html(rawdataextras[9]);
$("#TfeelslikeTL").html(rawdataextras[10]);
$("#feelslikeTL").html(rawdataextras[11]);
$("#temprange").html(rawdataextras[12]);
$("#avgtemp").html(rawdataextras[13]);
$("#humidexTH").html(rawdataextras[14]);
$("#ThumidexTH").html(rawdataextras[15]);
$("#wchillTL").html(rawdataextras[16]);
$("#TwchillTL").html(rawdataextras[17]);
$("#heatindexTH").html(rawdataextras[18]);
$("#TheatindexTH").html(rawdataextras[19]);
$("#humTH").html(rawdataextras[20]);
$("#ThumTH").html(rawdataextras[21]);
$("#humTL").html(rawdataextras[22]);
$("#ThumTL").html(rawdataextras[23]);
$("#solarTH").html(rawdataextras[24]);
$("#TsolarTH").html(rawdataextras[25]);
$("#SunshineHours").html(rawdataextras[26]);
$("#UVTH").html(rawdataextras[27]);
$("#TUVTH").html(rawdataextras[28]);
$("#wgustTM").html(rawdataextras[29]);
$("#TwgustTM").html(rawdataextras[30]);
$("#windTM").html(rawdataextras[31]);
$("#Tbeaufort").html(rawdataextras[32]);
$("#TwindTM").html(rawdataextras[33]);
$("#windrun").html(rawdataextras[34]);
$("#domwindbearing").html(rawdataextras[35]+rawdataextras[36]);
$("#rfall").html(rawdataextras[37]);
$("#rrateTM").html(rawdataextras[38]);
$("#TrrateTM").html(rawdataextras[39]);
$("#hourlyrainTH").html(rawdataextras[40]);
$("#ThourlyrainTH").html(rawdataextras[41]);
$("#ConsecutiveRainDays").html(rawdataextras[42]);
$("#ConsecutiveDryDays").html(rawdataextras[43]);
$("#pressTH").html(rawdataextras[44]);
$("#TpressTH").html(rawdataextras[45]);
$("#pressTL").html(rawdataextras[46]);
$("#TpressTL").html(rawdataextras[47]);
$("#time").html(rawdataextras[48]);
$("#dewpointTL").html(rawdataextras[49]);
$("#TdewpointTL").html(rawdataextras[50]);
$("#dewpointTH").html(rawdataextras[51]);
$("#TdewpointTH").html(rawdataextras[52]);
$("#winddiricon").html('<img src="images/ajax-images/' + rawdataextras[53] + '.gif"align =center>');
$("#temptrendenglish").html('<img src="images/ajax-images/' + rawdataextras[54] + '.png"align =center>');
$("#presstrendenglish").html('<img src="images/ajax-images/' + rawdataextras[55] + '.png"align =center>');
$("#forecasticons").html('<img src="images/cumulus_icon/forecast_0_'  + rawdata[48] + '.png"align =right>');

 // Calculate the forecast
var fcast = rawdata[48];
if (fcast=="0"){var fdesc="unknown!";} else
if (fcast=="1"){var fdesc="Settled fine";} else
if (fcast=="2"){var fdesc="Fine weather";} else
if (fcast=="3"){var fdesc="Becoming fine";} else
if (fcast=="4"){var fdesc="Fine, becoming less settled";} else
if (fcast=="5"){var fdesc="Fine, possible showers";} else
if (fcast=="6"){var fdesc="Fairly fine, improving";} else
if (fcast=="7"){var fdesc="Fairly fine, possible showers early";} else
if (fcast=="8"){var fdesc="Fairly fine, showery later";} else
if (fcast=="9"){var fdesc="Showery early, improving";} else
if (fcast=="10"){var fdesc="Changeable, mending";} else
if (fcast=="11"){var fdesc="Fairly fine, showers likely";} else
if (fcast=="12"){var fdesc="Rather unsettled clearing later";} else
if (fcast=="13"){var fdesc="Unsettled, probably improving";} else
if (fcast=="14"){var fdesc="Showery, bright intervals";} else
if (fcast=="15"){var fdesc="Showery, becoming less settled";} else
if (fcast=="16"){var fdesc="Changeable, some precipitation";} else
if (fcast=="17"){var fdesc="Unsettled, short fine intervals";} else
if (fcast=="18"){var fdesc="Unsettled, precipitation later";} else
if (fcast=="19"){var fdesc="Unsettled, some precipitation";} else
if (fcast=="20"){var fdesc="Mostly very unsettled";} else
if (fcast=="21"){var fdesc="Occasional precipitation, worsening";} else
if (fcast=="22"){var fdesc="Precipitation at times, very unsettled";} else
if (fcast=="23"){var fdesc="Precipitation at frequent intervals";} else
if (fcast=="24"){var fdesc="Precipitation, very unsettled";} else
if (fcast=="25"){var fdesc="Stormy, may improve";} else
if (fcast=="26"){var fdesc="Stormy, much precipitation";} else
{ var fdesc="";}
if (fdesc == "" || fdesc == "unknown!") {
$("#forecast").hide();
}
else
{
$("#forecast").show();
}
$("#forecast").html("" + fdesc);



tick_counter=update_seconds;
}
else
{
tick_counter--;
$("#refresh_in").html(tick_counter);
}

}




« Last Edit: February 02, 2022, 05:36:26 AM by dazza »

 

anything