Player Progression Tracker

Stores player attributes for the Deeproute.com online football game

目前為 2018-03-02 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Player Progression Tracker
  3. // @namespace Deep Route
  4. // @author Triplex
  5. // @version 1.3.2
  6. // @description Stores player attributes for the Deeproute.com online football game
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // @include http://deeproute.com/default.asp?js=oneplayer&lookatplayer=*&leagueno=*
  10. // @include http://deeproute.com/default.asp?js=oneplayer&lookatplayer=*&myleagueno=*
  11. // @include http://deeproute.com/?js=oneplayer&lookatplayer=*&leagueno=*
  12. // @include http://deeproute.com/?js=oneplayer&lookatplayer=*&myleagueno=*
  13. // @include http://deeproute.com/default.asp?js=rosters&myleagueno=*&myteamno=*
  14. // @include http://deeproute.com/?js=rosters&myleagueno=*&myteamno=*
  15. // @include http://deeproute.com/?js=oneplayer&leagueno=*&lookatplayer=*
  16. // @include http://deeproute.com/?js=oneplayer&myleagueno=*&lookatplayer=*
  17. // @include http://deeproute.com/default.asp?js=oneplayer&leagueno=*&lookatplayer=*
  18. // ==/UserScript==
  19.  
  20. var prefix="DR_progress";
  21. var run=0, attr=[], attrstr="", lgno=0, playerid=0, curryear=-1, counter=0, pidlist=[];
  22.  
  23. function addtr(intable, incol, isBold) {
  24.  
  25. var tr1 = document.createElement("tr"), color;
  26. intable.appendChild(tr1);
  27.  
  28. if (counter++%2===0) {
  29. color='#FFFFDD';
  30. }
  31. else {
  32. color='#EEFFFF';
  33. }
  34.  
  35. for (var x=0; x<incol.length; x++) {
  36.  
  37. var td1 = document.createElement("td");
  38. td1.setAttribute('align','center');
  39. var newDiv = document.createElement('div');
  40. newDiv.innerHTML=incol[x];
  41. td1.appendChild(newDiv);
  42. if (isBold || x===0) {
  43. td1.setAttribute('style', 'font-weight: bold;');
  44. }
  45. td1.setAttribute('bgcolor', color);
  46.  
  47. tr1.appendChild(td1);
  48. }
  49.  
  50. }
  51.  
  52.  
  53. function parseData(instr) {
  54.  
  55. var ptr1=0, ptr2, ptr3, year, str1;
  56.  
  57. alldata=[];
  58.  
  59. while (1) {
  60. ptr2=instr.indexOf(":", ptr1);
  61. ptr3=instr.indexOf(".", ptr2+1);
  62. if (ptr2<0 || ptr3<0) {
  63. break;
  64. }
  65. var tmp=new Array (1);
  66. year=parseInt(instr.substring(ptr1, ptr2));
  67. str1=instr.substring(ptr2+1, ptr3);
  68. ptr1=ptr3+1;
  69. tmp[0]=year;
  70.  
  71. for (var x=0; x<str1.length; x+=2) {
  72. ptr2=str1.substring(x, x+2);
  73. if (ptr2.substring(0, 1) == '0') {
  74. ptr3=ptr2.substring(1, 2);
  75. ptr2=ptr3;
  76. }
  77. tmp[tmp.length]=parseInt(ptr2);
  78. }
  79.  
  80. alldata[alldata.length]=tmp;
  81. }
  82.  
  83.  
  84. for (var x=0; x<alldata.length; x++) {
  85. for (var y=x+1; y<alldata.length; y++) {
  86. if (alldata[x][0] > alldata[y][0]) {
  87. var tmp0=alldata[x];
  88. alldata[x]=alldata[y];
  89. alldata[y]=tmp0;
  90. }
  91. }
  92. }
  93.  
  94. }
  95.  
  96. function constructCols(inname, index1, index2) {
  97.  
  98. var cols=[];
  99. cols[0]=inname;
  100.  
  101. for (var x=0; x<alldata.length; x++) {
  102. var cell = (alldata[x][index1]).toString() + "/" + (alldata[x][index2]).toString();
  103. if (x > 0) {
  104. var curDelta;
  105. var potDelta;
  106. var currentDeltaInt = alldata[x][index1] - alldata[x-1][index1];
  107. var potentialDeltaInt = alldata[x][index2] - alldata[x-1][index2];
  108.  
  109. if (currentDeltaInt < 0) {
  110. curDelta = currentDeltaInt.toString();
  111. }
  112. else {
  113. curDelta = "+" + currentDeltaInt.toString();
  114. }
  115.  
  116. if (potentialDeltaInt < 0) {
  117. potDelta = potentialDeltaInt.toString();
  118. }
  119. else {
  120. potDelta = "+" + potentialDeltaInt.toString();
  121. }
  122.  
  123. cell = cell.concat(" (" + curDelta + "/" + potDelta + ")");
  124. }
  125. cols[x+1]=cell;
  126. }
  127.  
  128. cols[cols.length]=(attr[index1-1]).toString() + "/" + (attr[index2-1]).toString();
  129. return cols;
  130. }
  131.  
  132.  
  133. function print_progression() {
  134.  
  135. var indexstr=prefix+"_"+lgno+"_"+playerid;
  136. var storedata=GM_getValue(indexstr, null);
  137. var divptr=document.getElementById("progress_mesg"), cols;
  138.  
  139. if (storedata===null || storedata=="deleted") {
  140. divptr.innerHTML="No historical data is saved previously or data of this player is deleted";
  141. }
  142. else if (run==1) {
  143. divptr.innerHTML="Progression table is displayed already";
  144. }
  145. else {
  146.  
  147. run=1;
  148. parseData(storedata);
  149.  
  150. var outtable = document.createElement("table");
  151. outtable.setAttribute("border","1");
  152. outtable.setAttribute("cellspacing","0");
  153. outtable.setAttribute('style','width: 100%; table-layout: fixed');
  154. outtable.setAttribute('id',"combine table");
  155.  
  156. cols=[];
  157. cols[0]="Season";
  158. for (var x=0; x<alldata.length; x++) {
  159. cols[x+1]=alldata[x][0];
  160. }
  161. cols[cols.length]="Current";
  162.  
  163. addtr(outtable, cols, 1);
  164. addtr(outtable, constructCols("Overall", 187, 188) ,0);
  165. addtr(outtable, constructCols("Strength/Size", 9, 10) ,0);
  166. addtr(outtable, constructCols("Stamina", 49, 50) ,0);
  167. addtr(outtable, constructCols("Toughness", 51, 52) ,0);
  168. addtr(outtable, constructCols("Athleticism", 57, 58) ,0);
  169. addtr(outtable, constructCols("Intelligence", 11, 12) ,0);
  170. addtr(outtable, constructCols("Leadership", 13, 14) ,0);
  171. addtr(outtable, constructCols("Discipline", 27, 28) ,0);
  172. addtr(outtable, constructCols("Clutch", 23, 24) ,0);
  173. addtr(outtable, constructCols("Consistency", 53, 54) ,0);
  174. addtr(outtable, constructCols("Passing Arm", 1, 2) ,0);
  175. addtr(outtable, constructCols("Passing Accuracy", 3, 4) ,0);
  176. addtr(outtable, constructCols("Handle Snap", 63, 64) ,0);
  177. addtr(outtable, constructCols("Escapability", 5, 6) ,0);
  178. addtr(outtable, constructCols("Speed/Size", 33, 34) ,0);
  179. addtr(outtable, constructCols("Footwork", 35, 36) ,0);
  180. addtr(outtable, constructCols("Cover Skills/Size", 81, 82) ,0);
  181. addtr(outtable, constructCols("Protect ball", 37, 38) ,0);
  182. addtr(outtable, constructCols("Shed Blocker", 59, 60) ,0);
  183. addtr(outtable, constructCols("Pass Catching", 15, 16) ,0);
  184. addtr(outtable, constructCols("Route", 17, 18) ,0);
  185. addtr(outtable, constructCols("First Step", 25, 26) ,0);
  186. addtr(outtable, constructCols("Run Blocking", 19, 20) ,0);
  187. addtr(outtable, constructCols("Pass Blocking", 21, 22) ,0);
  188. addtr(outtable, constructCols("Snapping", 61, 62) ,0);
  189. addtr(outtable, constructCols("Motor", 7, 8) ,0);
  190. addtr(outtable, constructCols("Read Opposition", 55, 56) ,0);
  191. addtr(outtable, constructCols("Tackling", 29, 30) ,0);
  192. addtr(outtable, constructCols("Leaping", 31, 32) ,0);
  193. addtr(outtable, constructCols("Feel Pressure", 45, 46) ,0);
  194. addtr(outtable, constructCols("Find Opening", 47, 48) ,0);
  195. addtr(outtable, constructCols("FG Accuracy", 41, 42) ,0);
  196. addtr(outtable, constructCols("Kicking Strength", 39, 40) ,0);
  197. addtr(outtable, constructCols("Punting Accuracy", 43, 44) ,0);
  198.  
  199. divptr.innerHTML="Player Progression:";
  200.  
  201. var divptr=document.getElementById("progress_mesg");
  202. divptr.parentNode.insertBefore(outtable, divptr.nextSibling);
  203. }
  204.  
  205.  
  206. }
  207.  
  208. function save_data() {
  209.  
  210. var indexstr=prefix+"_"+lgno+"_"+playerid;
  211. var storedata=GM_getValue(indexstr, null);
  212.  
  213. if ((storedata===null || storedata=="deleted") && attr!=="" && curryear!=-1) {
  214. GM_setValue(indexstr, curryear.toString()+":"+attrstr+".");
  215. var divptr=document.getElementById("progress_mesg");
  216. divptr.innerHTML="Attributes Saved";
  217. }
  218. else if (curryear!=-1) {
  219. parseData(storedata);
  220. var found=0;
  221. for (var x=0; x<alldata.length; x++) {
  222. if (alldata[x][0] == curryear) {
  223. found=1;
  224. break;
  225. }
  226. }
  227.  
  228. var divptr=document.getElementById("progress_mesg");
  229.  
  230. if (found===0) {
  231. GM_setValue(indexstr, storedata+curryear.toString()+":"+attrstr+".");
  232. divptr.innerHTML="Attributes Saved";
  233. }
  234. else {
  235. divptr.innerHTML="This season's attributes are already saved";
  236. }
  237. }
  238. else {
  239. var divptr=document.getElementById("progress_mesg");
  240. divptr.innerHTML="Save failed: Can't find current year info in the page. Try saving whole team instead";
  241. }
  242. }
  243.  
  244. function save_all() {
  245.  
  246. for (var x=0; x<pidlist.length; x++) {
  247.  
  248. var indexstr=prefix+"_"+lgno+"_"+pidlist[x];
  249. var str1="pattnoinj"+pidlist[x];
  250. var attsptr=document.getElementsByName(str1);
  251. var atts=attsptr[0].value.toString();
  252. var storedata=GM_getValue(indexstr, null);
  253.  
  254. if (storedata===null || storedata=="deleted") {
  255. GM_setValue(indexstr, curryear.toString()+":"+atts+".");
  256. }
  257. else {
  258. parseData(storedata);
  259. var found=0;
  260. for (var y=0; y<alldata.length; y++) {
  261. if (alldata[y][0] == curryear) {
  262. found=1;
  263. break;
  264. }
  265. }
  266.  
  267. if (found===0) {
  268. GM_setValue(indexstr, storedata+curryear.toString()+":"+atts+".");
  269. }
  270. }
  271. }
  272.  
  273. var divptr=document.getElementById("progress_all_mesg");
  274. divptr.innerHTML="Attributes of all players saved";
  275.  
  276. }
  277.  
  278. function delete_all() {
  279.  
  280. var shouldDelete = confirm("are you sure you want to delete all records?");
  281.  
  282. if (shouldDelete === true) {
  283. for (var x=0; x<pidlist.length; x++) {
  284.  
  285. var indexstr=prefix+"_"+lgno+"_"+pidlist[x];
  286. var storedata=GM_getValue(indexstr, null);
  287.  
  288. if (storedata!==null) {
  289. GM_setValue(indexstr, "deleted");
  290. }
  291. }
  292.  
  293. var divptr=document.getElementById("progress_all_mesg");
  294. divptr.innerHTML="Attribuite records deleted";
  295. }
  296.  
  297. }
  298.  
  299. function delete_data() {
  300.  
  301. var shouldDelete = confirm("are you sure you want to delete this player's records?");
  302.  
  303. if (shouldDelete === true) {
  304. var indexstr=prefix+"_"+lgno+"_"+playerid;
  305. GM_setValue(indexstr, "deleted");
  306. var divptr=document.getElementById("progress_mesg");
  307. divptr.innerHTML="Old data deleted";
  308. }
  309. }
  310.  
  311. window.setTimeout( function() {
  312.  
  313. var url=window.location.toString();
  314.  
  315. if (url.indexOf("oneplayer",0) >= 0) {
  316.  
  317.  
  318. var buttontable = document.createElement('table');
  319. buttontable.setAttribute('cellspacing', '0');
  320. buttontable.setAttribute('cellpadding', '0');
  321. buttontable.setAttribute('id', 'track_table');
  322.  
  323. var newtr=document.createElement('tr');
  324. buttontable.appendChild(newtr);
  325. var newtd1 = document.createElement('td');
  326. newtd1.setAttribute('colspan', '10');
  327. var newDiv2 = document.createElement('div');
  328. newDiv2.align = 'center';
  329. newDiv2.innerHTML = '<input type="button" style="font-size: 10pt; font-weight: bold; width: 100%; height: 30px" value="Show Progression">';
  330. newDiv2.addEventListener('click', function() { print_progression(); }, true);
  331. newtd1.appendChild(newDiv2);
  332. newtr.appendChild(newtd1);
  333.  
  334. newtd1 = document.createElement('td');
  335. newtd1.setAttribute('colspan', '10');
  336. newDiv2 = document.createElement('div');
  337. newDiv2.align = 'center';
  338. newDiv2.innerHTML = '<input type="button" style="font-size: 10pt; font-weight: bold; width: 100%; height: 30px" value="Save current season\'s Attributes">';
  339. newDiv2.addEventListener('click', function() { save_data(); }, true);
  340. newtd1.appendChild(newDiv2);
  341. newtr.appendChild(newtd1);
  342.  
  343. newtd1 = document.createElement('td');
  344. newtd1.setAttribute('colspan', '10');
  345. newDiv2 = document.createElement('div');
  346. newDiv2.align = 'center';
  347. newDiv2.innerHTML = '<input type="button" style="font-size: 10pt; font-weight: bold; width: 100%; height: 30px" value="Delete saved data">';
  348. newDiv2.addEventListener('click', function() { delete_data(); }, true);
  349. newtd1.appendChild(newDiv2);
  350. newtr.appendChild(newtd1);
  351.  
  352. var newDiv = document.createElement('div');
  353. newDiv.setAttribute("id", "progress_mesg");
  354. newDiv.innerHTML='&nbsp;';
  355.  
  356.  
  357. var target = document.getElementById('hili1');
  358. if (target) {
  359.  
  360. target.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.insertBefore(
  361. newDiv, target.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.nextSibling);
  362.  
  363.  
  364. target.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.insertBefore(
  365. buttontable, target.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.nextSibling);
  366. }
  367.  
  368. var ptr1, ptr2, ptr3, input=document.body.innerHTML, lgptr=document.getElementById("mylgno"), yearptr=document.getElementById("hiyear");
  369.  
  370. if (lgptr!==null) lgno=lgptr.value;
  371. var yearptr1=document.getElementById("thisyear");
  372. if (yearptr1!==null) curryear=parseInt(yearptr1.value);
  373. else {
  374. if (yearptr!==null) {
  375. curryear=parseInt(yearptr.value);
  376. if (curryear<10) {
  377. curryear=-1;
  378. }
  379. }
  380. }
  381.  
  382. ptr1=input.indexOf("by Game Stats");
  383. if (ptr1>=0) {
  384. ptr2=input.lastIndexOf("\">", ptr1);
  385. ptr3=input.lastIndexOf("lookatplayer=", ptr1);
  386. if (ptr3>=0 && ptr2>ptr3) {
  387. playerid=parseInt(input.substring(ptr3+13, ptr2));
  388. }
  389. }
  390.  
  391. ptr1=input.indexOf("attsnoinj", 0);
  392. attrstr="";
  393.  
  394. if (ptr1>=0) {
  395. ptr2=input.indexOf("value=\"", ptr1);
  396. ptr3=input.indexOf("\"", ptr2+7);
  397. if (ptr2>=0 && ptr3>ptr2) {
  398.  
  399. attrstr=input.substring(ptr2+7, ptr3);
  400.  
  401. for (var x=0; x<attrstr.length; x+=2) {
  402. ptr1=attrstr.substring(x, x+2);
  403. if (ptr1.substring(0, 1) == '0') {
  404. ptr2=ptr1.substring(1, 2);
  405. ptr1=ptr2;
  406. }
  407. attr[attr.length]=parseInt(ptr1);
  408. }
  409. }
  410. }
  411. }
  412. else if (url.indexOf("rosters",0) >= 0) {
  413.  
  414. var lgptr=document.getElementById("mylgno"), pids=document.getElementsByName("pid"), yearptr=document.getElementById("myseason");
  415. var currptr=0, ptr1, ptr2, str1;
  416.  
  417. if (lgptr!==null) lgno=lgptr.value;
  418. if (yearptr!==null) curryear=parseInt(yearptr.value);
  419.  
  420. str1=(pids[0].value).toString();
  421.  
  422. while (1) {
  423. ptr1=str1.indexOf("!", currptr);
  424. ptr2=str1.indexOf(" ", ptr1+1);
  425. if (ptr1<0 || ptr2<0) {
  426. break;
  427. }
  428. pidlist[pidlist.length]=parseInt(str1.substring(ptr1+1, ptr2));
  429. currptr=ptr2;
  430. }
  431.  
  432. var buttontable = document.createElement('table');
  433. buttontable.setAttribute('cellspacing', '0');
  434. buttontable.setAttribute('cellpadding', '0');
  435. buttontable.setAttribute('id', 'track_table');
  436.  
  437. var newtr=document.createElement('tr');
  438. buttontable.appendChild(newtr);
  439. var newtd1 = document.createElement('td');
  440. newtd1.setAttribute('colspan', '10');
  441. var newDiv2 = document.createElement('div');
  442. newDiv2.align = 'center';
  443. newDiv2.innerHTML = '<input type="button" style="font-size: 10pt; font-weight: bold; width: 100%; height: 30px" value="Record all players\' attributes">';
  444. newDiv2.addEventListener('click', function() { save_all(); }, true);
  445. newtd1.appendChild(newDiv2);
  446. newtr.appendChild(newtd1);
  447.  
  448. newtr=document.createElement('tr');
  449. buttontable.appendChild(newtr);
  450. newtd1 = document.createElement('td');
  451. newtd1.setAttribute('colspan', '10');
  452. newDiv2 = document.createElement('div');
  453. newDiv2.align = 'center';
  454. newDiv2.innerHTML = '<input type="button" style="font-size: 10pt; font-weight: bold; width: 100%; height: 30px" value="Delete all players\' records">';
  455. newDiv2.addEventListener('click', function() { delete_all(); }, true);
  456. newtd1.appendChild(newDiv2);
  457. newtr.appendChild(newtd1);
  458.  
  459. var newDiv = document.createElement('div');
  460. newDiv.setAttribute("id", "progress_all_mesg");
  461. newDiv.innerHTML='&nbsp;';
  462.  
  463. var target = document.getElementById('storeme');
  464.  
  465. if (target) {
  466.  
  467. target.parentNode.parentNode.parentNode.parentNode.parentNode.insertBefore(newDiv,
  468. target.parentNode.parentNode.parentNode.parentNode.nextSibling);
  469.  
  470. target.parentNode.parentNode.parentNode.parentNode.parentNode.insertBefore(buttontable,
  471. target.parentNode.parentNode.parentNode.parentNode.nextSibling);
  472. }
  473. }
  474.  
  475.  
  476.  
  477. }, 200);