Ok, I will be honest - my first javascript challenge is a little hard, but has been handed down to me from my uncle. He doesnt know how to do it, and thinks a fresh mind might be able to make sence of it. Fresh meaning fairly new to js... not his wisest move I would say.

I come here instead :)

Here's the deal - I believe that he intends to make a program to execute a function (in his case, a vote) when a timer reaches 1.
The timer is located somewhere in a javascript he has provided me with, and after some scouring, I think I have found the relevent area.

The script passes along the timer text to a webpage in the form of HH:MM:SS - but I need another way of geting that timer data out (to a program or script??).

1. Is there a way to extract the timer data in any way shape or form?

He would be rapt if I could solve his final programming challenge too, but this might be a bit (read: lot) more challenging.

2. What ways could I get that data into a local javascript (or anything else if easier) script to make it execute a function (not sure, but I believe just a url or mouse press) when the timer reaches 1 second. The original script in full and page with the timer will be located on his server and accessable to me through the web, so the script would need to be capable of running locally from me to him. Can that be done??

Please ask and I would be delighted to give you any other info you need.

Here is the part of the script where I believe the final condition for the timer is handled. As I am new to js, let me know if I have butchered anything before or after that is critical to you understanding the timer function.

// JavaScript Document (Part)

 update: function (updateTime) {var id, pollId, i, count, item, amount_element, time_element, element, field, value;if ((typeof updateTime === "undefined" || updateTime === true) && this.serverTimeUpdated === null || new Date - this.serverTimeUpdated > 1000) {++this.serverTime;}this.updateServerTime();if (typeof this.data.pollList !== "undefined") {for (pollId in this.data.pollList.itemList) {item = this.data.pollList.itemList[pollId];if (item.status !== "online" && item.status !== "offline") {continue;}item.updated.push("time");id = "poll_" + pollId;i = 0;count = item.updated.length;if (typeof this.elementList[id] !== "undefined" && count > 0) {for (; i < count; ++i) {field = item.updated[i];if (field === "count_down_time") {if (this.ignoreNextTimeHighlight === pollId) {this.ignoreNextTimeHighlight = false;} else {this.highlight(this.elementList[id].time);}continue;}value = item[field];if (field === "amount") {this.needAdditionalDataUpdate = true;value = this.formatAmount(value);} else if (field === "time") {if (item.status === "offline") {value = "00:00:00";} else {timeRemaining = value - this.serverTime - 1;if (timeRemaining > 0) {if (item.status === "completed") {item.status = "online";this.setPollAsOnline(item);}value = this.formatTime(timeRemaining);} else {value = "00:00:00";if (item.status === "completed") {continue;}}if (typeof this.elementList[id][field] !== "undefined") {element = this.elementList[id][field];var className = this.getTimerColorClass(item.status, timeRemaining);element.className = element.className.replace(/ red| green| dark_gray/, "") + " " + className;}}}

Well firstly, how 'bout you give us a non-minified version of the javascript. I am not about to go wading through that block of crap. And by non-minifid I mean put some damn newlines in there, perhaps some tabs or spaces, some form of indentation. If it was written this way then whoever wrote it needs to be shot.

As what have, Shawn said: Providing us with less lines of codes, will just complicate the whole thing. You must provide us with all the Functions:Classes—Variables: Declared-Values&#8212;Labels:Objects/Values that you used on your stated code.

Compacting your code:

<script type="text/javascript">
<!-- 

// Making us guess on what you have on the lines, will take plenty of our time, solving your problem and might as well drop the whole issue.

// knowing that we offer free service on your solution(s)... 
  

var Mystery = function( serverTimeUpdated ) {
   this.serverTimeUpdated = (( serverTimeUpdated ) ? serverTimeUpdated : null );
   this.serverTime = 0;
};

Mystery.prototype = {
// GUESSING GAME!
   data : { 
      pollList : {
         itemList : {
            online : "online",
            offline : "offline",
            completed : "completed",
            updated : [ ]
         }
      }
   }, updateServerTime : function() {
   alert( "updateServerTime" );
   }, update : function( updateTime ) {
   updateTime = (( updateTime ) ? updateTime : undefined );
var id;
var pollId;
var i;
var item;
var count;
var amount_element;
var time_element;
var element;
var field;
var value;
   (( updateTime || !( updateTime && this.serverTimeUpdated ) || (( new Date - this.serverTimeUpdated ) > 1000 )) ? ++this.serverTime : null );
   this.updateServerTime(); // What could be the statements inside this function?
   if ( this.data.pollList ) { // What could be the ( LABEL/KEY : OBJECT/VALUE )?
      for ( pollId in this.data.pollList.itemList ) {
         item = this.data.pollList.itemList[ pollId ];
         if ( item.status !== "offline" && item.status !== "online" ) {
            continue;
         }
         item.updated.push( "time" );
         id = "poll_" + pollId;
         count = item.updated.length;
         if ( this.element[ id ] && count > 0 ) {
            for ( i = 0; i < count; ++i ) {
               field = item.updated[ i ];
              if ( field === "count_down_timer" ) {                               this.ignoreNextTimeHighlight = (( this.ignoreNextTimeHighlight === pollId ) ? false : pollId );
                 if ( !this.ignoreNextTimeHighlight ) {
                    this.highlight( this.elementList[ id ].time );
                 } continue;
              } value = item[ field ];
                 switch( field ) {
                 case "amount" :
                 this.needAdditionalDataUpdate = true; 
                 value = this.formatAmount( value );
                 break;
                 case "time" : 
                 (( item.status === "offline" ) ? value = "00:00:00" : timeRemaining = ((( value ) - this.serverTime ) - 1 ));
                 (( timeRemaining > 0 && item.status === "complete" ) ? item.status = "online" : (( item.status === "online" ) ? this.formatTime( item ) : value = this.formatTime( timeRemaining ))); 
                 break;
                 default :
                 value = "00:00:00";
                    if ( item.status === "complete" ) {
                       continue;
                    }
                 }
              } if ( this.element[ id ][ field ] ) {
                 element = this.element[ id ][ field ];
                 var className = this.getTimerColorClass( item.status, timeRemaining );
                 element.className = element.className.replace(/ red| green| dark_grey/, "" ) + " " + className;
               }
            }
         }
      }
   }
};

var fun = new Mystery();
window.onload = function() {
 
// BOUNDLESs Call-->
fun.updateServerTime();
   for ( var x in fun.data.pollList.itemList ) {
      alert( x );
   }
};
// -->
</script>

Right, so lets give you the whole script.

I must apologize greatly though, as it looks like a piece of **@#.

I had to run it through a decoder, that is why there is little to no formatting. So, umm please don't shoot me?

My aim is to find a way to use that timer to vote last minute.
I assume I need to run a script on the page after load, but that is a later stage.

It seems that javascript:alert(timeRemaining) gives me the time remaining for other polls on the page - not necessarily the main one I want! (There is a "related polls" section near the bottom of the page) Is there something I can use to specify WHICH timeRemaining I want?

My final script would probably look something like:
(Psuedocode here... dont know the exact wording)
If: timeRemaing on this poll = 1
then: vote (yet to find out the correct command for this - this is stage 2)
loop the If to keep checking

The timer counts down from the time the last person voted, if that's relevent.

Well, heres the script. The stuff you got was down near line 17 (although it's a LONG line).

Thanks again!

Aaaaaaaaagh!!!!

Did I hear a distant pop? I think ShawnCPlus just burst a blood vessel.

Airshow

I'm pretty sure we said don't post minified versions. Ya gotta have some newlines and indentation in there.

Good thing I found a beautifier. I wouldn't want to be responsible for any blood, other bodily fluids and/or ruptured organs/vessels that may be caused by reading the other version. :)

I went through the script today with the IE8 developer tool.
It seems that "timeRemaining" is only assigned a value for a part of the script, otherwise it is undefined.

You guys know this better than me though.

Also, with looping the testing for timer value part of the script (which I will end up creating), it would have to allow for the timeRemaining to be refreshed before executing the check again. (Yes, new to js; but still can think logically)

Thanks

Has anyone had any luck with this?

I have been poking around myself, but without knowing where and what to look for - I'm stumped.

:( Nothing?

Bump for any new comers to have a look at this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.