Guest User

score and grab flashing

a guest
Jun 20th, 2014
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. // ==UserScript==
  2. // @name score and grab flashing
  3. // @namespace http://www.reddit.com/user/happytagpro/
  4. // @include http://tagpro-*.koalabeast.com:*
  5. // @include http://tangent.jukejuice.com:*
  6. // @include http://maptest.newcompte.fr:*
  7. // @author happy
  8. // @version o.2
  9. // ==/UserScript==
  10.  
  11. var FlashDuration = 200;
  12.  
  13. // set up CSS for blue red and transparent overlays
  14. var transparentOverlay = {
  15. height:"100%",
  16. width:"100%",
  17. position:"fixed",
  18. left:0,
  19. top:0,
  20. background:"rgba(0,0,0,0)"
  21. }
  22.  
  23. var blueOverlay = {
  24. height:"100%",
  25. width:"100%",
  26. position:"fixed",
  27. left:0,
  28. top:0,
  29. background:"rgba(0,0,200,0.5)"
  30. }
  31.  
  32. var redOverlay = {
  33. height:"100%",
  34. width:"100%",
  35. position:"fixed",
  36. left:0,
  37. top:0,
  38. background:"rgba(200,0,0,0.5)"
  39. }
  40.  
  41. // add div overlay element to webpage
  42. var overlay = '<div class="overlay"></div>'
  43. $('body').find('#sound').after(overlay);
  44.  
  45. //when a sound is played, a message is sent as the arguement of function(message)
  46.  
  47. tagpro.socket.on("sound", function(message) {
  48.  
  49. //I couldnt figure out how to set these variables AFTER the page is fully loaded. they kept on being set to null when placed earlier.
  50. teamColor = tagpro.players[tagpro.playerId].team == 1 ? 'r' : 'b';
  51. opponentColor = teamColor == 'r' ? 'b' : 'r';
  52.  
  53. // list of sound names:
  54. //burst, alert, cheering, drop, sigh, powerup, pop, click, explosion, countdown, friendlydrop, friendlyalert, alertlong (not currently used), go, degreeup, teleport
  55. //the screen will flash a certian color, depending on what sound is played.
  56. sound = message.s
  57. if (sound == "cheering" | sound == "friendlyalert") {
  58. flashColor(teamColor)
  59. } else if (sound == "sigh" | sound == "alert") {
  60. flashColor(opponentColor)
  61. }
  62.  
  63. });
  64.  
  65. // change overlay to either blue or red depending on who scored, then revert overlay to transparent
  66. function flashColor(c) {
  67. css = c == 'r' ? redOverlay : blueOverlay;
  68. $('.overlay').css(css)
  69. setTimeout(function(){$('.overlay').css(transparentOverlay)}, FlashDuration);
  70. }
Add Comment
Please, Sign In to add comment