Satrex_

Leaderboard reset timer

Aug 2nd, 2014
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name          TagPro Leaderboard Countdown
  3. // @namespace     http://www.reddit.com/user/Satrex/
  4. // @description   Shows a Countdown on the leaderboard until the reset
  5. // @include       http://tagpro-*.koalabeast.com/boards
  6. // @include       http://tangent.jukejuice.com/boards
  7. // @include       http://maptest.newcompte.fr/boards
  8. // @copyright     2014+ Satrex
  9. // @author        Satrex
  10. // @version       1.0
  11. // ==/UserScript==
  12. var canvas = document.createElement('canvas');
  13. canvas.id = "CursorLayer";
  14. canvas.width = 213;
  15. canvas.height = 25;
  16. canvas.style.position = "absolute";
  17. canvas.style.border = "1px solid";
  18. canvas.style.display = "inline";
  19. canvas.style.backgroundColor = 'rgba(0,0,0,1)';
  20. canvas.style.marginTop = "195px"
  21. canvas.style.marginLeft = window.innerWidth  +"px";
  22.  
  23. var body = document.getElementsByTagName("body")[0];
  24. body.insertBefore(canvas, body.firstChild);
  25.  
  26. cursorLayer = document.getElementById("CursorLayer");
  27. var ctx = cursorLayer.getContext("2d");
  28.  
  29. function daysInMonth(month,year) {
  30.     return new Date(year, month, 0).getDate();
  31. }
  32.  
  33. function daily()
  34. {
  35.     var dayboard = document.getElementById("Day");
  36.     if(dayboard.style.display != "none")
  37.     {
  38.         cursorLayer.width = 213;
  39.         var daily = new Date();
  40.                 var dhours = daily.getUTCHours();
  41.         var dmonth = daily.getUTCMonth() + 1;
  42.         var dyear = daily.getUTCFullYear();
  43.              
  44.         var dsLeft = 59 - daily.getUTCSeconds();
  45.         var dmLeft = 59 - daily.getMinutes();
  46.         var dhLeft = 19 - dhours;
  47.        
  48.         if (dhLeft< 0)
  49.         {
  50.             dhLeft = 24 + dhLeft;    
  51.         }
  52.        
  53.         var s10 = "";
  54.         var m10 = "";
  55.         var h10 = "";
  56.        
  57.         if (dsLeft < 10)
  58.         {
  59.             s10 = "0";
  60.            
  61.         }
  62.         if (dmLeft <10)
  63.         {
  64.             m10 = "0";
  65.            
  66.         }
  67.         if (dhLeft <10)
  68.         {
  69.             h10 = "0";
  70.            
  71.         }
  72.         var actualtimer = h10 + (dhLeft).toString() + ":"+ m10 + (dmLeft).toString() + ":" + s10 + (dsLeft).toString();
  73.        
  74.         actualtimer = "Time until reset: " + actualtimer;
  75.         ctx.fillStyle="#FFFFFF";
  76.         ctx.font="20px Hallo Sans Light";
  77.         ctx.clearRect(0, 0, canvas.width, canvas.height);
  78.        
  79.         ctx.fillText(actualtimer,1,20);
  80.     }
  81.    
  82.    
  83. }
  84. setInterval(daily,1000);
  85.  
  86. function weekly()
  87. {
  88.     var weekboard = document.getElementById("Week");
  89.     if(weekboard.style.display != "none")
  90.     {
  91.         cursorLayer.width = 230;
  92.         var w = new Date();
  93.  
  94.                 var whours = w.getUTCHours();
  95.         var wmonth = w.getUTCMonth() + 1;
  96.         var wyear = w.getUTCFullYear();
  97.              
  98.         var wsLeft = 59 - w.getUTCSeconds();
  99.         var wmLeft = 59 - w.getMinutes();
  100.         var whLeft = 19 - whours;
  101.        
  102.        
  103.      
  104.         if(whLeft<0)
  105.         {
  106.             whLeft = 24 + whLeft;    
  107.         }
  108.        
  109.         var ws10 = "";
  110.         var wm10 = "";
  111.         var wh10 = "";
  112.        
  113.         if (wsLeft < 10)
  114.         {
  115.             ws10 = "0";
  116.            
  117.         }
  118.         if (wmLeft < 10)
  119.         {
  120.             wm10 = "0";
  121.            
  122.         }
  123.         if (whLeft < 10)
  124.         {
  125.             wh10 = "0";
  126.            
  127.         }
  128.         var weekday = w.getUTCDay();
  129.        
  130.         if (weekday == 0)
  131.         {weekday = 7;}
  132.        
  133.         weekday = 7 - weekday;
  134.        
  135.        
  136.        
  137.        
  138.          if(w.getUTCHours() >= 20)
  139.        {
  140.             weekday = weekday - 1;
  141.        if(weekday == -1)
  142.        {weekday = 6;}
  143.            
  144.        }
  145.        
  146.        
  147.        
  148.        
  149.        
  150.        
  151.         var weeklytimer = weekday.toString() + ":" + wh10 + (whLeft).toString() + ":" + wm10 + (wmLeft).toString() + ":" + ws10 + (wsLeft).toString();
  152.         weeklytimer = "Time until reset: " + weeklytimer;
  153.         ctx.fillStyle="#FFFFFF";
  154.         ctx.font="20px Hallo Sans Light";
  155.         ctx.clearRect(0, 0, canvas.width, canvas.height);
  156.        
  157.         ctx.fillText(weeklytimer,1,20);
  158.     }
  159.    
  160.    
  161. }
  162. setInterval(weekly,1000);
  163.  
  164.  
  165.  
  166.  
  167. function monthly()
  168. {
  169.     var monthboard = document.getElementById("Month");
  170.     if(monthboard.style.display != "none")
  171.     {
  172.        
  173.        
  174.         var m = new Date();
  175.  
  176.         var mhours = m.getUTCHours();
  177.         var mmonth = m.getUTCMonth() + 1;
  178.         var myear = m.getUTCFullYear();
  179.         var day = m.getUTCDate();
  180.        
  181.         var msLeft = 59 - m.getUTCSeconds();
  182.         var mmLeft = 59 - m.getUTCMinutes();
  183.         var mhLeft = 19 - mhours;
  184.        
  185.    
  186.        
  187.         if (mhLeft< 0)
  188.         {
  189.             mhLeft = 24 + mhLeft;    
  190.         }
  191.        
  192.         var s10 = "";
  193.         var m10 = "";
  194.         var h10 = "";
  195.        
  196.         if (msLeft < 10)
  197.         {
  198.             s10 = "0";
  199.            
  200.         }
  201.         if (mmLeft <10)
  202.         {
  203.             m10 = "0";
  204.            
  205.         }
  206.         if (mhLeft <10)
  207.         {
  208.             h10 = "0";
  209.            
  210.         }
  211.         var actualtimer = h10 + (mhLeft).toString() + ":"+ m10 + (mmLeft).toString() + ":" + s10 + (msLeft).toString();
  212.        
  213.        
  214.         var ndays = daysInMonth(mmonth,m.getUTCFullYear());
  215.  
  216.       day = ndays - day;
  217.        
  218.        
  219.        
  220.         if( day > 9)
  221.         {
  222.             cursorLayer.width = 240;
  223.         }
  224.         if( day < 10)
  225.         {
  226.             cursorLayer.width = 230;
  227.         }
  228.        if(m.getUTCHours() >= 20)
  229.        {
  230.            day = day - 1;
  231.        }
  232.         if(day == -1)
  233.         {
  234.             if(mmonth == 11)
  235.             {day = daysInMonth(01 ,m.getUTCFullYear() + 1);}
  236.        
  237.             else{day = daysInMonth(mmonth + 1 ,m.getUTCFullYear());}
  238.         }
  239.        
  240.         actualtimer = "Time until reset: " + day.toString() +":" + actualtimer;
  241.         ctx.fillStyle="#FFFFFF";
  242.         ctx.font="20px Hallo Sans Light";
  243.         ctx.clearRect(0, 0, canvas.width, canvas.height);
  244.        
  245.         ctx.fillText(actualtimer,1,20);
  246.     }
  247.    
  248.    
  249. }
  250. setInterval(monthly,1000);
  251.  
  252. function center()
  253. {
  254.     cursorLayer.style.marginLeft = Math.round((window.innerWidth  / 2) - (cursorLayer.width /2)) +"px";
  255. }
  256. setInterval(center,30);
Add Comment
Please, Sign In to add comment