Advertisement
Guest User

Score Flashing

a guest
Jun 18th, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Score Flashing
  3. // @include http://*.koalabeast.com:*
  4. // @include http://*.jukejuice.com:*
  5. // @version 0.1
  6. // ==/UserScript==
  7.  
  8.  
  9. var redScore = 0,
  10. blueScore = 0,
  11. firstRun = 1,
  12. FlashDuration = 150;
  13.  
  14.  
  15. // add div overlay element to webpage
  16. var overlay = '<div class="overlay"></div>'
  17. $('body').find('#sound').after(overlay);
  18.  
  19. // set up CSS for blue red and transparent overlays
  20. var transparentOverlay = {
  21. height:"100%",
  22. width:"100%",
  23. position:"fixed",
  24. left:0,
  25. top:0,
  26. background:"rgba(0,0,0,0)"
  27. }
  28.  
  29. var blueOverlay = {
  30. height:"100%",
  31. width:"100%",
  32. position:"fixed",
  33. left:0,
  34. top:0,
  35. background:"rgba(0,0,200,0.5)"
  36. }
  37.  
  38. var redOverlay = {
  39. height:"100%",
  40. width:"100%",
  41. position:"fixed",
  42. left:0,
  43. top:0,
  44. background:"rgba(200,0,0,0.5)"
  45. }
  46.  
  47. tagpro.socket.on("score", function(message) {
  48.  
  49. console.log(message)
  50. if (firstRun) {
  51. redScore = message['r']
  52. blueScore = message['b']
  53. firstRun = 0
  54.  
  55. } else {
  56. if (!(redScore == message['r'])) {
  57. flashColor('r')
  58. redScore = message['r']
  59. } else if (!(blueScore == message['b'])){
  60. flashColor('b')
  61. blueScore = message['b']
  62. }
  63. }
  64. });
  65.  
  66.  
  67. // change overlay to either blue or red depending on who scored
  68. function flashColor(c) {
  69.  
  70. if (c == 'r') {
  71. css = redOverlay
  72. } else {
  73. css = blueOverlay
  74. }
  75. $('.overlay').css(css)
  76.  
  77. setTimeout(function(){flashOff()}, FlashDuration);
  78. }
  79.  
  80. // revert overlay to transparent
  81. function flashOff() {
  82. $('.overlay').css(transparentOverlay)
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement