Page 1 of 1

Grease Monkey Timer Count Down

PostPosted: Tue Aug 07, 2007 2:05 pm
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/conquerclubcountdown.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]);


Major Update

PostPosted: Wed Aug 08, 2007 1:25 pm
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)

PostPosted: Wed Aug 08, 2007 2:16 pm
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!!

PostPosted: Wed Aug 08, 2007 2:19 pm
by Phobia
Well, I like how the timer is in big bold writing, so i'll take it :)

PostPosted: Wed Aug 08, 2007 2:40 pm
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...?

PostPosted: Wed Aug 08, 2007 2:50 pm
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?

.

PostPosted: Wed Aug 08, 2007 3:08 pm
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.

PostPosted: Thu Aug 09, 2007 6:19 pm
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!