Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 10th, 2010  |  syntax: JavaScript  |  size: 4.21 KB  |  views: 64  |  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.3.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. 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. var tArray = new Array(4);
  29. var fCD;
  30. var type = ['day','hour','minute','second'];
  31.  
  32. window.opera.addEventListener(
  33.         'afterscript', //we definitely want scripts loaded first
  34.         function (e) { //only enter main if we are on a proper page and the countdown script loaded
  35.                 var source = e.element.getAttribute('src');
  36.                 if (source != null){
  37.                         if( source.indexOf('countdown.js') != -1 && (
  38.                                 (isDom && trackDomination) ||
  39.                                 (isIncit && trackIncit) ||
  40.                                 (isAuc && trackAuctions) ||
  41.                                 (isCharMe && trackVisits) ||
  42.                                 (isIB && trackItemBuildr) ||
  43.                                 (isFB && trackForumBuildr)
  44.                         )){
  45.                                 setTimeout('checkForCountdown()', 1000); //give it 1 second for safety
  46.                         }
  47.                 }
  48.         },
  49.         false
  50. );
  51.  
  52.  
  53. function checkForCountdown(){ //TODO add end of timer check here or maybe main()
  54.         if(document.getElementById('countdown') != null)
  55.                 main(); //countdown element is not empty. enter main
  56.         else
  57.                 setTimeout('checkForCountdown()', 1000); //else loop
  58. }
  59.  
  60.  
  61. //our main function that calls itself (loop)
  62. function main() {
  63.         if(document.getElementById('countdown')==null){
  64.                 document.title=orgTitle;
  65.                 setTimeout('main()',1000); //keep retrying in a new thread
  66.                 return; //exit this thread
  67.         }
  68.  
  69.         fCD = document.getElementById('countdown').firstChild.nodeValue; //full countdown
  70.         var newTitle = ''; //start out new title variable as empty
  71.  
  72.         if(useShort || useExShort || useZeros){
  73.                 getTimes();
  74.                 for (i=0;i<tArray.size();i++){
  75.                         if ( (tArray[i] > 0 || useZeros) && (tArray[i] > 0 || !useExShort) ) newTitle += tArray[i] + type[i].substr(0,1) + spacer;
  76.                         if (tArray[i] > 0 && useExShort) break; //break loop after first non-zero
  77.                 }
  78.         } else {
  79.                 newTitle=fCD; //no match. use full countdown string
  80.         }
  81.  
  82.         if(isIncit && trackIncit){ //INCIT specific code
  83.                 var submissions = document.getElementById('submissions_received');
  84.                 if(submissions!=undefined){ //for when it's not loaded yet
  85.                         submissions = submissions.innerHTML.split(' ',1); //first chars (number)
  86.                         if(submissions[0] > 0)
  87.                                 newTitle += spacer + submissions[0] + 'sub'; //append number + 'sub' to new title
  88.                 }
  89.  
  90.                 var links = document.getElementsByTagName('a'); //grab all links
  91.                 var ass = '0'; //initialize 'ass'
  92.                 for(i=40;i<60;i++){ //should be the 47th link, but we will search this range if links change
  93.                         if (links[i].text.indexOf('Assholes Online') != -1){ //find 'Assholes Online' link text
  94.                                 ass = links[i].text.split(' ',1); //grab first chars (number)
  95.                                 newTitle += spacer + ass[0] + 'ass'; //append number + 'ass' to new title
  96.                                 break; //exit loop. we only need one match. I got two for some reason...
  97.                         }
  98.                 }
  99.         }
  100.  
  101.         if (!newTitle) newTitle = '...'; //Opera defaults to URL if the title is empty... big nono there.
  102.         document.title=newTitle; //finally, set the new title
  103.         setTimeout('main()', 1000); //loop main with delay
  104. }
  105.  
  106.  
  107. function getTimes(){
  108.         for (i=0;i<type.size();i++){
  109.                 var offset = fCD.indexOf(type[i]);
  110.                 tArray[i] = offset != -1 ? fCD.substr(fCD.indexOf('',offset-3), 2).strip(' ') : 0;
  111.         }
  112. }