Advertisement
Guest User

Untitled

a guest
May 19th, 2015
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Time On Ball
  3. // @version 0.3
  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 TEXT_COLOR = "white";
  17.  
  18. // Opacity of text - 0 is transparent, 1 is opaque
  19. var TEXT_OPACITY = 0.7;
  20.  
  21. // Size of the timer text font in pixels
  22. var TEXT_SIZE = 15;
  23.  
  24. // Whether to rotate with the player.
  25. var ROTATE = false;
  26.  
  27. ////////////////////////////////
  28. // END USER DEFINED VARIABLES //
  29. ////////////////////////////////
  30.  
  31. var TILE_SIZE = 40;
  32.  
  33. // Wait until the tagpro object exists, and add the function to tagpro.ready
  34. function addToTagproReady(fn) {
  35. // Make sure the tagpro object exists.
  36. if (typeof tagpro !== "undefined") {
  37. tagpro.ready(fn);
  38. } else {
  39. // If not ready, try again after a short delay.
  40. setTimeout(function() {
  41. addToTagproReady(fn);
  42. }, 0);
  43. }
  44. }
  45.  
  46. function waitForId(fn) {
  47. if (typeof tagpro !== "undefined" && tagpro.playerId) {
  48. fn();
  49. } else {
  50. setTimeout(function() {
  51. waitForId(fn);
  52. });
  53. }
  54. }
  55.  
  56. /**
  57. * Get text for overlaying on center of tiles.
  58. * @param {string} [color="#FFFFFF"] - The fill color to use for the text.
  59. * @return {PIXI.Text} - The created text.
  60. */
  61. function makeText() {
  62. var text = new PIXI.Text("", {
  63. font: "bold " + TEXT_SIZE + "pt Arial",
  64. fill: TEXT_COLOR,
  65. stroke: "#000000",
  66. strokeThickness: 3,
  67. alpha: TEXT_OPACITY,
  68. align: "center"
  69. });
  70. text.anchor = new PIXI.Point(0.5, 0.5);
  71. text.x = text.y = 20;
  72. text.visible = false;
  73. return text;
  74. }
  75.  
  76. addToTagproReady(function() {
  77. waitForId(function() {
  78. var text = makeText();
  79. var sprites = tagpro.players[tagpro.playerId].sprites;
  80. sprites.timer = text;
  81. sprites.ball.addChild(sprites.timer);
  82.  
  83.  
  84. var stdUpdate = tagpro.ui.update;
  85. tagpro.ui.update = function() {
  86. stdUpdate.apply(null, arguments);
  87. var millis = Math.max(0, tagpro.gameEndsAt - Date.now());
  88. var seconds = Math.floor((millis/1000))%60;
  89. if (seconds >= 0 && seconds <= 9) {
  90. seconds = '0' + seconds;
  91. }
  92. text.setText(seconds);
  93. if (ROTATE) {
  94. text.rotation = tagpro.players[tagpro.playerId].angle;
  95. }
  96. };
  97. });
  98. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement