Advertisement
Guest User

Untitled

a guest
Apr 15th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.75 KB | None | 0 0
  1. // ==UserScript==
  2. // @name TagPro Scoreboard Enhancer
  3. // @version 0.7.3
  4. // @description Adds multiple features and functionality to the game scoreboard
  5. // @include http://tagpro-*.koalabeast.com:*
  6. // @include http://tangent.jukejuice.com:*
  7. // @include http://*.newcompte.fr:*
  8. // @grant GM_setValue
  9. // @grant GM_getValue
  10. // @author Some Ball -1
  11. // ==/UserScript==
  12.  
  13. tagpro.ready(function() {
  14. // Keeps track of players who left the game by continuing to include them on the scoreboard, 2 lines below the regular scoreboard
  15. // Players who left are shown just below the normal scoreboard and are moved back onto the regular scoreboard if they rejoin (so long as their name hasn't changed)
  16. var keepTrackOfLeftPlayers = false; //true or false
  17.  
  18. // The minimum number of players that must be in the game before your ball's row on the scoreboard is given a white line beside it (so greater than or equal to this number)
  19. // Set to a very large number (eg 1000) to disable
  20. var minDistinguishPlayer = 0; //integer value
  21.  
  22. // Highlight the max scores/times in each column
  23. var highlightMax = true; //true or false
  24.  
  25. // Red team highlight color in the form of rgba(R, G, B, a)
  26. // where R is the amount of red from 0 to 255, G is green from 0 to 255, B is blue from 0 to 255
  27. // a is the amount of alpha from 0 to 1. 0 alpha is 100% transparent, 1 is opaque
  28. // try picking a color you like from this site: http://www.rapidtables.com/web/color/RGB_Color.htm
  29. // once you find the color you want, copy over the R, G, and B values in place of x, y, and z, respectively
  30. var redTeamColor = 'rgba(255, 0, 0, .35)'; //default 'rgba(255, 0, 0, .35)'
  31.  
  32. // Blue team highlight color, same format as above
  33. var blueTeamColor = 'rgba(0, 0, 255, .35)'; //default 'rgba(255, 0, 0, .35)'
  34.  
  35. // How wide the scoreboard is (slightly wider will allow longer names to fit on a single line)
  36. var scoreboardWidth = 900; //game default is 860
  37.  
  38.  
  39.  
  40.  
  41. //// NOTHING MORE TO EDIT //////
  42. if($('#options').css('width')==='860px' && scoreboardWidth!==860) //only modify width if it hasn't already been modified from game default (860px)
  43. {
  44. $('#options').css('width',scoreboardWidth+'px');
  45. tagpro.renderer.centerView();
  46. }
  47. var shifting = false,
  48. stayShifting = 0;
  49. $(document).keydown(function(key) {
  50. shifting = key.shiftKey;
  51. });
  52. var cats = $('#stats > thead th'), //grab column headers
  53. sorter = GM_getValue('sorter'),
  54. sortBy = 'score',
  55. order = ['name','score','s-tags','s-pops','s-grabs','s-drops','s-hold','s-captures','s-prevent','s-returns','s-support','s-powerups','points'],
  56. countOrder = 0,
  57. desc;
  58. cats.splice(-1,1); //grab headings but ignore the last column ('report' column)
  59. for(var i=0;i < cats.length;i++) //setup column header clicking, names, and ids
  60. {
  61. var col = cats.eq(i);
  62. col.attr('id',i);
  63. if(!col.attr('name'))
  64. {
  65. col.attr('name',order[i]);
  66. countOrder++;
  67. }
  68. if(sorter===i) sortBy = col.attr('name');
  69. col.click(function() {
  70. if(sorter===$(this).attr('id')) //already sorting by this column
  71. {
  72. if(desc) //currently descending so switch
  73. {
  74. $(this).css('text-decoration','overline');
  75. }
  76. else
  77. {
  78. $(this).css('text-decoration','underline');
  79. }
  80. desc = !desc;
  81. clearTimeout(clearable);
  82. clearable = setTimeout(function() { //no need to setValue all the time if people are just clicking around
  83. GM_setValue('desc',desc.toString());
  84. }, 1000, desc);
  85. }
  86. else
  87. {
  88. $('#'+sorter).css('text-decoration','none');
  89. $(this).css('text-decoration','underline');
  90. sorter = $(this).attr('id');
  91. sortBy = $(this).attr('name');
  92. desc = true;
  93. clearTimeout(clearable);
  94. clearable = setTimeout(function() {
  95. GM_setValue('sorter',sorter.toString());
  96. GM_setValue('desc',desc.toString());
  97. }, 1000, sorter, desc);
  98. }
  99. });
  100. }
  101. if(sorter && cats.eq(sorter).attr('name'))
  102. {
  103. sorter = parseInt(sorter);
  104. sortBy = cats.eq(sorter).attr('name');
  105. desc = (GM_getValue('desc')==='true');
  106. if(desc)
  107. {
  108. cats.eq(sorter).css('text-decoration','underline');
  109. }
  110. else
  111. {
  112. cats.eq(sorter).css('text-decoration','overline');
  113. }
  114. }
  115. else //first-time load
  116. {
  117. cats.eq(1).css('text-decoration','underline');
  118. sorter = 1;
  119. desc = true;
  120. GM_setValue('sorter',sorter.toString());
  121. GM_setValue('desc',desc.toString());
  122. }
  123. var sorted = [],
  124. idOrder = [],
  125. max = [],
  126. cache = {},
  127. showOld = [],
  128. wasDistinguished = false,
  129. clearable;
  130. tagpro.events.register({
  131. sortPlayers: function(players) {
  132. if(stayShifting<2 || !sorted.length)
  133. {
  134. players.sort(function(a,b){
  135. //return b.score-a.score
  136. //b-a sorts descending, a-b sorts ascending
  137. if(sorter===0) //by player name so don't want to differentiate between upper/lowercase
  138. {
  139. if (a.name.toUpperCase() > b.name.toUpperCase())
  140. {
  141. return 1;
  142. }
  143. if (a.name.toUpperCase() < b.name.toUpperCase())
  144. {
  145. return -1;
  146. }
  147. return 0; //equal
  148. }
  149. return b[sortBy]-a[sortBy];
  150. });
  151. if(!desc)
  152. {
  153. players.reverse();
  154. }
  155. sorted = $.extend([],players);
  156. if(keepTrackOfLeftPlayers && showOld.length)
  157. {
  158. players.push({});
  159. for(var i = 0;i < showOld.length;i++)
  160. {
  161. players.push(showOld[i]);
  162. }
  163. }
  164. if(stayShifting===1)
  165. {
  166. stayShifting++;
  167. idOrder = [];
  168. for(var i = 0;i < sorted.length;i++) idOrder.push(sorted[i].id);
  169. }
  170. }
  171. else if(stayShifting===2)
  172. {
  173. players.sort(function(a,b){ //sort based on the saved order of IDs
  174.  
  175. //return b.score-a.score
  176. //b-a sorts descending, a-b sorts ascending
  177. var aplace = idOrder.indexOf(a.id);
  178. var bplace = idOrder.indexOf(b.id);
  179. if(aplace<0)
  180. {
  181. idOrder.push(a.id); //if a new player joins while in static scoreboard mode then stick them at the end
  182. if(bplace<0)
  183. {
  184. idOrder.push(b.id);
  185. return 0;
  186. }
  187. return 1;
  188. }
  189. if(bplace<0)
  190. {
  191. idOrder.push(b.id);
  192. return -1;
  193. }
  194. return idOrder.indexOf(a.id)-idOrder.indexOf(b.id);
  195. });
  196. sorted = $.extend([],players);
  197. if(keepTrackOfLeftPlayers && showOld.length)
  198. {
  199. players.push({});
  200. for(var i = 0;i < showOld.length;i++)
  201. {
  202. players.push(showOld[i]);
  203. }
  204. }
  205. }
  206. if(highlightMax)
  207. {
  208. max = [];
  209. for(var i = 0;i < sorted.length;i++) //player
  210. {
  211. for(var j = 0;j < cats.length-1;j++) //for each element that can be highlighted (-1 so no name)
  212. {
  213. if(!max[j]) max[j] = [i];
  214. else
  215. {
  216. if(sorted[i][cats.eq(j+1).attr('name')]>sorted[max[j][0]][cats.eq(j+1).attr('name')])
  217. {
  218. max[j] = [i];
  219. }
  220. else if(sorted[i][cats.eq(j+1).attr('name')]==sorted[max[j][0]][cats.eq(j+1).attr('name')])
  221. {
  222. max[j].push(i);
  223. }
  224. }
  225. }
  226. }
  227. }
  228. },
  229. modifyScoreUI: function() {
  230. if(highlightMax)
  231. {
  232. for(var i = 0;i < max.length;i++)
  233. {
  234. if(max[i].length!==sorted.length) //don't highlight if everyone has max value
  235. {
  236. var current = $('.template').next();
  237. for(var j = 0;j < sorted.length;j++)
  238. {
  239. if(max[i].indexOf(j)>-1)
  240. {
  241. current.children().eq(i+1).css('background-color',sorted[j].team===1?redTeamColor:blueTeamColor);
  242. }
  243. else
  244. {
  245. current.children().eq(i+1).css('background-color','none');
  246. }
  247. current = current.next();
  248. }
  249. }
  250. }
  251. }
  252. /*var curr = $('.template').next();
  253. for(var i = 0;i < sorted.length;i++)
  254. {
  255. if(sorted[i].degree)
  256. {
  257. curr.children().get(0).innerHTML += '<sup>'+sorted[i].degree+'</sup>';
  258. }
  259. curr = curr.next();
  260. }*/
  261. if(!tagpro.spectator && sorted.length>=minDistinguishPlayer)
  262. {
  263. var current = $('#stats .template').next();
  264. for(var i = 0;i < sorted.length;i++)
  265. {
  266. if(sorted[i].id===tagpro.playerId)
  267. {
  268. current.children().eq(0).css({'border-left': '2px solid white'});
  269. }
  270. else
  271. {
  272. current.children().eq(0).css({'border-left': 'none'});
  273. }
  274. current = current.next();
  275. }
  276. wasDistinguished = true;
  277. }
  278. else if(wasDistinguished)
  279. {
  280. var current = $('#stats .template').next();
  281. for(var i = 0;i < sorted.length;i++)
  282. {
  283. current = current.children().eq(0).css({'border-left': 'none'}).next();
  284. }
  285. wasDistinguished = false;
  286. }
  287. }
  288. });
  289. if(keepTrackOfLeftPlayers)
  290. {
  291. var first = false;
  292. tagpro.socket.on('p',function(data) {
  293. data = data.u || data;
  294. for(var i = 0;i < data.length;i++)
  295. {
  296. if(!cache[data[i].id])
  297. {
  298. first = data[i].id;
  299. cache[data[i].id] = data[i];
  300. }
  301. else if(first===data[i].id)
  302. {
  303. first = false;
  304. var amatch = false;
  305. var where = -1;
  306. var scores = ['name','s-captures','s-drops','s-grabs','s-hold','s-pops','s-powerups','s-prevent','s-returns','s-support','s-tags'];
  307. for(var j = 0;j < showOld.length;j++)
  308. {
  309. var breaker = false;
  310. for(var k = 0;k < scores.length;k++)
  311. {
  312. if(data[i][scores[k]]!==showOld[j][scores[k]])
  313. {
  314. breaker = true;
  315. break;
  316. }
  317. }
  318. if(!breaker) //someone matched
  319. {
  320. amatch = true;
  321. where = j;
  322. break;
  323. }
  324. }
  325. if(amatch) //everything was the same, the same guy is back
  326. {
  327. showOld.splice(where,1);
  328. }
  329. }
  330. }
  331. });
  332. tagpro.socket.on('playerLeft',function(id) {
  333. if(tagpro.state!==1) return;
  334. if(cache[id])
  335. {
  336. cache[id].score = '';
  337. showOld.push(cache[id]);
  338. }
  339. else console.log('Error: Wasn\'t able to catch the guy that just left');
  340. });
  341. var tfs = tagpro.helpers.timeFromSeconds;
  342. tagpro.helpers.timeFromSeconds = function(val) {
  343. if(val===undefined) return ''; //get rid of those pesky NaN:NaN
  344. return tfs.apply(this,arguments);
  345. };
  346. }
  347. var old = tagpro.showOptions,
  348. init = false;
  349. tagpro.showOptions = function() {
  350. stayShifting = shifting ? 1 : 0;
  351. old.apply(this,arguments);
  352. };
  353. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement