Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 20th, 2010  |  syntax: JavaScript  |  size: 6.78 KB  |  hits: 50  |  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.com
  2. //   This will place the countdown timer into the title
  3. //   Author: TT
  4. //   v1.4.1
  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. only days). 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. var allowEnd=true; //stop the timer (don't loop past 0) and exit for FB,IB,Me. auctions always end.
  18. var debug=false; //use with javascript:dbg() in address bar to find problems
  19. var debugVerbose=false; //use with caution. can eat memory with lots of text
  20.  
  21.  
  22. // !!! DO NOT EDIT BELOW THIS UNLESS YOU KNOW WHAT YOU ARE DOING !!!
  23. var orgTitle = document.title;
  24. var URL = document.location.href;
  25. var isDom = URL.indexOf('forumwarz.com/domination') != -1;
  26. var isIncit = URL.indexOf('forumwarz.com/incit') != -1;
  27. var isAuc = URL.indexOf('forumwarz.com/auctions') != -1;
  28. var isCharMe = URL.indexOf('forumwarz.com/characters/me') != -1;
  29. var isIB = URL.indexOf('forumwarz.com/item_buildr') != -1;
  30. var isFB = URL.indexOf('forumwarz.com/forum_buildr') != -1;
  31. var fCD;
  32. var type = ['day','hour','minute','second'];
  33.  
  34. if (debug) document.title = 'Script loaded...';
  35. if (debug) var debugStr = 'Debug started.';
  36. else var debugStr = 'Enable debugging, jackass';
  37.  
  38. if ( (isDom && trackDomination) || (isIncit && trackIncit) || (isAuc && trackAuctions) ||
  39.          (isCharMe && trackVisits) || (isIB && trackItemBuildr) || (isFB && trackForumBuildr) ){
  40.                 debugAdd('Page trackable. Loading CD check.',false);
  41.                 checkForCountdown();
  42. }
  43.  
  44.  
  45.  
  46. function checkForCountdown(){
  47.         if (document.getElementById('countdown') != null){
  48.                 debugAdd('Found CD element. Entering main',false);
  49.                 main(); //countdown element is not empty. enter main
  50.         } else if (checkFinished()) {
  51.                 finished();
  52.                 return;
  53.         } else {
  54.                 debugAdd('Element not ready. Looping...',true);
  55.                 setTimeout('checkForCountdown()', 1000); //else loop
  56.         }
  57. }
  58.  
  59.  
  60. //our main function that calls itself (loop)
  61. function main() {
  62.         if (document.getElementById('countdown') == null){
  63.                 if (isAuc){ //only auctions lose their element
  64.                         debugAdd('Auction closed. Exiting.',false);
  65.                         finished();
  66.                         return; //just leave. don't loop
  67.                 }
  68.                 debugAdd('Element disappeared... Loop til found.',true);
  69.                 document.title=orgTitle;
  70.                 setTimeout('main()',1000); //keep retrying in a new thread
  71.                 return; //exit this thread
  72.         } else if (document.getElementById('countdown').childNodes.length == 0) {
  73.                 debugAdd('No children. Having secks again...',true);
  74.                 setTimeout('main()',1000); //keep retrying in a new thread
  75.                 return; //exit this thread
  76.         }
  77.         debugAdd('Entered main successfully.',true);
  78.        
  79.         fCD = document.getElementById('countdown').firstChild.nodeValue; //full countdown
  80.         debugAdd('Set fCD.',true);
  81.         var newTitle = ''; //start out new title variable as empty
  82.        
  83.         if (isIncit){ //INCIT specific code for voting page notify!
  84.                 if (fCD.indexOf('ends') != -1) newTitle = 'VOTING!' + spacer;
  85.         }
  86.  
  87.         var hasFinished = false;
  88.         var t = getCdTextSplit();
  89.         if ( (t[0]==0&&t[1]==0&&t[2]==0&&t[3]==1) )
  90.                 hasFinished = true;
  91.         if ( (isAuc && hasFinished) ||
  92.                  (isFB && hasFinished && allowEnd) ||
  93.                  (isIB && hasFinished && allowEnd) ||
  94.                  (isDom && hasFinished && allowEnd) ||
  95.                  (isCharMe && hasFinished && allowEnd) ){
  96.                         finished(); //post our ending title
  97.                         return; //leave without looping
  98.         }
  99.        
  100.         if (useShort || useExShort || useZeros){
  101.                 debugAdd('Running getCdTextSplit.',true);
  102.                 var cdTextSplit = getCdTextSplit();
  103.                 for (i=0;i<cdTextSplit.size();i++){
  104.                         if ( (cdTextSplit[i] > 0 || useZeros) && (cdTextSplit[i] > 0 || !useExShort) ||
  105.                                  (i==3 && cdTextSplit[3] == 0 && newTitle != '') ){ //add 0 seconds to non-empty title
  106.                                 newTitle += cdTextSplit[i] + type[i].substr(0,1) + spacer;
  107.                         }
  108.                         if (cdTextSplit[i] > 0 && useExShort) break; //break loop after first non-zero
  109.                 }
  110.         } else {
  111.                 debugAdd('Fallback. Failed to get times.',true);
  112.                 newTitle=fCD; //no match. use full countdown string
  113.         }
  114.  
  115.        
  116.         if (isIncit && trackIncit){ //INCIT specific code
  117.                 debugAdd('INCIT Shit...',true);
  118.                 var submissions = document.getElementById('submissions_received');
  119.                 if (submissions!=undefined){ //for when it's not loaded yet
  120.                         submissions = submissions.innerHTML.split(' ',1); //first chars (number)
  121.                         if (submissions[0] > 0){
  122.                                 newTitle += submissions[0] + 'sub' + spacer; //append number + 'sub' to new title
  123.                         }
  124.                         debugAdd('Finished sub add code.',true);
  125.                 }
  126.  
  127.                 var links = document.getElementsByTagName('a'); //grab all links
  128.                 var ass = '0'; //initialize 'ass'
  129.                 for(i=0;i<60;i++){ //should be the 47th link, but we will search this range if links change
  130.                         if (links[i].text.indexOf('Assholes Online') != -1){ //find 'Assholes Online' link text
  131.                                 ass = links[i].text.split(' ',1); //grab first chars (number)
  132.                                 newTitle += spacer + ass[0] + 'ass' + spacer; //append number + 'ass' to new title
  133.                                 break; //exit loop. we only need one match. I got two for some reason...
  134.                         }
  135.                 }
  136.                 debugAdd('Finished ass add code.',true);
  137.         }
  138.  
  139.         if (!newTitle) newTitle = '...'; //Opera defaults to URL if the title is empty... big nono there.
  140.         document.title=newTitle; //finally, set the new title
  141.         debugAdd('Title set. Looping...',true);
  142.         setTimeout('main()', 1000); //loop main with delay
  143. }
  144.  
  145.  
  146. function getCdTextSplit(){
  147.         var offset;
  148.         var cdTextSplit = new Array(4);
  149.         for (i=0;i<type.size();i++){
  150.                 offset = fCD.indexOf(type[i]);
  151.                 cdTextSplit[i] = offset != -1 ? fCD.substr(fCD.indexOf('',offset-3), 2).strip(' ') : 0;
  152.         }
  153.         return cdTextSplit;
  154. }
  155.  
  156. function debugAdd(str,verbose){
  157.         if (debug && (!verbose || debugVerbose)) debugStr += '\n' + str;
  158. }
  159.  
  160. function dbg(){
  161.         alert(debugStr);
  162. }
  163.  
  164. function finished(){
  165.         if (isAuc)
  166.                 document.title='Auction closed!';
  167.         else if (isDom)
  168.                 document.title='Dom round over!';
  169.         else if (isFB)
  170.                 document.title='FB ended!';    
  171.         else if (isIB)
  172.                 document.title='IB ended!';
  173.         else if (isIB)
  174.                 document.title='New visits & gifts!';
  175. }
  176.  
  177. function checkFinished(){
  178.         if (!isAuc) return false; //only auctions can "start" in finished state.
  179.         if (document.getElementById('remaining') != null){
  180.                 var text = document.getElementById('remaining').firstChild.nodeValue;
  181.                 if (text.indexOf('This auction is closed.') != -1){
  182.                         debugAdd('Auction finished. Exit.',false);
  183.                         return true;
  184.                 } else {
  185.                         debugAdd('Auction NOT finished. Continue,',false);
  186.                         return false;
  187.                 }
  188.         } else {
  189.                 debugAdd("ERROR: You shouldn't see this",false);
  190.                 return false;
  191.         }
  192. }