Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Java][jQuery]How to find out want variables are needed to make a downcounter to set

Newbie Spellweaver
Joined
Apr 15, 2008
Messages
30
Reaction score
0
I am using a already existing script that sents a downcounter's time to zero. I wanting to change it's variables over so it will work for another downcounter. I have the existing script and I'm NOT wanting someone to do this for me as I want to learn how to do it, I just want someone to help me recognize what to do so I can do it and learn from this. I have tried many times getting this do work but I haven't got it to work yet so i have come to get help.

Existing Code
Code:
GM_addStyle("#counter { position: fixed; width: 60px; top: 0; left: 0; border: 3px solid #999; padding: 2px 5px; font-size: 12pt;}");

var free = document.getElementById("ff");
if(free)
   free.childNodes[7].click();


setTimeout(function() {

	var x = unsafeWindow.c;

	unsafeWindow.c = 2;

	var div = document.createElement("div");

	with (div) {

		id = "counter",

		innerHTML = (x/60).toFixed(1);

	}

	document.body.appendChild(div);

	var rs = function() {

		var timer = window.setInterval(function() {

			x--;

			document.getElementById("counter").innerHTML = x;

			if (x == 0) {

				clearInterval(timer);

				var link = document.getElementById("dl");
				var X = link.childNodes[0].childNodes[2].childNodes[0];
				X.click();

			}

		}, 1000);

	}

	rs();

}, 500);


New Code that i want to insert it's variables into the code above
Code:
jQuery.fn.extend({
	everyTime: function(interval, label, fn, times) {
		return this.each(function() {
			jQuery.timer.add(this, interval, label, fn, times);
		});
	},
	oneTime: function(interval, label, fn) {
		return this.each(function() {
			jQuery.timer.add(this, interval, label, fn, 1);
		});
	},
	stopTime: function(label, fn) {
		return this.each(function() {
			jQuery.timer.remove(this, label, fn);
		});
	}
});

jQuery.extend({
	timer: {
		global: [],
		guid: 1,
		dataKey: "jQuery.timer",
		regex: /^([0-9]+(?:\.[0-9]*)?)\s*(.*s)?$/,
		powers: {
			// Yeah this is major overkill...
			'ms': 1,
			'cs': 10,
			'ds': ****
			's': 1000,
			'das': 10000,
			'hs': 100000,
			'ks': 1000000
		},
		timeParse: function(value) {
			if (value == undefined || value == null)
				return null;
			var result = this.regex.exec(jQuery.trim(value.toString()));
			if (result[2]) {
				var num = parseFloat(result[1]);
				var mult = this.powers[result[2]] || 1;
				return num * mult;
			} else {
				return value;
			}
		},
		add: function(element, interval, label, fn, times) {
			var counter = 0;
			
			if (jQuery.isFunction(label)) {
				if (!times) 
					times = fn;
				fn = label;
				label = interval;
			}
			
			interval = jQuery.timer.timeParse(interval);

			if (typeof interval != 'number' || isNaN(interval) || interval < 0)
				return;

			if (typeof times != 'number' || isNaN(times) || times < 0) 
				times = 0;
			
			times = times || 0;
			
			var timers = jQuery.data(element, this.dataKey) || jQuery.data(element, this.dataKey, {});
			
			if (!timers[label])
				timers[label] = {};
			
			fn.timerID = fn.timerID || this.guid++;
			
			var handler = function() {
				if ((++counter > times && times !== 0) || fn.call(element, counter) === false)
					jQuery.timer.remove(element, label, fn);
			};
			
			handler.timerID = fn.timerID;
			
			if (!timers[label][fn.timerID])
				timers[label][fn.timerID] = window.setInterval(handler,interval);
			
			this.global.push( element );
			
		},
		remove: function(element, label, fn) {
			var timers = jQuery.data(element, this.dataKey), ret;
			
			if ( timers ) {
				
				if (!label) {
					for ( label in timers )
						this.remove(element, label, fn);
				} else if ( timers[label] ) {
					if ( fn ) {
						if ( fn.timerID ) {
							window.clearInterval(timers[label][fn.timerID]);
							delete timers[label][fn.timerID];
						}
					} else {
						for ( var fn in timers[label] ) {
							window.clearInterval(timers[label][fn]);
							delete timers[label][fn];
						}
					}
					
					for ( ret in timers[label] ) break;
					if ( !ret ) {
						ret = null;
						delete timers[label];
					}
				}
				
				for ( ret in timers ) break;
				if ( !ret ) 
					jQuery.removeData(element, this.dataKey);
			}
		}
	}
});

jQuery(window).bind("unload", function() {
	jQuery.each(jQuery.timer.global, function(index, item) {
		jQuery.timer.remove(item);
	});
});

Thanks for Reading my thread and PLEASE, don't do it for me, or if you do, tell me want to do so I can check mine with that one to see if I do it right.
 
Back
Top