Advertisement
Guest User

Untitled

a guest
May 19th, 2015
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Time On Ball
  3. // @version 0.1
  4. // @include http://*.koalabeast.com:*
  5. // @include http://*.jukejuice.com:*
  6. // @include http://*.newcompte.*
  7. // @author ballparts & Flail
  8. // ==/UserScript==
  9.  
  10.  
  11. ////////////////////////////
  12. // USER DEFINED VARIABLES //
  13. ////////////////////////////
  14.  
  15. // Color of text - can be hex value or color name (e.g., "white")
  16. var TEXTCOLOR = "white";
  17.  
  18. // Opacity of text - 0 is transparent, 1 is opaque
  19. var TEXTOPACITY = 0.7;
  20.  
  21. // Size of the timer text font in pixels
  22. var TEXTSIZE = 15;
  23.  
  24. // Where should the text be centered horizontally:
  25. // 0 : all the way to the left
  26. // 1 : all the way to the right
  27. var TEXTLOCATION_HOR = 0.5025;
  28.  
  29. // Where should the text be placed vertically:
  30. // 0 : all the way at the top
  31. // 1 : all the way at the bottom
  32. var TEXTLOCATION_VER = 0.49;
  33.  
  34. ////////////////////////////////
  35. // END USER DEFINED VARIABLES //
  36. ////////////////////////////////
  37.  
  38.  
  39.  
  40.  
  41. function waitForInitialized(fn) {
  42. if (!tagpro) {
  43. setTimeout(function() {
  44. waitForInitialized(fn);
  45. }, 10);
  46. } else {
  47. fn();
  48. }
  49. }
  50.  
  51. waitForInitialized(function() {
  52. tagpro.ready(function() {
  53.  
  54. //////////////////////
  55. // TIMER TEXT SETUP //
  56. //////////////////////
  57.  
  58. // SET UP TEXT FOR TIMER
  59. var timerText = tagpro.renderer.prettyText('', TEXTCOLOR);
  60.  
  61. // Set up text style
  62. var textStyle = timerText.style;
  63. textStyle.align = "center";
  64. textStyle.fill = TEXTCOLOR;
  65. textStyle.font = "bold " + TEXTSIZE + "pt Arial";
  66.  
  67. // set opacity
  68. timerText.alpha = TEXTOPACITY;
  69.  
  70. // settings object
  71. var textSettings = {
  72. TEXTLOCATION_HOR: TEXTLOCATION_HOR,
  73. TEXTLOCATION_VER: TEXTLOCATION_VER
  74. };
  75.  
  76.  
  77. function updateTimerStyle(timerText, newValue, textSettings) {
  78. // set text value
  79. timerText.setText(newValue);
  80.  
  81. // set location of text
  82. timerText.x = tagpro.renderer.canvas.width * textSettings.TEXTLOCATION_HOR - timerText.width/2;
  83. timerText.y = tagpro.renderer.canvas.height * textSettings.TEXTLOCATION_VER;
  84. }
  85.  
  86. //////////////////////////
  87. // END TIMER TEXT SETUP //
  88. //////////////////////////
  89.  
  90.  
  91. function getTimerText() {
  92. //var timeSinceLastUpdate = (Date.now() - lastUpdateTime) / 1000;
  93. //var newTimerText = timeSinceLastUpdate >= 20 ? 30 - Math.floor(timeSinceLastUpdate) : '';
  94. //return newTimerText;
  95. var millis = Math.max(0, tagpro.gameEndsAt - Date.now());
  96. var seconds = Math.floor((millis/1000))%60;
  97. if (seconds >= 0 && seconds <= 9) {
  98. return '0' + seconds;
  99. }
  100. return seconds;
  101. }
  102.  
  103. // add text sprite to TagPro's UI layer
  104. tagpro.renderer.layers.ui.addChild(timerText);
  105.  
  106.  
  107. // update timer text
  108. requestAnimationFrame(function updateTimerText() {
  109. requestAnimationFrame(updateTimerText);
  110. var newValue = getTimerText();
  111. updateTimerStyle(timerText, newValue, textSettings);
  112. });
  113. });
  114. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement