Conquer Club

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.

Grease Monkey Timer Count Down

Postby mikeycgto on Tue Aug 07, 2007 2:05 pm

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]);

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

Major Update

Postby mikeycgto on Wed Aug 08, 2007 1:25 pm

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.
Private mikeycgto
 
Posts: 9
Joined: Thu Aug 02, 2007 10:58 am

Postby mikeycgto on Wed Aug 08, 2007 2:16 pm

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!!
Private mikeycgto
 
Posts: 9
Joined: Thu Aug 02, 2007 10:58 am

Postby Phobia on Wed Aug 08, 2007 2:19 pm

Well, I like how the timer is in big bold writing, so i'll take it :)
User avatar
Sergeant 1st Class Phobia
 
Posts: 1497
Joined: Fri May 26, 2006 2:11 pm
Location: Sheffield, England

Postby mikeycgto on Wed Aug 08, 2007 2:40 pm

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...?
Private mikeycgto
 
Posts: 9
Joined: Thu Aug 02, 2007 10:58 am

Postby Selin on Wed Aug 08, 2007 2:50 pm

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

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

.
Brigadier Selin
 
Posts: 1100
Joined: Wed Oct 04, 2006 7:56 am
Location: Istanbul, Turkey

Postby mikeycgto on Wed Aug 08, 2007 3:08 pm

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.
Private mikeycgto
 
Posts: 9
Joined: Thu Aug 02, 2007 10:58 am

Postby mikeycgto on Thu Aug 09, 2007 6:19 pm

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!
Private mikeycgto
 
Posts: 9
Joined: Thu Aug 02, 2007 10:58 am


Return to Tool Archives

Who is online

Users browsing this forum: No registered users

cron