Advertisement
Guest User

CAW CAW FLAG LIGHTS with Score Flashing

a guest
Jun 17th, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.50 KB | None | 0 0
  1.  
  2. // ==UserScript==
  3. // @name CAW CAW FLAG LIGHTS with Score Flashing
  4. // @include http://*.koalabeast.com:*
  5. // @include http://*.jukejuice.com:*
  6. // @version 0.1
  7. // ==/UserScript==
  8.  
  9. USE_SOLID_COLORS = true;
  10.  
  11. var color = 0,
  12. red = 0,
  13. green = 0,
  14. blue = 0,
  15. maxColor = 127,
  16. flags = {},
  17. oldCSS = "",
  18. css = "";
  19. flagHeld = 0,
  20. lastFlagHeld = 0;
  21.  
  22. // add div overlay element to webpage
  23. var flash = '<div class="flash"></div>'
  24. $('body').find('#sound').after(flash);
  25.  
  26. // Blue CSS
  27. var blueCSS = {
  28. background: "#00007f", /* Old browsers */
  29. background: "-moz-radial-gradient(center, ellipse cover, #00007f 33%, #000000 99%)", /* FF3.6+ */
  30. background: "-webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(33%,#00007f), color-stop(99%,#000000))", /* Chrome,Safari4+ */
  31. background: "-webkit-radial-gradient(center, ellipse cover, #00007f 33%,#000000 99%)", /* Chrome10+,Safari5.1+ */
  32. background: "-o-radial-gradient(center, ellipse cover, #00007f 33%,#000000 99%)", /* Opera 12+ */
  33. background: "-ms-radial-gradient(center, ellipse cover, #00007f 33%,#000000 99%)", /* IE10+ */
  34. background: "radial-gradient(ellipse at center, #00007f 33%,#000000 99%)", /* W3C */
  35. filter: "progid:DXImageTransform.Microsoft.gradient( startColorstr='#00007f', endColorstr='#000000',GradientType=1 )", /* IE6-9 fallback on horizontal gradient */
  36. }
  37.  
  38. // Red CSS
  39. var redCSS = {
  40. background: "#7f0000", /* Old browsers */
  41. background: "-moz-radial-gradient(center, ellipse cover, #7f0000 33%, #000000 99%)", /* FF3.6+ */
  42. background: "-webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(33%,#7f0000), color-stop(99%,#000000))", /* Chrome,Safari4+ */
  43. background: "-webkit-radial-gradient(center, ellipse cover, #7f0000 33%,#000000 99%)", /* Chrome10+,Safari5.1+ */
  44. background: "-o-radial-gradient(center, ellipse cover, #7f0000 33%,#000000 99%)", /* Opera 12+ */
  45. background: "-ms-radial-gradient(center, ellipse cover, #7f0000 33%,#000000 99%)", /* IE10+ */
  46. background: "radial-gradient(ellipse at center, #7f0000 33%,#000000 99%)", /* W3C */
  47. filter: "progid:DXImageTransform.Microsoft.gradient( startColorstr='#7f0000', endColorstr='#000000',GradientType=1 )", /* IE6-9 fallback on horizontal gradient */
  48. }
  49. // Purple CSS
  50. var purpleCSS = {
  51. background: "#7f007f", /* Old browsers */
  52. background: "-moz-radial-gradient(center, ellipse cover, #7f007f 33%, #000000 99%)", /* FF3.6+ */
  53. background: "-webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(33%,#7f007f), color-stop(99%,#000000))", /* Chrome,Safari4+ */
  54. background: "-webkit-radial-gradient(center, ellipse cover, #7f007f 33%,#000000 99%)", /* Chrome10+,Safari5.1+ */
  55. background: "-o-radial-gradient(center, ellipse cover, #7f007f 33%,#000000 99%)", /* Opera 12+ */
  56. background: "-ms-radial-gradient(center, ellipse cover, #7f007f 33%,#000000 99%)", /* IE10+ */
  57. background: "radial-gradient(ellipse at center, #7f007f 33%,#000000 99%)", /* W3C */
  58. filter: "progid:DXImageTransform.Microsoft.gradient( startColorstr='#7f007f', endColorstr='#000000',GradientType=1 )", /* IE6-9 fallback on horizontal gradient */
  59. }
  60.  
  61. // Grey CSS
  62. var greyCSS = {
  63. background: "#636363", /* Old browsers */
  64. background: "-moz-radial-gradient(center, ellipse cover, #636363 33%, #000000 99%)", /* FF3.6+ */
  65. background: "-webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(33%,#636363), color-stop(99%,#000000))", /* Chrome,Safari4+ */
  66. background: "-webkit-radial-gradient(center, ellipse cover, #636363 33%,#000000 99%)", /* Chrome10+,Safari5.1+ */
  67. background: "-o-radial-gradient(center, ellipse cover, #636363 33%,#000000 99%)", /* Opera 12+ */
  68. background: "-ms-radial-gradient(center, ellipse cover, #636363 33%,#000000 99%)", /* IE10+ */
  69. background: "radial-gradient(ellipse at center, #636363 33%,#000000 99%)", /* W3C */
  70. filter: "progid:DXImageTransform.Microsoft.gradient( startColorstr='#636363', endColorstr='#000000',GradientType=1 )", /* IE6-9 fallback on horizontal gradient */
  71. }
  72.  
  73. var yellowCSS = {
  74. background: "#d1960c", /* Old browsers */
  75. background: "-moz-radial-gradient(center, ellipse cover, #d1960c 34%, #000000 99%)", /* FF3.6+ */
  76. background: "-webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(34%,#d1960c), color-stop(99%,#000000))", /* Chrome,Safari4+ */
  77. background: "-webkit-radial-gradient(center, ellipse cover, #d1960c 34%,#000000 99%)", /* Chrome10+,Safari5.1+ */
  78. background: "-o-radial-gradient(center, ellipse cover, #d1960c 34%,#000000 99%)", /* Opera 12+ */
  79. background: "-ms-radial-gradient(center, ellipse cover, #d1960c 34%,#000000 99%)", /* IE10+ */
  80. background: "radial-gradient(ellipse at center, #d1960c 34%,#000000 99%)", /* W3C */
  81. filter: "progid:DXImageTransform.Microsoft.gradient( startColorstr='#d1960c', endColorstr='#000000',GradientType=1 )", /* IE6-9 fallback on horizontal gradient */
  82. }
  83.  
  84.  
  85. // set up CSS for blue red and transparent overlays
  86. var transparentCSS = {
  87. height:"100%",
  88. width:"100%",
  89. position:"fixed",
  90. left:0,
  91. top:0,
  92. background:"rgba(0,0,0,0)"
  93. }
  94.  
  95. var blueFlashCSS = {
  96. height:"100%",
  97. width:"100%",
  98. position:"fixed",
  99. left:0,
  100. top:0,
  101. background:"rgba(0,0,200,0.5)"
  102. }
  103.  
  104. var redFlashCSS = {
  105. height:"100%",
  106. width:"100%",
  107. position:"fixed",
  108. left:0,
  109. top:0,
  110. background:"rgba(200,0,0,0.5)"
  111. }
  112.  
  113.  
  114. init();
  115.  
  116. function init(){
  117.  
  118. $("html").css("background-color", "#000000");
  119. $("html").css("background", "#000000");
  120.  
  121. if (!tagpro.map)
  122. return setTimeout(function(){init();},0);
  123.  
  124. checkPlayers();
  125.  
  126. //I place this here so that this would run after the page had finished loading. If it was placed earlier, bScore and rScore would be equal to null.
  127. bScore = tagpro.score['b']
  128. rScore = tagpro.score['r']
  129.  
  130. tagpro.socket.on("p", function(message) {
  131. if(!Array.isArray(message)) {
  132. message = [message];
  133. }
  134. for (var i = 0; i < message.length; i++) {
  135. var data = message[i].u;
  136.  
  137. if(data !== undefined) {
  138. for(var j = 0; j < data.length; j++) {
  139. if(data[j].flag || typeof data[j].flag == "object") {
  140. flagHeld = 1;
  141. checkPlayers();
  142.  
  143.  
  144. // check for change in score
  145. if (!(rScore == tagpro.score['r'])) {
  146. rScore = tagpro.score['r']
  147. flashColor('r')
  148. } else if (!(bScore == tagpro.score['b'])){
  149. bScore = tagpro.score['b']
  150. flashColor('b')
  151. }
  152.  
  153. }
  154. }
  155. } }
  156. if(!flagHeld && lastFlagHeld) {
  157. setColor(0,0,0);
  158. }
  159. lastFlagHeld = flagHeld;
  160. });
  161. }
  162.  
  163. function checkPlayers() {
  164. red = 0,
  165. green = 0,
  166. blue = 0;
  167. for (var id in tagpro.players) {
  168. var player = tagpro.players[id];
  169. if (player.flag) {
  170.  
  171. /*
  172. blue = player.flag == 1 ? maxColor : blue;
  173. red = player.flag == 2 ? maxColor : red;
  174. green = player.flag == 3 ? maxColor : 0;*/
  175.  
  176. // from cumflakes comment; background is same color as the player who is carrying the flag.
  177. red = player.flag == 2 ? maxColor : red;
  178. blue = player.flag == 1 ? maxColor : blue;
  179. red = (player.team == 1 && player.flag == 3) ? maxColor : red;
  180. blue = (player.team == 2 && player.flag == 3) ? maxColor : blue;
  181. }
  182. }
  183.  
  184. var newColor = red + "," + green + "," + blue;
  185. if (color != newColor ){
  186. color = newColor;
  187. setColor(red,green,blue);
  188. }
  189. }
  190.  
  191.  
  192. // change overlay to either blue or red depending on who scored
  193. function flashColor(c) {
  194.  
  195. if (c == 'r') {
  196. css = redFlashCSS
  197. } else {
  198. css = blueFlashCSS
  199. }
  200. $('.flash').css(css)
  201.  
  202. setTimeout(function(){flashOff()}, 100);
  203. }
  204.  
  205. // revert overlay to transparent
  206. function flashOff() {
  207. $('.flash').css(transparentCSS)
  208. }
  209.  
  210.  
  211.  
  212. function setColor(red,green,blue){
  213. if(USE_SOLID_COLORS) {
  214. colorString = "#";
  215. colorString += ("0"+(red.toString(16))).slice(-2);
  216. colorString += ("0"+(green.toString(16))).slice(-2);
  217. colorString += ("0"+(blue.toString(16))).slice(-2);
  218.  
  219. $("html").css("background-color", colorString);
  220. $("html").css("background", colorString);
  221. }
  222. else {
  223. console.log("RED: ", red, "BLUE: ", blue);
  224. if(red && blue) {
  225. css = purpleCSS;
  226. }
  227. else if (red) {
  228. css = redCSS;
  229. }
  230. else if (blue) {
  231. css = blueCSS;
  232. }
  233. else {
  234. css = greyCSS;
  235. }
  236. $("html").css(css);
  237. }
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement