Guest User

Untitled

a guest
Jul 8th, 2014
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.28 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Consistent Team Colors
  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. // @license WTFPL
  8. // @author happy
  9. // @version 0.2.3
  10. // ==/UserScript==
  11.  
  12. //Set your team color and other preferences here:
  13. teamColor = 'blue'
  14. translateWords = false //when colors tiles are switched, swap the words 'red' and 'blue' in chat, system messages are always swapped
  15. useBackgroundWarnings = true
  16. useFlashAlertsForScoring = true
  17.  
  18.  
  19. opponentColor = teamColor == 'blue' ? 'red' : 'blue';
  20. tagpro.switchedColors = false
  21. colorId = {red:1, blue:2}
  22. teamId = 0
  23.  
  24. function checkTeam() {
  25.  
  26. //wait until you'be been assigned to a team and the tiles have been loaded.
  27. if (!tagpro.players[tagpro.playerId] | !tagpro.tiles) {
  28. return setTimeout(checkTeam,10)
  29. }
  30.  
  31. //if the team color you've been assigned to is different from your preference, switch team colored tiles
  32. teamId = tagpro.players[tagpro.playerId]['team']
  33. if (teamId != colorId[teamColor]) {
  34. tagpro.switchedColors = true
  35. switchTiles()
  36. }
  37. }
  38. checkTeam()
  39.  
  40. //switch tiles back if you switch teams
  41. tagpro.socket.on('chat',function(m){
  42. if (m.message.indexOf("has switched to the")>-1) {
  43. setTimeout(function() {
  44. if (teamId != tagpro.players[tagpro.playerId]['team']) {
  45. teamId = tagpro.players[tagpro.playerId]['team']
  46. switchTiles()
  47. tagpro.switchedColors = !tagpro.switchedColors
  48. }
  49. },500)
  50. }
  51. })
  52.  
  53. function switchTiles() {
  54. //store red tiles temporarily
  55. rFlag = tagpro.tiles[3]
  56. rEmptyFlag = tagpro.tiles[3.1]
  57. rSpeedPad = tagpro.tiles[14]
  58. rEmptySpeedPad = tagpro.tiles[14.1]
  59. rGate = tagpro.tiles[9.2]
  60. rZone = tagpro.tiles[17]
  61. rTeam = tagpro.tiles[11]
  62. rBall = tagpro.tiles['redball']
  63. rFlag2 = tagpro.tiles['redflag']
  64.  
  65. //set red tiles equal to blue tiles
  66. tagpro.tiles[3] = tagpro.tiles[4]
  67. tagpro.tiles[3.1] = tagpro.tiles[4.1]
  68. tagpro.tiles[14] = tagpro.tiles[15]
  69. tagpro.tiles[14.1] = tagpro.tiles[15.1]
  70. tagpro.tiles[9.2] = tagpro.tiles[9.3]
  71. tagpro.tiles[17] = tagpro.tiles[18]
  72. tagpro.tiles[11] = tagpro.tiles[12]
  73. tagpro.tiles['redball'] = tagpro.tiles['blueball']
  74. tagpro.tiles['redflag'] = tagpro.tiles['blueflag']
  75.  
  76. //set blue tiles equal to red tiles that were stored earlier
  77. tagpro.tiles[4] = rFlag
  78. tagpro.tiles[4.1] = rEmptyFlag
  79. tagpro.tiles[15] = rSpeedPad
  80. tagpro.tiles[15.1]= rEmptySpeedPad
  81. tagpro.tiles[9.3] = rGate
  82. tagpro.tiles[18] = rZone
  83. tagpro.tiles[12] = rTeam
  84. tagpro.tiles['blueball'] = rBall
  85. tagpro.tiles['blueflag'] = rFlag2
  86.  
  87. tagpro.api.redrawBackground()
  88. }
  89.  
  90.  
  91. //switch score colors and position
  92. tagpro.ui.scores = function (e,t,n){
  93. if (tagpro.switchedColors) {
  94. color1 = "rgba(0, 0, 255, .5)"
  95. color2 = "rgba(255, 0, 0, .5)"
  96. X = -1
  97. } else {
  98. color2 = "rgba(0, 0, 255, .5)"
  99. color1 = "rgba(255, 0, 0, .5)"
  100. X=1
  101. }
  102. e.save(),e.textAlign="center",e.fillStyle=color1,e.font="bold 40pt Arial",e.fillText(tagpro.score.r,t.x-120*X,n.height-50),e.fillStyle=color2,e.fillText(tagpro.score.b,t.x+120*X,n.height-50),e.restore()}
  103.  
  104. //switch flag state positions
  105. tagpro.ui.flags = function (e,t,n){
  106. if (tagpro.switchedColors) {
  107. yellowLeft = 120
  108. yellowRight = -160
  109. red = -120
  110. blue = 80
  111. } else {
  112. yellowLeft = -160
  113. yellowRight = 120
  114. red = 80
  115. blue = -120
  116. }
  117. tagpro.ui.redFlagTaken&&(e.globalAlpha=.75,tagpro.tiles.draw(e,"redflag",{x:t.x+red,y:n.height-50},30,30)),tagpro.ui.blueFlagTaken&&(e.globalAlpha=.75,tagpro.tiles.draw(e,"blueflag",{x:t.x+blue,y:n.height-50},30,30)),tagpro.ui.yellowFlagTakenByRed&&(e.globalAlpha=.75,tagpro.tiles.draw(e,"yellowflag",{x:t.x+yellowLeft,y:n.height-50},30,30)),tagpro.ui.yellowFlagTakenByBlue&&(e.globalAlpha=.75,tagpro.tiles.draw(e,"yellowflag",{x:t.x+yellowRight,y:n.height-50},30,30)),e.globalAlpha=1}
  118.  
  119.  
  120. //switch winning alert color/message
  121. originalAlert = tagpro.ui.largeAlert
  122. tagpro.ui.largeAlert = function (e,t,n,r,i){
  123. if (tagpro.switchedColors) {
  124. switch(r) {
  125. case "Blue Team Wins!":
  126. r = "Red Team Wins!"
  127. i = "#ff0000"
  128. break;
  129. case "Red Team Wins!":
  130. r = "Blue Team Wins!"
  131. i = "#0000ff"
  132. break;
  133. }
  134. }
  135. return originalAlert(e,t,n,r,i)
  136. }
  137.  
  138. //swap colors and words in chat, taken from NewCompte script
  139. prettyTextOriginal = tagpro.prettyText
  140. tagpro.prettyText= function(e,t,n,r,s,o,u) {
  141.  
  142. if (tagpro.switchedColors) {
  143. //swap the words 'red' and 'blue' in chat. used placeholders so that a message with both words will still be switched properly
  144. //always swap words for system messages.
  145. if (e.indexOf("team")>-1 & (e.indexOf("has switched to the")>-1 | e.indexOf("has joined the")>-1 | e.indexOf("left the")>-1)) {
  146. e=e.replace(/blue/gi, "placeHolderForBlue");
  147. e=e.replace(/red/gi, "placeHolderForRed");
  148. e=e.replace("placeHolderForBlue", "red");
  149. e=e.replace("placeHolderForRed", "blue");
  150. } else if (translateWords) {
  151. e=e.replace(/blue/gi, "placeHolderForBlue");
  152. e=e.replace(/red/gi, "placeHolderForRed");
  153. e=e.replace("placeHolderForBlue", "red");
  154. e=e.replace("placeHolderForRed", "blue");
  155. }
  156.  
  157.  
  158. //swap colors
  159. switch(r) {
  160. case "#FFB5BD":
  161. r = "#CFCFFF";
  162. break;
  163. case "#CFCFFF":
  164. r = "#FFB5BD";
  165. break;
  166. }
  167. }
  168. return prettyTextOriginal(e,t,n,r,s,o,u)
  169. }
  170.  
  171.  
  172. //swap colors in stats
  173. // @name Tagpro Color Switcher
  174. // @namespace http://www.reddit.com/user/NewCompte
  175. // @include http://tagpro-*.koalabeast.com:*
  176. // @include http://tangent.jukejuice.com:*
  177. // @include http://maptest.newcompte.fr:*
  178. // @license WTFPL
  179. // @author NewCompte, slightly modified by happy
  180. // @version 0.28
  181.  
  182. function myColorBlindScript () {
  183. var dummyred = document.createElement("div");
  184. dummyred.id = "dummyred";
  185. dummyred.style.display = "none";
  186. document.body.appendChild(dummyred);
  187. $('#dummyred').css("color", "#FFB5BD");
  188. var redstyle = $('#dummyred').css("color");
  189. var dummyblue = document.createElement("div");
  190. dummyblue.id = "dummyblue";
  191. dummyblue.style.display = "none";
  192. document.body.appendChild(dummyblue);
  193. $('#dummyblue').css("color", "#CFCFFF");
  194. var bluestyle = $('#dummyblue').css("color");
  195. var drawOptions = false;
  196. tagpro.showOptions = function () {
  197. if (drawOptions) {
  198. drawOptions = false;
  199. $("div#options").hide(), $("#name").blur();
  200. } else {
  201. drawOptions = true;
  202. var e = $("div#options");
  203. e.find("#name").val(tagpro.players[tagpro.playerId].name),e.css({left:$(document.body).width()/2-e.width()/2,top:$(document.body).height()/2-e.height()/2});
  204. var t = function () {
  205. //console.log("in the function that updates stats, drawOptions="+drawOptions);
  206. var r=e.find("tbody.stats"),
  207. i=r.find("tr.template"),
  208. s=[];
  209. r.find("tr").not(".template").remove();
  210. for (var o in tagpro.players) s.push(tagpro.players[o]);
  211. s.sort(function(e,t){return t.score-e.score}),
  212. s.forEach(function(e) {
  213. var t=i.clone().removeClass("template").appendTo(r).find("td");
  214. if (tagpro.switchedColors) {
  215. color = e.team==1?"#CFCFFF":"#FFB5BD"
  216. } else {
  217. color = e.team==2?"#CFCFFF":"#FFB5BD"
  218. }
  219.  
  220. t.eq(0).find(".scoreName").text(e.name).css("color",color).end().find(".scoreAuth").html(e.auth?"✓":"").end(),t.eq(1).text(e.score),t.eq(2).text(e["s-tags"]),t.eq(3).text(e["s-pops"]),t.eq(4).text(e["s-grabs"]),t.eq(5).text(e["s-drops"]),t.eq(6).text(tagpro.helpers.timeFromSeconds(e["s-hold"],!0)),t.eq(7).text(e["s-captures"]),t.eq(8).text(tagpro.helpers.timeFromSeconds(e["s-prevent"],!0)),t.eq(9).text(e["s-returns"]),t.eq(10).text(e["s-support"]),t.eq(11).text(e["points"]==null?"-":e.points),
  221. t.find("a.kick").attr("href",e.id)
  222. }),
  223. drawOptions&&setTimeout(t,1e3)
  224. };
  225. drawOptions&&t();
  226. e.show();
  227. }
  228. };
  229. }
  230.  
  231. var source = "(" + myColorBlindScript + ")()";
  232. var thescript = document.createElement('script');
  233. thescript.setAttribute("type", "application/javascript");
  234. thescript.textContent = source;
  235. document.body.appendChild(thescript);
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243. ////////////////////////////////////////////////////////////////////////////////////////////
  244. //OPTIONAL ADD-ONS
  245.  
  246.  
  247. ////////////////////////////////////////////////////////////////////////////////////////////
  248. //background warning
  249.  
  250. if (useBackgroundWarnings) {
  251. var previousFlagStateHash = 4;
  252. var colorIntensity = 127;
  253. tagpro.socket.on("p", function(m) {
  254.  
  255. if (tagpro.switchedColors) {
  256. blueTeamHasFlag = tagpro.ui.blueFlagTaken | tagpro.ui.yellowFlagTakenByRed
  257. redTeamHasFlag = tagpro.ui.redFlagTaken | tagpro.ui.yellowFlagTakenByBlue
  258.  
  259. } else {
  260. redTeamHasFlag = tagpro.ui.blueFlagTaken | tagpro.ui.yellowFlagTakenByRed
  261. blueTeamHasFlag = tagpro.ui.redFlagTaken | tagpro.ui.yellowFlagTakenByBlue
  262. }
  263.  
  264. currentHash = redTeamHasFlag + blueTeamHasFlag*2
  265. if (previousFlagStateHash != currentHash) {
  266. previousFlagState = currentHash
  267. color = 'rgb('+colorIntensity*redTeamHasFlag.toString()+',0,'+colorIntensity*blueTeamHasFlag.toString()+')'
  268. $("html").css('background', color)
  269. }
  270. });
  271. }
  272.  
  273.  
  274. ////////////////////////////////////////////////////////////////////////////////////////////
  275. //flash alerts for scoring or other sounds.
  276.  
  277. if (useFlashAlertsForScoring) {
  278. var FlashDuration = 200;
  279.  
  280. // set up CSS for blue red and transparent overlays
  281. var transparentOverlay = {
  282. height:"100%",
  283. width:"100%",
  284. position:"fixed",
  285. left:0,
  286. top:0,
  287. background:"rgba(0,0,0,0)"
  288. }
  289.  
  290. var blueOverlay = {
  291. height:"100%",
  292. width:"100%",
  293. position:"fixed",
  294. left:0,
  295. top:0,
  296. background:"rgba(0,0,200,0.5)"
  297. }
  298.  
  299. var redOverlay = {
  300. height:"100%",
  301. width:"100%",
  302. position:"fixed",
  303. left:0,
  304. top:0,
  305. background:"rgba(200,0,0,0.5)"
  306. }
  307.  
  308. // add div overlay element to webpage
  309. var overlay = '<div class="overlay"></div>'
  310. $('body').find('#sound').after(overlay);
  311.  
  312. //when a sound is played, a message is sent as the arguement of function(message)
  313. tagpro.socket.on("sound", function(message) {
  314.  
  315. //the screen will flash a certian color, depending on what sound is played.
  316. //list of sound names: //burst, alert, cheering, drop, sigh, powerup, pop, click, explosion, countdown, friendlydrop, friendlyalert, go, degreeup, teleport
  317. //you can add these sount names to into the if/ else if statments if you want flashes to occur when they play.
  318. sound = message.s
  319. if (sound == "cheering") {
  320. flashColor(teamColor)
  321. } else if (sound == "sigh") {
  322. flashColor(opponentColor)
  323. }
  324. });
  325.  
  326. // change overlay to either blue or red depending on who scored, then revert overlay to transparent
  327. function flashColor(c) {
  328. css = c == 'red' ? redOverlay : blueOverlay;
  329. $('.overlay').css(css)
  330. setTimeout(function(){$('.overlay').css(transparentOverlay)}, FlashDuration);
  331. }
  332. }
Add Comment
Please, Sign In to add comment