Replay Rewrite - Player Highlight On Replay

Highlight players you own when watching GLB replays with the replay rewrite script.

  1. // ==UserScript==
  2. // @name Replay Rewrite - Player Highlight On Replay
  3. // @description Highlight players you own when watching GLB replays with the replay rewrite script.
  4. // @namespace pbr/phor
  5. // @include http://*goallineblitz.com/game/home.pl
  6. // @include http://*goallineblitz.com/game/replay.pl?game_id=*&pbp_id=*
  7. // @include http://glb.warriorgeneral.com/game/home.pl
  8. // @include http://glb.warriorgeneral.com/game/replay.pl?game_id=*&pbp_id=*
  9. // @copyright 2009, pabst
  10. // @license (CC) Attribution Share Alike; http://creativecommons.org/licenses/by-sa/3.0/
  11. // @version 14.01.301
  12. // @require https://greasyfork.org/scripts/1371-libpbr2/code/libpbr2.js?version=3533
  13. // ==/UserScript==
  14.  
  15. /*
  16. *
  17. * pabst did this 08/06/26+
  18. *
  19. *
  20. */
  21.  
  22. var scriptName = "Player Highlight";
  23. var scriptVersion = "14.01.30";
  24. var scriptWebpage = "http://userscripts.org/scripts/show/54518";
  25.  
  26. var other_player_ids = [];
  27.  
  28. var cookieName = "pbr_pl";
  29. var myPlayers;
  30. var cookieDate;
  31. var cookieData;
  32.  
  33. window.setTimeout( function() {
  34. player_highlight_on_replay();
  35. }, 1000);
  36.  
  37. function player_highlight_on_replay() {
  38. var inetAddress = window.location.toString();
  39.  
  40. if (inetAddress.match("replay.pl") != null) {
  41. cookieData = readCookieData(cookieName);
  42. console.log("CD="+cookieData);
  43.  
  44. if (cookieData != null) {
  45. myPlayers = cookieData;
  46. }
  47. else {
  48. myPlayers = new Array();
  49. }
  50.  
  51. for (var i=0; i<other_player_ids.length; i++) {
  52. var p = new Player();
  53. p.id = other_player_ids[i];
  54. myPlayers.push(p);
  55. }
  56.  
  57. console.log("players found = "+myPlayers.length);
  58. init();
  59. }
  60. else {
  61. // -------- on the home page ---------
  62. parsePage(document.getElementById("players").innerHTML);
  63. }
  64. }
  65.  
  66. function colorize(id, color) {
  67. var dot = document.getElementById(id);
  68. if (dot != null) {
  69. console.log("changing color for "+id);
  70. dot.style.backgroundColor = color;
  71. }
  72. else {
  73. console.log("waiting for color");
  74. setTimeout(function() {
  75. colorize(id, color);
  76. }, 500);
  77. }
  78. }
  79.  
  80. function activate(e) {
  81. lock();
  82. console.log("activate highlight");
  83.  
  84. var player_names = document.getElementsByClassName("player_name");
  85. for (var j=0; j<player_names.length; j++) {
  86. var href = player_names[j].href.toString().split("=")[1];
  87. //console.log(j+"/"+href.length+" --> looking for player "+href);
  88.  
  89. for (var i=0; i<myPlayers.length; i++) {
  90. var id = myPlayers[i].id;
  91. //console.log("\t"+i+" id is "+id);
  92. if (href == myPlayers[i].id) {
  93. var color = getColor(i);
  94. player_names[j].style.color = color;
  95. colorize(id, color);
  96. }
  97. }
  98. }
  99.  
  100. unlock();
  101. }
  102.  
  103. function getColor(idx) {
  104. var color;
  105. var b = "00"+(idx%8).toString(2);
  106. b = b.slice(b.length-3);
  107.  
  108. var color = "#";
  109. for (var i=0; i<3; i++) {
  110. var ch = b.slice(i,i+1);
  111. if (ch == "0") {
  112. color += "00";
  113. }
  114. else {
  115. color += "D0";
  116. }
  117. }
  118. return color;
  119. }
  120.  
  121. function Player() {
  122. this.id = -1;
  123. this.name = "unnamed";
  124.  
  125. this.toString = function() {
  126. return this.id+" - '"+this.name+"'";
  127. };
  128. }
  129.  
  130. function readCookieData() {
  131. var arr = new Array();
  132. for (var n=0; n<10; n++) {
  133. var data = getCookie(cookieName+n);
  134. if (data == null) continue;
  135.  
  136. var str = data.split("\f");
  137. for (var i=0; i<str.length; i+=2) {
  138. var p = new Player();
  139. p.id = parseFloat(str[i]);
  140. p.name = str[i+1];
  141. arr.push(p);
  142. }
  143. }
  144. if (arr.length == 0) return null;
  145. else return arr;
  146. }
  147.  
  148. function writeCookie(arr) {
  149. var plist = ["","","","","","","","","",""];
  150. for (var i=0; i<arr.length; i=i+2) {
  151. var id = parseInt(arr[i]);
  152. var name = arr[i+1];
  153. plist[id%10] += id+"\f"+name+"\f";
  154. }
  155. for (var i=0; i<10; i++) {
  156. setCookie(cookieName+i,plist[i]+";");
  157. }
  158. }
  159.  
  160. function parsePage(text) {
  161. //console.log(text);
  162. var searchString = "/game/player.pl?player_id=";
  163. var sslen = searchString.length;
  164. var playerArray = [];
  165.  
  166. while (text.indexOf(searchString) != -1) {
  167. var start = text.indexOf(searchString)+sslen;
  168. text = text.slice(start);
  169.  
  170. var end = text.indexOf('"');
  171. var t = text.slice(0,end);
  172. text = text.slice(end+2);
  173. end = text.indexOf("</a>");
  174.  
  175. var name = text.slice(text.indexOf(">")+1,end);
  176. if (name == "") {
  177. name = text.slice(0,text.indexOf("<"));
  178. }
  179. name = name.replace("&nbsp;"," ");
  180. name = name.replace("&amp;","&");
  181. playerArray.push(parseInt(t));
  182. playerArray.push(name);
  183.  
  184. text = text.slice(end);
  185. }
  186.  
  187. //console.log("writing cookie : "+playerArray);
  188. console.log("playerArray : "+(playerArray.length/2));
  189. writeCookie(playerArray);
  190. }