Grease Monkey Timer Count Down

Archival storage to keep things organized and uncluttered. Can't find what you need? Search for old topics here.

Moderator: Tech Team

Forum rules
Please read the Community Guidelines before posting.
Post Reply
mikeycgto
Posts: 9
Joined: Thu Aug 02, 2007 10:58 am

Grease Monkey Timer Count Down

Post by mikeycgto »

I know it already exists, but I'm new to the site and got bored last night and built a really simple count down script.

The script is located at http://www.breakbase.com/cc/conquerclub ... wn.user.js

The source code is as follows:

Code: Select all

// ==UserScript==
// @name           conquer club count down
// @namespace      CC
// @include        http://www.conquerclub.com/game.php?game=*
// ==/UserScript==

var game = null;
function init(elem) {
	if (elem.nextSibling.nodeType != 3)
		return;
    var str    = elem.nextSibling.nodeValue;
    var h      = (parseInt(str.substr(1,2),10)*3600000);
    var m      = (parseInt(str.substr(7,2),10)*60000);
    var s      = (parseInt(str.substr(13,2),10)*1000);
    var e      = document.createElement('div');
	var now    = new Date();
	game = new Date(now.getTime()+(h+m+s));
	
    e.setAttribute('id','timer');
    elem.parentNode.replaceChild(e,elem.nextSibling);
    update();
}
function update() {
    var e     = document.getElementById('timer');
    var now   = new Date();
	if (now.getTime() < game.getTime()) {
		var hours = Math.floor(Math.floor(game.getTime()-now.getTime())/3600000);
		var mins  = Math.floor(Math.floor(game.getTime()-now.getTime())%3600000/60000);
		var sec   = Math.floor(Math.floor(game.getTime()-now.getTime())%3600000%60000/1000);
		e.innerHTML = doubleDigit(hours)+'hrs '+doubleDigit(mins)+'mins '+doubleDigit(sec)+'sec';
		setTimeout(update, 1000);
	} else 
		window.location.reload();
}

function doubleDigit(n) {
	if (n >= 10)
		return ''+n;
	else
		return '0'+n;
}

init(document.getElementsByTagName('h4')[0]);

mikeycgto
Posts: 9
Joined: Thu Aug 02, 2007 10:58 am

Major Update

Post by mikeycgto »

Added Options for formatting the clock:

- Size: can be any integer. Automatically appends the 'pt' to the end. Default is 16

- Weight: can be 'bold', 'bolder', 'normal', ect. Default is 'bold'

- Align: can be 'left', 'right', 'center'. Default is 'center'

- Display: can be 'text' or 'colon'. The 'text' setting looks like '24hrs 42min 11sec' and the 'colon' setting looks like '24:42:11'. Default is 'colon'

Options are found at the top of the script and look like so:

Code: Select all

options['align']  	= 'center';
options['display']   = 'colon';
options['size']      = 16;
options['weight'] 	= 'bold';
NOTE: All the options with quotes (align, display, weight) need to be in quotes and lower case. There is some validation that'll set them to their defaults if they're not strings.

I also changed the HTML so the clock doesn't 'blink' as much when it updates the time (each piece, hour\mins\secs, is there own node).

You can find the script here(same as above)
Last edited by mikeycgto on Wed Aug 08, 2007 2:18 pm, edited 1 time in total.
mikeycgto
Posts: 9
Joined: Thu Aug 02, 2007 10:58 am

Post by mikeycgto »

Okay, everything works now, even if you have BOB installed it doesn't what loads first. My timer will hide BOB timer for the record. The URL is still the same, hope you all enjoy!!
User avatar
Phobia
Posts: 1497
Joined: Fri May 26, 2006 2:11 pm
Gender: Male
Location: Sheffield, England

Post by Phobia »

Well, I like how the timer is in big bold writing, so i'll take it :)
mikeycgto
Posts: 9
Joined: Thu Aug 02, 2007 10:58 am

Post by mikeycgto »

if enough people like it, I'll make the options easier to change and maybe add some more features or perhaps integrate it into BOB...?
Selin
Posts: 1100
Joined: Wed Oct 04, 2006 7:56 am
Location: Istanbul, Turkey

Post by Selin »

thanks for fixing Bob. that helped a lot. =D>

saved search function does not work with "game labels" option. can you fix that too?

.
mikeycgto
Posts: 9
Joined: Thu Aug 02, 2007 10:58 am

Post by mikeycgto »

I just fixed my script to 'play nicely' with the BOB script. I can take a look at the saved search script though and will post back here.
mikeycgto
Posts: 9
Joined: Thu Aug 02, 2007 10:58 am

Post by mikeycgto »

I'm adding a few 'new' features to the script as well as a better way to control the options. Should be releasing it within a few days, so stay tuned!
Post Reply

Return to “Tool Archives”