Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 1st, 2010  |  syntax: JavaScript  |  size: 3.65 KB  |  hits: 70  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //set these variables for the "options"
  2. var useShort=true; //set to false if you prefer long string as title
  3. var useExShort=false; //only uses biggest value (e.g. days only when at least one remains). trumps useShort.
  4. var spacer=""; //default is a "nothing" for the spacer. use " " for a space
  5. var useZeros=false; //show days/hours/minutes as "0" instead of excluding them
  6.  
  7. var URL = document.location.href;
  8.  
  9. window.opera.addEventListener(
  10.         'afterscript', //we definitely want scripts loaded first
  11.         function (e) {
  12.                 if( e.element.getAttribute('src').indexOf('countdown.js') != -1 && (
  13.                         //deleted or comment-out below what you don't want tracked!
  14.                         URL.indexOf('forumwarz.com/domination') != -1 ||
  15.                         URL.indexOf('forumwarz.com/incit') != -1 ||
  16.                         URL.indexOf('forumwarz.com/auctions') != -1 ||
  17.                         URL.indexOf('forumwarz.com/characters/me') != -1 ||
  18.                         URL.indexOf('forumwarz.com/item_buildr') != -1 ||
  19.                         URL.indexOf('forumwarz.com/forum_buildr') != -1
  20.                 )){
  21.                         setTimeout("checkForCountdown()", 1000); //give it 1 second for safety
  22.                 }
  23.         },
  24.         false
  25. );
  26.  
  27. function checkForCountdown(){ //TODO add end of timer check here or maybe main()
  28.         if(document.getElementById("countdown") != null)
  29.                 main();
  30.         else
  31.                 setTimeout("checkForCountdown()", 1000);
  32. }
  33.  
  34. //our main function that calls itself (loop)
  35. function main() {
  36.         var fCD = document.getElementById("countdown").firstChild.nodeValue; //full countdown
  37.  
  38.         var offset = 0;
  39.         if(URL.indexOf('forumwarz.com/domination') != -1 || URL.indexOf('forumwarz.com/incit') != -1) offset = 3;
  40.         if(fCD.indexOf('until the next round begins') != -1) offset = 5;
  41.  
  42.         var newTitle;
  43.         var sArray = fCD.split(" ");
  44.  
  45.         if(useExShort){
  46.                 newTitle = sArray[0] + sArray[1].substr(0,1);
  47.         } else if(useShort && !useZeros){
  48.           switch(sArray.size()-offset){
  49.                 case 3: //seconds
  50.                         newTitle = sArray[0] + "s";break;
  51.                 case 6: //minutes+seconds
  52.                         newTitle = sArray[0] + "m" + spacer + sArray[3] + "s";break;
  53.                 case 8: //hours+minutes+seconds
  54.                         newTitle = sArray[0] + "h" + spacer + sArray[2] + "m" + spacer + sArray[5] + "s";break;
  55.                 case 10: //days+hours+minutes+seconds
  56.                         newTitle = sArray[0] + "d" + spacer + sArray[2] + "h" + spacer + sArray[4] + "m" + spacer + sArray[7] + "s";break;
  57.                 default:
  58.                         newTitle = fCD;
  59.           }
  60.         } else if(useShort && useZeros) {              
  61.           switch(sArray.size()-offset){
  62.                 case 3: //seconds
  63.                         newTitle = "0d" + spacer + "0h" + spacer + "0m" + spacer + sArray[0] + "s";break;
  64.                 case 6: //minutes+seconds
  65.                         newTitle = "0d" + spacer + "0h" + spacer + sArray[0] + "m" + spacer + sArray[3] + "s";break;
  66.                 case 8: //hours+minutes+seconds
  67.                         newTitle = "0d" + spacer + sArray[0] + "h" + spacer + sArray[2] + "m" + spacer + sArray[5] + "s";break;
  68.                 case 10: //days+hours+minutes+seconds
  69.                         newTitle = sArray[0] + "d" + spacer + sArray[2] + "h" + spacer + sArray[4] + "m" + spacer + sArray[7] + "s";break;
  70.                 default:
  71.                         newTitle = fCD;
  72.           }
  73.         } else if(!useShort && useZeros) {
  74.           switch(sArray.size()-offset){
  75.                 case 3: //seconds
  76.                         newTitle = "0 days 0 hours 0 minutes and " + fCD;break;
  77.                 case 6: //minutes+seconds
  78.                         newTitle = "0 days 0 hours " + fCD;break;
  79.                 case 8: //hours+minutes+seconds
  80.                         newTitle = "0 days " + fCD;break;
  81.                 default: //case 10 (days,hrs,mins,secs) is same as default so let's just default =P
  82.                         newTitle = fCD;
  83.           }
  84.         } else {
  85.                 newTitle=fCD;
  86.         }
  87.  
  88.  
  89. //      var submissions = document.getElementById('submissions_received').innerHTM;
  90. //      if(submissions!=undefined){
  91. //              submissions = submissions.substr(0,1);
  92. //              if(submissions > 0) newTitle = newTitle + spacer + submissions + "sub";
  93. //      }
  94.  
  95.         document.title=newTitle; //set the title
  96.         setTimeout("main()", 1000);
  97.  
  98.         //alert(sArray.size());
  99. }