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 2nd, 2010  |  syntax: JavaScript  |  size: 5.33 KB  |  hits: 58  |  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. // Opera UserJS - Countdown script for forumwarz.
  2. // This will place the countdown timer into the title
  3. // Author: TT
  4. // v1.2.0
  5.  
  6. //set these variables for the "options"
  7. var useShort=true; //set to false if you prefer long string as title
  8. var useExShort=false; //only uses biggest value (e.g. days only when at least one remains). trumps useShort.
  9. var spacer=""; //default is a "nothing" for the spacer. use " " for a space
  10. var useZeros=false; //show 0 days/hours/minutes as "0" instead of excluding them
  11. var trackIncit=true;
  12. var trackDomination=true;
  13. var trackAuctions=true;
  14. var trackVisits=true; // track time until visits reload (also deliveries) on /character/me
  15. var trackItemBuildr=true;
  16. var trackForumBuildr=true;
  17.  
  18. // !!! DO NOT EDIT BELOW THIS UNLESS YOU KNOW WHAT YOU ARE DOING !!!
  19.  
  20. //var orgTitle = document.title;
  21. var URL = document.location.href;
  22. var isDom = URL.indexOf('forumwarz.com/domination') != -1;
  23. var isIncit = URL.indexOf('forumwarz.com/incit') != -1;
  24. var isAuc = URL.indexOf('forumwarz.com/auctions') != -1;
  25. var isCharMe = URL.indexOf('forumwarz.com/characters/me') != -1;
  26. var isIB = URL.indexOf('forumwarz.com/item_buildr') != -1;
  27. var isFB = URL.indexOf('forumwarz.com/forum_buildr') != -1;
  28.  
  29.  
  30. window.opera.addEventListener(
  31.         'afterscript', //we definitely want scripts loaded first
  32.         function (e) { //only enter main if we are on a proper page and the countdown script loaded
  33.                 if( e.element.getAttribute('src').indexOf('countdown.js') != -1 && (
  34.                         (isDom && trackDomination) ||
  35.                         (isIncit && trackIncit) ||
  36.                         (isAuc && trackAuctions) ||
  37.                         (isCharMe && trackVisits) ||
  38.                         (isIB && trackItemBuildr) ||
  39.                         (isFB && trackForumBuildr)
  40.                 )){
  41.                         setTimeout("checkForCountdown()", 1000); //give it 1 second for safety
  42.                 }
  43.         },
  44.         false
  45. );
  46.  
  47. function checkForCountdown(){ //TODO add end of timer check here or maybe main()
  48.         if(document.getElementById("countdown") != null)
  49.                 main(); //countdown element is not empty. enter main
  50.         else
  51.                 setTimeout("checkForCountdown()", 1000); //else loop
  52. }
  53.  
  54. //our main function that calls itself (loop)
  55. function main() {
  56.         var fCD = document.getElementById("countdown").firstChild.nodeValue; //full countdown
  57.  
  58.         var offset = 0; //default no offset (auctions)
  59.         if(isDom || isIncit || isIB) offset = 3; //offset fix for domination, INCIT, and Item_Buildr
  60.         if(fCD.indexOf('until the next round begins') != -1 || isFB)
  61.                 offset = 5; //extra offset fix for "end of round" for INCIT and for Forum_Buildr
  62.         if(isCharMe) offset = 6; // character/me offset fix
  63.  
  64.         var newTitle; //start out new title variable
  65.         var sArray = fCD.split(" "); //split countdown text by spaces
  66.  
  67.         if(useExShort){
  68.                 newTitle = sArray[0] + sArray[1].substr(0,1); //grb first char (number) only
  69.         } else if(useShort && !useZeros){
  70.           switch(sArray.size()-offset){
  71.                 case 3: //seconds
  72.                         newTitle = sArray[0] + "s";break;
  73.                 case 6: //minutes+seconds
  74.                         newTitle = sArray[0] + "m" + spacer + sArray[3] + "s";break;
  75.                 case 8: //hours+minutes+seconds
  76.                         newTitle = sArray[0] + "h" + spacer + sArray[2] + "m" + spacer + sArray[5] + "s";break;
  77.                 case 10: //days+hours+minutes+seconds
  78.                         newTitle = sArray[0] + "d" + spacer + sArray[2] + "h" + spacer + sArray[4] + "m" + spacer + sArray[7] + "s";break;
  79.                 default:
  80.                         newTitle = fCD;
  81.           }
  82.         } else if(useShort && useZeros) {              
  83.           switch(sArray.size()-offset){
  84.                 case 3: //seconds
  85.                         newTitle = "0d" + spacer + "0h" + spacer + "0m" + spacer + sArray[0] + "s";break;
  86.                 case 6: //minutes+seconds
  87.                         newTitle = "0d" + spacer + "0h" + spacer + sArray[0] + "m" + spacer + sArray[3] + "s";break;
  88.                 case 8: //hours+minutes+seconds
  89.                         newTitle = "0d" + spacer + sArray[0] + "h" + spacer + sArray[2] + "m" + spacer + sArray[5] + "s";break;
  90.                 case 10: //days+hours+minutes+seconds
  91.                         newTitle = sArray[0] + "d" + spacer + sArray[2] + "h" + spacer + sArray[4] + "m" + spacer + sArray[7] + "s";break;
  92.                 default:
  93.                         newTitle = fCD;
  94.           }
  95.         } else if(!useShort && useZeros) {
  96.           switch(sArray.size()-offset){
  97.                 case 3: //seconds
  98.                         newTitle = "0 days 0 hours 0 minutes and " + fCD;break;
  99.                 case 6: //minutes+seconds
  100.                         newTitle = "0 days 0 hours " + fCD;break;
  101.                 case 8: //hours+minutes+seconds
  102.                         newTitle = "0 days " + fCD;break;
  103.                 default: //case 10 (days,hrs,mins,secs) is same as default so let's just default =P
  104.                         newTitle = fCD;
  105.           }
  106.         } else {
  107.                 newTitle=fCD; //no match. use full countdown string
  108.         }
  109.  
  110.         if(isIncit && trackIncit){ //INCIT specific code
  111.                 var submissions = document.getElementById('submissions_received');
  112.                 if(submissions!=undefined){ //for when it's not loaded yet
  113.                         submissions = submissions.text.substr(0,1); //first char (number)
  114.                         if(submissions > 0)
  115.                                 newTitle += spacer + submissions + "sub"; //append number + "sub" to new title
  116.                 }
  117.  
  118.                 var links = document.getElementsByTagName('a'); //grab all links
  119.                 var ass = "0"; //initialize "ass"
  120.                 for(i=40;i<60;i++){ //should be the 47th link, but we will search this range if links change
  121.                         if (links[i].text.indexOf("Assholes Online") != -1){ //find "Assholes Online" link text
  122.                                 ass = links[i].text.substr(0,1); //grab first char (number)
  123.                                 newTitle += spacer + ass + "ass"; //append number + "ass" to new title
  124.                                 break; //exit loop. we only need one match. I got two for some reason...
  125.                         }
  126.                 }
  127.         }
  128.  
  129.         document.title=newTitle; //finally, set the new title
  130.         setTimeout("main()", 1000); //loop main with delay
  131. }