Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 2nd, 2010  |  syntax: JavaScript  |  size: 5.49 KB  |  views: 63  |  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.2
  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.         if(document.getElementById("countdown")==null){
  57.                 document.title=orgTitle;
  58.                 setTimeout("main()",1000); //keep retrying
  59.                 return; //exit for now
  60.         }
  61.         var fCD = document.getElementById("countdown").firstChild.nodeValue; //full countdown
  62.  
  63.         var offset = 0; //default no offset (auctions)
  64.         if(isDom || isIncit || isIB) offset = 3; //offset fix for domination, INCIT, and Item_Buildr
  65.         if(fCD.indexOf('until the next round begins') != -1 || isFB)
  66.                 offset = 5; //extra offset fix for "end of round" for INCIT and for Forum_Buildr
  67.         if(isCharMe) offset = 6; // character/me offset fix
  68.  
  69.         var newTitle; //start out new title variable
  70.         var sArray = fCD.split(" "); //split countdown text by spaces
  71.  
  72.         if(useExShort){
  73.                 newTitle = sArray[0] + sArray[1].substr(0,1); //grb first char (number) only
  74.         } else if(useShort && !useZeros){
  75.           switch(sArray.size()-offset){
  76.                 case 3: //seconds
  77.                         newTitle = sArray[0] + "s";break;
  78.                 case 6: //minutes+seconds
  79.                         newTitle = sArray[0] + "m" + spacer + sArray[3] + "s";break;
  80.                 case 8: //hours+minutes+seconds
  81.                         newTitle = sArray[0] + "h" + spacer + sArray[2] + "m" + spacer + sArray[5] + "s";break;
  82.                 case 10: //days+hours+minutes+seconds
  83.                         newTitle = sArray[0] + "d" + spacer + sArray[2] + "h" + spacer + sArray[4] + "m" + spacer + sArray[7] + "s";break;
  84.                 default:
  85.                         newTitle = fCD;
  86.           }
  87.         } else if(useShort && useZeros) {              
  88.           switch(sArray.size()-offset){
  89.                 case 3: //seconds
  90.                         newTitle = "0d" + spacer + "0h" + spacer + "0m" + spacer + sArray[0] + "s";break;
  91.                 case 6: //minutes+seconds
  92.                         newTitle = "0d" + spacer + "0h" + spacer + sArray[0] + "m" + spacer + sArray[3] + "s";break;
  93.                 case 8: //hours+minutes+seconds
  94.                         newTitle = "0d" + spacer + sArray[0] + "h" + spacer + sArray[2] + "m" + spacer + sArray[5] + "s";break;
  95.                 case 10: //days+hours+minutes+seconds
  96.                         newTitle = sArray[0] + "d" + spacer + sArray[2] + "h" + spacer + sArray[4] + "m" + spacer + sArray[7] + "s";break;
  97.                 default:
  98.                         newTitle = fCD;
  99.           }
  100.         } else if(!useShort && useZeros) {
  101.           switch(sArray.size()-offset){
  102.                 case 3: //seconds
  103.                         newTitle = "0 days 0 hours 0 minutes and " + fCD;break;
  104.                 case 6: //minutes+seconds
  105.                         newTitle = "0 days 0 hours " + fCD;break;
  106.                 case 8: //hours+minutes+seconds
  107.                         newTitle = "0 days " + fCD;break;
  108.                 default: //case 10 (days,hrs,mins,secs) is same as default so let's just default =P
  109.                         newTitle = fCD;
  110.           }
  111.         } else {
  112.                 newTitle=fCD; //no match. use full countdown string
  113.         }
  114.  
  115.         if(isIncit && trackIncit){ //INCIT specific code
  116.                 var submissions = document.getElementById('submissions_received');
  117.                 if(submissions!=undefined){ //for when it's not loaded yet
  118.                         submissions = submissions.innerHTML.split(" ",1); //first chars (number)
  119.                         if(submissions > 0)
  120.                                 newTitle += spacer + submissions[0] + "sub"; //append number + "sub" to new title
  121.                 }
  122.  
  123.                 var links = document.getElementsByTagName('a'); //grab all links
  124.                 var ass = "0"; //initialize "ass"
  125.                 for(i=40;i<60;i++){ //should be the 47th link, but we will search this range if links change
  126.                         if (links[i].text.indexOf("Assholes Online") != -1){ //find "Assholes Online" link text
  127.                                 ass = links[i].text.split(" ",1); //grab first chars (number)
  128.                                 newTitle += spacer + ass[0] + "ass"; //append number + "ass" to new title
  129.                                 break; //exit loop. we only need one match. I got two for some reason...
  130.                         }
  131.                 }
  132.         }
  133.  
  134.         document.title=newTitle; //finally, set the new title
  135.         setTimeout("main()", 1000); //loop main with delay
  136. }
clone this paste RAW Paste Data