Advertisement
Guest User

Untitled

a guest
Mar 1st, 2021
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.51 KB | None | 0 0
  1. // ==UserScript==
  2. // @name MMA Tycoon Skill Snapshot Stat Extractor
  3. // @namespace http://www.tycoontools.com/greasemonkey-scripts
  4. // @description This script shows the exact skill values of your fighters on the Skill Snapshot page. In addition, it adds an Extract All button, which extracts all skill values of all of your fighters, which makes it much easier to track skill progression.
  5. // @include http://www.mmatycoon.com/mystatssnapshot.php
  6. // @include http://mmatycoon.com/mystatssnapshot.php
  7. // @include https://www.mmatycoon.com/mystatssnapshot.php
  8. // @include https://mmatycoon.com/mystatssnapshot.php
  9. // @version 1.0
  10. // @copyright 2010
  11. // @require http://code.jquery.com/jquery-3.5.1.min.js
  12. // @require https://code.jquery.com/ui/1.12.1/jquery-ui.js
  13. // @grant GM_getValue
  14. // @grant GM_setValue
  15. // @grant GM_log
  16. // ==/UserScript==
  17.  
  18. /* globals jQuery, $, waitForKeyElements */
  19.  
  20. var AUTOMATION_IN_PROGRESS = "Automation In Progress";
  21. var FIGHTER_IDS = "Fighter Ids";
  22. var SKILLS_PENDING_EXTRACTION = "Skills Pending Extraction";
  23. var FIGHTER_DATA = "Fighter Data";
  24. var RESULTS_AVAILABLE = "Show Results";
  25. var LAST_EXTRACT = "Last Extracted";
  26.  
  27. function traceEnabled()
  28. {
  29. if (GM_getValue("TRACE", 1) == 1) {
  30. return true;
  31. }
  32. else{
  33. return false;
  34. }
  35. }
  36.  
  37. function enableTrace()
  38. {
  39. GM_setValue("TRACE", 1);
  40. }
  41.  
  42. function trace(message)
  43. {
  44. if (traceEnabled() == true)
  45. {
  46. var now = new Date().toLocaleString();
  47. var fullMessage = now + " : " + message;
  48. jQuery("body").append("<div style='background: white; width: 100%'>" + fullMessage + "<br/></span>");
  49. GM_log(fullMessage);
  50. }
  51. }
  52.  
  53. function setValueJSON(key, value)
  54. {
  55. trace("setValueJSON, key = " + key);
  56. var jsonString = JSON.stringify(value);
  57.  
  58. GM_setValue(key, jsonString);
  59. }
  60.  
  61. function getValueJSON(key)
  62. {
  63. trace("getValueJSON, key = " + key);
  64.  
  65. var value = GM_getValue(key);
  66. console.log(value)
  67. var parsedObject = JSON.parse(value);
  68.  
  69. trace("getValueJSON, returning");
  70.  
  71. return parsedObject;
  72. }
  73.  
  74. function startAutomation()
  75. {
  76. trace("startAutomation");
  77.  
  78. trace("getting fighter ids");
  79. var fighterIds = getFighterIds();
  80. setValueJSON(FIGHTER_IDS, fighterIds);
  81.  
  82. trace("getting skill names");
  83. var skillNames = getSkillNames();
  84. setValueJSON(SKILLS_PENDING_EXTRACTION, skillNames);
  85.  
  86. trace("setting AUTOMATION_IN_PROGRESS = true");
  87. GM_setValue(AUTOMATION_IN_PROGRESS, 1);
  88.  
  89. trace("starting automation");
  90. selectSkillsAndRefresh();
  91.  
  92. var fighterSkillObject = new Object();
  93. setValueJSON(FIGHTER_DATA, fighterSkillObject);
  94.  
  95. GM_setValue(LAST_EXTRACT, Date().toLocaleString());
  96. }
  97.  
  98. function injectJQueryIntoPage()
  99. {
  100. var script = document.createElement('script');
  101.  
  102. script.setAttribute("type", "application/javascript");
  103. script.setAttribute("src", "https://userscripts.org/scripts/source/74204.user.js");
  104.  
  105. document.body.appendChild(script);
  106. document.body.removeChild(script);
  107. }
  108.  
  109. function selectSkillsAndRefresh()
  110. {
  111. trace("selectSkillsAndRefresh");
  112. var pendingSkills = getPendingSkillBlock();
  113. var toRemove = 0;
  114.  
  115. if (pendingSkills.length <= 0)
  116. {
  117. stopAutomation();
  118.  
  119. GM_setValue(RESULTS_AVAILABLE, 1);
  120.  
  121. window.$("select[name='selSkill_1']").val("");
  122. window.$("select[name='selSkill_2']").val("");
  123. window.$("select[name='selSkill_3']").val("");
  124. unsafeWindow.showMyFighterSkill();
  125. }
  126.  
  127. var skill = pendingSkills[0].toString();
  128.  
  129. if (pendingSkills.length >= 1)
  130. {
  131. trace("selectSkillsAndRefresh, selecting [" + skill + "] in selSkill_1");
  132. window.$("select[name='selSkill_1']").val(skill);
  133. toRemove++;
  134. }
  135. if (pendingSkills.length >= 2)
  136. {
  137. skill = pendingSkills[1].toString();
  138. trace("selectSkillsAndRefresh, selecting [" + skill + "] in selSkill_2");
  139. window.$("select[name='selSkill_2']").val(skill);
  140. toRemove++;
  141. }
  142. if (pendingSkills.length >= 3)
  143. {
  144. skill = pendingSkills[2].toString();
  145. jQuery("select[name='selSkill_3']").val(skill);
  146. trace("selectSkillsAndRefresh, selecting [" + skill + "] in selSkill_3");
  147. window.$("select[name='selSkill_3']").val(skill);
  148. toRemove++;
  149. }
  150.  
  151. var allSkills = getValueJSON(SKILLS_PENDING_EXTRACTION);
  152. allSkills.splice(0, toRemove);
  153. setValueJSON(SKILLS_PENDING_EXTRACTION, allSkills);
  154.  
  155. trace("window.showMyFighterSkill()");
  156. unsafeWindow.showMyFighterSkill();
  157. }
  158.  
  159. function getPendingSkillBlock()
  160. {
  161. trace("getPendingSkillBlock");
  162. var allSkills = getValueJSON(SKILLS_PENDING_EXTRACTION);
  163. if (allSkills.length <= 0)
  164. {
  165. trace("getPendingSkillBlock, returning empty array because there was nothing in SKILLS_PENDING_EXTRACTION");
  166. return new Array();
  167. }
  168.  
  169. var result = new Array();
  170. if (allSkills.length >= 1)
  171. {
  172. trace("getPendingSkillBlock, found " + allSkills[0] + " as pending extraction");
  173. result[0] = allSkills[0];
  174. }
  175. if (allSkills.length >= 2)
  176. {
  177. trace("getPendingSkillBlock, found " + allSkills[1] + " as pending extraction");
  178. result[1] = allSkills[1];
  179. }
  180. if (allSkills.length >= 3)
  181. {
  182. trace("getPendingSkillBlock, found " + allSkills[2] + " as pending extraction");
  183. result[2] = allSkills[2];
  184. }
  185.  
  186. trace("getPendingSkillBlock returning");
  187. return result;
  188. }
  189.  
  190. function getSkillNames()
  191. {
  192. trace("getSkillNames");
  193. var result = new Array();
  194. var validItems = jQuery("select[id='selSkill_1']").find("option[value!='-'][value!='']");
  195. validItems.each(
  196. function()
  197. {
  198. result[result.length] = jQuery(this).attr("value");
  199. }
  200. );
  201. trace("getSkillNames returning");
  202. return result;
  203. }
  204.  
  205. function getSkillTable()
  206. {
  207. return jQuery("strong:contains('Name')").first().parent("td").parent("tr").parent("tbody").parent("table");
  208. }
  209.  
  210. function getFighterIds()
  211. {
  212. var fighterNames = new Array();
  213. var skillTable = getSkillTable();
  214.  
  215. skillTable.find("a[href*='fighterprofilemanager.php']").each(
  216. function()
  217. {
  218. var name = jQuery(this).text();
  219. fighterNames[fighterNames.length] = name;
  220. }
  221. );
  222. return fighterNames;
  223. }
  224.  
  225. function stopAutomation()
  226. {
  227. GM_setValue(AUTOMATION_IN_PROGRESS, 0);
  228. }
  229.  
  230.  
  231. function getSkillLevelMarkup(modifier)
  232. {
  233. var result = "";
  234. if (modifier == "+" || modifier == "++") {
  235. result = "<font color='#006600' style='font-weight: bold;'>" + modifier + "</font>";
  236. }
  237. if (modifier == "-" || modifier == "--") {
  238. result = "<font color='#ff0000' style='font-weight: bold;'>" + modifier + "</font>";
  239. }
  240.  
  241. return result;
  242. }
  243.  
  244. function getSkillLevelModifier(points)
  245. {
  246. var currentLevelPoints = -1;
  247. var result = "";
  248.  
  249. if (points >= 10){
  250. currentLevelPoints = points % 10;
  251. }
  252. else {
  253. currentLevelPoints = points;
  254. }
  255.  
  256. if (currentLevelPoints >= 0.00 && currentLevelPoints < 2.5) {
  257. result = "--";
  258. }
  259. if (currentLevelPoints >= 2.5 && currentLevelPoints < 5) {
  260. result = "-";
  261. }
  262. if (currentLevelPoints >= 5 && currentLevelPoints < 7.5) {
  263. result = "+";
  264. }
  265. if (currentLevelPoints >= 7.5 && currentLevelPoints < 10) {
  266. result = "++";
  267. }
  268.  
  269. return result;
  270. }
  271.  
  272. function getSkillLevel(points)
  273. {
  274. if (points >= 0 && points < 10){
  275. return "Useless";
  276. }
  277. if (points >= 10 && points < 20){
  278. return "Abysmal";
  279. }
  280. if (points >= 20 && points < 30){
  281. return "Woeful";
  282. }
  283. if (points >= 30 && points < 40){
  284. return "Feeble";
  285. }
  286. if (points >= 40 && points < 50){
  287. return "Mediocre";
  288. }
  289. if (points >= 50 && points < 60){
  290. return "Competant";
  291. }
  292. if (points >= 60 && points < 70){
  293. return "Respectable";
  294. }
  295. if (points >= 70 && points < 80){
  296. return "Proficient";
  297. }
  298. if (points >= 80 && points < 90){
  299. return "Strong";
  300. }
  301. if (points >= 90 && points < 100){
  302. return "Superb";
  303. }
  304. if (points >= 100 && points < 110){
  305. return "Remarkable";
  306. }
  307. if (points >= 110 && points < 120){
  308. return "Wonderful";
  309. }
  310. if (points >= 120 && points < 130){
  311. return "Exceptional";
  312. }
  313. if (points >= 130 && points < 140){
  314. return "Sensational";
  315. }
  316. if (points >= 140 && points < 150){
  317. return "Elite";
  318. }
  319.  
  320. return null;
  321. }
  322.  
  323. function getPointsFromWidth(width)
  324. {
  325. return (width / 100) * 150;
  326. }
  327.  
  328.  
  329. function getFirstDropDownSkill()
  330. {
  331. return jQuery("select[id='selSkill_1'] option:selected").text();
  332. }
  333.  
  334. function getSecondDropDownSkill()
  335. {
  336. return jQuery("select[id='selSkill_2'] option:selected").text();
  337. }
  338.  
  339. function getThirdDropDownSkill()
  340. {
  341. return jQuery("select[id='selSkill_3'] option:selected").text();
  342. }
  343.  
  344. function updateFighterSkill(fighterId, pointsValue, skillName)
  345. {
  346. var skill = unescape(skillName).replace("\r", "").replace("\n", "");
  347.  
  348. while (true)
  349. {
  350. if (skill.indexOf(" ") == -1) {
  351. break;
  352. }
  353. else {
  354. skill = skill.replace(" ", " ");
  355. }
  356. }
  357.  
  358. var fighterSkillObject = getValueJSON(FIGHTER_DATA);
  359.  
  360. if (typeof fighterSkillObject[fighterId] == "undefined") {
  361. fighterSkillObject[fighterId] = new Object();
  362. }
  363.  
  364. fighterSkillObject[fighterId][skill] = pointsValue;
  365.  
  366. setValueJSON(FIGHTER_DATA, fighterSkillObject);
  367. }
  368.  
  369. function showSkillValues(skillAction)
  370. {
  371. jQuery("tr[bgcolor='#efefef'],tr[bgcolor='#ffffff']")
  372. .each(
  373. function ()
  374. {
  375. var fighterLink = jQuery(this).find("a[href*='FID=']");
  376. var fighterLinkText = fighterLink.text();
  377. var skillBars = jQuery(this).find("td[background*='images/bar']").each(
  378. function ()
  379. {
  380. var currentBackground = jQuery(this).attr("background").toString();
  381. var currentSkill = null;
  382. if (currentBackground.indexOf("barred") != -1) {
  383. currentSkill = getFirstDropDownSkill();
  384. }
  385. if (currentBackground.indexOf("bargreen") != -1) {
  386. currentSkill = getSecondDropDownSkill();
  387. }
  388. if (currentBackground.indexOf("barblue") != -1) {
  389. currentSkill = getThirdDropDownSkill();
  390. }
  391.  
  392. var barWidth = parseFloat(jQuery(this).attr("width").toString().replace("%", ""));
  393. var skillPoints = getPointsFromWidth(barWidth);
  394. var modifier = getSkillLevelModifier(skillPoints);
  395. var skillLevel = getSkillLevel(skillPoints);
  396. var roundedPoints = skillPoints.toFixed(2);
  397.  
  398. var pointString = "(" + roundedPoints + ")";
  399. jQuery(this)
  400. .parent("tr")
  401. .parent("tbody")
  402. .parent("table")
  403. .parent("td")
  404. .append("<span style='font-size: 8pt'>" + skillLevel + getSkillLevelMarkup(modifier) + " (" + roundedPoints + ")</span>");
  405.  
  406. if (currentSkill.indexOf("-") == -1)
  407. {
  408. trace(fighterLinkText + " has " + skillPoints + " in " + currentSkill);
  409.  
  410. if (skillAction != null){
  411. skillAction(fighterLinkText, skillPoints, currentSkill);
  412. }
  413. }
  414. }
  415. );
  416. }
  417. );
  418. }
  419.  
  420. function showResults(dataObject)
  421. {
  422. var stringOutput = "";
  423. var fighterIds = new Array();
  424. var skills = new Array();
  425. var lines = new Array();
  426. var currentSkill = "";
  427.  
  428. for (var propertyName in dataObject)
  429. {
  430. if (!dataObj.hasOwnProperty(propertyName)) {
  431. continue;
  432. }
  433. fighterIds.push(propertyName);
  434. }
  435.  
  436. var firstFighter = dataObj[fighterIds[0]];
  437. for (propertyName in firstFighter)
  438. {
  439. if (!firstFighter.hasOwnProperty(propertyName)) {
  440. continue;
  441. }
  442. skills.push(propertyName);
  443. }
  444.  
  445. var header = "Fighter\t";
  446. for (var i = 0; i < skills.length; i++)
  447. {
  448. currentSkill = skills[i];
  449. header = header + currentSkill;
  450. if (i != (skills.length - 1)) {
  451. header = header + "\t";
  452. }
  453. }
  454.  
  455. lines.push(header);
  456.  
  457. for (i = 0; i < fighterIds.length; i++)
  458. {
  459. var line = "";
  460. var currentFighter = fighterIds[i];
  461. line = line + currentFighter + "\t";
  462.  
  463. for (var x = 0; x < skills.length; x++)
  464. {
  465. currentSkill = skills[x];
  466.  
  467. var currentSkillvalue = dataObj[currentFighter][currentSkill];
  468. line = line + currentSkillvalue.toString();
  469. if (x != (skills.length - 1)) {
  470. line = line + "\t";
  471. }
  472. }
  473.  
  474. lines.push(line);
  475. }
  476.  
  477. stringOutput = lines.join("\r\n");
  478.  
  479. var numRows = (fighterIds.length + 1).toString();
  480.  
  481. var boxMarkup = "<textarea id='txtResults' cols='999' rows='" + numRows + "' wrap='off' readonly='readonly' style='width: 100%; white-space: pre-wrap; overflow: scroll'>" + stringOutput + "</textarea>";
  482. var headerMarkup = "Fighter skill data as of " + GM_getValue(LAST_EXTRACT) + "<br/>";
  483. getSkillTable().after(headerMarkup + boxMarkup);
  484. }
  485.  
  486. enableTrace();
  487. injectJQueryIntoPage();
  488.  
  489. if (GM_getValue(AUTOMATION_IN_PROGRESS, 0) == 1)
  490. {
  491. jQuery("h1:contains('Fighter Skills - Snapshot')").append(" <input type='submit' id='stopAutomation' value='Stop Automation'/>");
  492. jQuery("input[id='stopAutomation']").click(stopAutomation);
  493.  
  494. showSkillValues(updateFighterSkill);
  495.  
  496. setTimeout(selectSkillsAndRefresh, 1500);
  497. }
  498. else
  499. {
  500. showSkillValues(null);
  501. jQuery("h1:contains('Fighter Skills - Snapshot')").append(" <input type='submit' id='extractSkills' value='Extract All Skill Data'/>");
  502. jQuery("input[id='extractSkills']").click(startAutomation);
  503.  
  504. if (GM_getValue(RESULTS_AVAILABLE, 0) == 1)
  505. {
  506. var dataObj = getValueJSON(FIGHTER_DATA);
  507. showResults(dataObj);
  508. }
  509. }
  510.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement