Player Progression Tracker

Stores player attributes for the Deeproute.com online football game

目前为 2016-04-15 提交的版本,查看 最新版本

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