Advertisement
TiagoSamuel

Untitled

Oct 2nd, 2020
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.19 KB | None | 0 0
  1. javascript:
  2.  
  3.  
  4. /*if (window.location.href.indexOf('screen=ally&mode=members') < 0) {
  5. //relocate
  6. window.location.assign(game_data.link_base_pure + "ally&mode=members");
  7. }*/
  8. // Sophie "Shinko to Kuma"
  9. var tribeTable = '';
  10. var rowStart = 1;
  11. var columnStart = 6;
  12. var columnName = 0;
  13. var rows;
  14. var BBTable = "";
  15. var csvTable = "";
  16. var statsEnabled = {};
  17.  
  18.  
  19. if (localStorage.getItem("tribeStatsEnabled") == null) {
  20. console.log("No settings stored, creating")
  21. statsEnabled = {
  22. "ODA": true,
  23. "ODD": true,
  24. "ODS": true,
  25. "Loot": true,
  26. "Gathering": true,
  27. "Combined": true,
  28. "ODATotal": true,
  29. "ODDTotal": true,
  30. "ODSTotal": true
  31. };
  32. localStorage.setItem("tribeStatsEnabled", JSON.stringify(statsEnabled));
  33. }
  34. else {
  35. console.log("Getting settings");
  36. statsEnabled = JSON.parse(localStorage.getItem("tribeStatsEnabled"));
  37. }
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. var langShinko;
  45. switch (game_data.locale) {
  46. case "pt_PT":
  47. langShinko = {
  48. "ODA": "ODA",
  49. "ODD": "ODD",
  50. "ODS": "ODS",
  51. "Loot": "Farm",
  52. "Gathered": "Buscas",
  53. "Combined": "Farm+Buscas",
  54. "ODATotal": "ODA TOTAL",
  55. "ODDTotal": "ODD TOTAL",
  56. "ODSTotal": "ODS TOTAL"
  57. }
  58. break;
  59. case "es_ES":
  60. langShinko = {
  61. "ODA": "ODA",
  62. "ODD": "ODD",
  63. "ODS": "ODS",
  64. "Loot": "Saqueado",
  65. "Gathered": "Recolectado",
  66. "Combined": "Combinado",
  67. "ODATotal": "ODA TOTAL",
  68. "ODDTotal": "ODD TOTAL",
  69. "ODSTotal": "ODS TOTAL"
  70. }
  71. break;
  72. case "de_DE":
  73. langShinko = {
  74. "ODA": "BGA",
  75. "ODD": "BGV",
  76. "ODS": "BGU",
  77. "Loot": "Geplündert",
  78. "Gathered": "Gesammelt",
  79. "Combined": "Insgesamt ",
  80. "ODATotal": "ODA TOTAL",
  81. "ODDTotal": "ODD TOTAL",
  82. "ODSTotal": "ODS TOTAL"
  83. }
  84. break;
  85. default:
  86. langShinko = {
  87. "ODA": "ODA",
  88. "ODD": "ODD",
  89. "ODS": "ODS",
  90. "Loot": "Loot",
  91. "Gathered": "Gathered",
  92. "Combined": "Combined",
  93. "ODATotal": "ODA TOTAL",
  94. "ODDTotal": "ODD TOTAL",
  95. "ODSTotal": "ODS TOTAL"
  96. }
  97. }
  98.  
  99. if (window.location.href.indexOf('screen=ally&mode=members') > -1) {
  100. //members own tribe
  101. tribeTable = "#content_value table.vis";
  102. rowStart = 3;
  103. columnStart = 6;
  104. columnName = 0;
  105. rows = $($("table .vis")[2]).find('tr');
  106. }
  107. if (window.location.href.indexOf('&screen=info_ally') > -1) {
  108. //any tribe
  109. tribeTable = ".vis:eq(" + (3 + $(".bbcodetable").length) + ")";
  110. rowStart = 1;
  111. columnStart = 5;
  112. columnName = 0;
  113. rows = $($("table .vis").not(".bbcodetable")[2]).find('tr');
  114. }
  115. if ((window.location.href.indexOf('screen=ranking&mode=player') > -1 || window.location.href.indexOf('screen=ranking&mode=con_player') > -1) || (window.location.href.indexOf('screen=ranking') > -1 && window.location.href.indexOf('&mode') == -1)) {
  116. //any player
  117. tribeTable = ".vis:eq(2)";
  118. rowStart = 1;
  119. columnStart = 6;
  120. columnName = 1;
  121. rows = $($("table .vis")[1]).find('tr');
  122. }
  123.  
  124.  
  125. $.getAll = function (
  126. urls, // array of URLs
  127. onLoad, // called when any URL is loaded, params (index, data)
  128. onDone, // called when all URLs successfully loaded, no params
  129. onError // called when a URL load fails or if onLoad throws an exception, params (error)
  130. ) {
  131. var numDone = 0;
  132. var lastRequestTime = 0;
  133. var minWaitTime = 200; // ms between requests
  134. loadNext();
  135. function loadNext() {
  136. if (numDone == urls.length) {
  137. onDone();
  138. return;
  139. }
  140.  
  141. let now = Date.now();
  142. let timeElapsed = now - lastRequestTime;
  143. if (timeElapsed < minWaitTime) {
  144. let timeRemaining = minWaitTime - timeElapsed;
  145. setTimeout(loadNext, timeRemaining);
  146. return;
  147. }
  148. console.log('Getting ', urls[numDone]);
  149. $("#progress").css("width", `${(numDone + 1) / urls.length * 100}%`);
  150. lastRequestTime = now;
  151. $.get(urls[numDone])
  152. .done((data) => {
  153. try {
  154. onLoad(numDone, data);
  155. ++numDone;
  156. loadNext();
  157. } catch (e) {
  158. onError(e);
  159. }
  160. })
  161. .fail((xhr) => {
  162. onError(xhr);
  163. })
  164. }
  165. };
  166. var names = [];
  167. var html = "<div style='width:500px'>";
  168. if (typeof customNames == 'undefined') {
  169. for (var i = 1; i < rows.length; i++) {
  170. names.push($(rows[i]).find('a')[0].innerText.trim().split(' ').join('+'));
  171. }
  172. }
  173. else {
  174. html += `<table class="vis" id="tableMembers" border="1" style="width: 100%"><tr><th>Player Name</th></tr>`;
  175. tribeTable = "#tableMembers";
  176. rowStart = 1;
  177. columnStart = 1;
  178. columnName = 0;
  179. rows = 4;
  180. for (var i = 0; i < customNames.length; i++) {
  181. html += `<tr><td id="${customNames[i]}" style="width:50px;padding: 5px;">${customNames[i]}</td></tr>`
  182. customNames[i] = customNames[i].trim().split(' ').join('+');
  183. }
  184. html += `</table></div>`
  185. names = customNames;
  186. $("#contentContainer").eq(0).prepend(html);
  187. }
  188.  
  189. $("#contentContainer").eq(0).prepend("<span>BB</span><br><textarea id='BBCODE' rows='" + (rows + 4) + "' cols='100'></textarea><br>");
  190. $("#contentContainer").eq(0).prepend("<span>CSV</span><br><textarea id='CSVCODE' rows='" + (rows + 4) + "' cols='100'></textarea><br>");
  191. function getData() {
  192. $("#getData").prop('disabled', true);
  193. //save checkboxes to localstorage
  194. for (var i = 0; i < Object.keys(statsEnabled).length; i++) {
  195. console.log("Current stat:" + Object.keys(statsEnabled)[i]);
  196. console.log("Set to: " + $(`:checkbox#${Object.keys(statsEnabled)[i]}`).is(":checked"))
  197. statsEnabled[Object.keys(statsEnabled)[i]] = $(`:checkbox#${Object.keys(statsEnabled)[i]}`).is(":checked");
  198. }
  199. localStorage.setItem("tribeStatsEnabled", JSON.stringify(statsEnabled));
  200.  
  201. linksODS = [];
  202. linksODD = [];
  203. linksODA = [];
  204. linksODSTotal = [];
  205. linksODDTotal = [];
  206. linksODATotal = [];
  207. linksLoot = [];
  208. linksGathering = [];
  209. ODSperPlayer = [];
  210. ODDperPlayer = [];
  211. ODAperPlayer = [];
  212. ODSTotalperPlayer = [];
  213. ODDTotalperPlayer = [];
  214. ODATotalperPlayer = [];
  215. lootperPlayer = [];
  216. gatheredperPlayer = [];
  217. for (var i = 0; i < names.length; i++) {
  218. if (statsEnabled.ODA) linksODA.push("/game.php?screen=ranking&mode=in_a_day&type=kill_att&name=" + names[i]);
  219. if (statsEnabled.ODD) linksODS.push("/game.php?screen=ranking&mode=in_a_day&type=kill_sup&name=" + names[i]);
  220. if (statsEnabled.ODS) linksODD.push("/game.php?screen=ranking&mode=in_a_day&type=kill_def&name=" + names[i]);
  221. if (statsEnabled.Loot) linksLoot.push("/game.php?screen=ranking&mode=in_a_day&type=loot_res&name=" + names[i]);
  222. if (statsEnabled.Gathering) linksGathering.push("/game.php?screen=ranking&mode=in_a_day&type=scavenge&name=" + names[i]);
  223. if (statsEnabled.ODATotal) linksODATotal.push("/game.php?screen=ranking&mode=kill_player&type=att&name=" + names[i]);
  224. if (statsEnabled.ODDTotal) linksODDTotal.push("/game.php?screen=ranking&mode=kill_player&type=def&name=" + names[i]);
  225. if (statsEnabled.ODSTotal) linksODSTotal.push("/game.php?screen=ranking&mode=kill_player&type=support&name=" + names[i]);
  226. }
  227. titleCount = 0;
  228. for (var i = 0; i < Object.keys(statsEnabled).length; i++) {
  229. if (statsEnabled[Object.keys(statsEnabled)[i]]) {
  230. $(tribeTable + " tr").eq(rowStart - 1).append("<th onclick='sortTableTest(" + (columnStart + titleCount) + ")'>" + langShinko[Object.keys(langShinko)[i]] + "</th>");
  231. titleCount++;
  232. }
  233. }
  234. $(tribeTable).eq(rowStart - 1).attr('id', 'tableMembers');
  235. $("#contentContainer").eq(0).prepend(`
  236. <div id="progressbar" style="width: 100%;
  237. background-color: #36393f;"><div id="progress" style="width: 0%;
  238. height: 35px;
  239. background-color: #4CAF50;
  240. text-align: center;
  241. line-height: 32px;
  242. color: black;"></div>
  243. </div>`);
  244. $("#mobileHeader").eq(0).prepend(`
  245. <div id="progressbar" style="width: 100%;
  246. background-color: #36393f;"><div id="progress" style="width: 0%;
  247. height: 35px;
  248. background-color: #4CAF50;
  249. text-align: center;
  250. line-height: 32px;
  251. color: black;"></div>
  252. </div>`);
  253. //ODA
  254. $.getAll(linksODA, (i, data) => {
  255. if ($(data).find(".lit-item")[3] != undefined) {
  256. temp = $(data).find(".lit-item")
  257. ODAperPlayer.push([temp[3].innerText.replace(/\./g, ','), temp[4].innerText]);
  258. }
  259. else {
  260. ODAperPlayer.push(["0", "Never"]);
  261. }
  262.  
  263. },
  264. () => {
  265. $("#progress").css("width", `${(linksODA.length) / linksODA.length * 100}%`);
  266. for (var o = rowStart; o < ODAperPlayer.length + rowStart; o++) {
  267. $(tribeTable + " tr").eq(o).append("<td title=" + ODAperPlayer[o - rowStart][1] + ">" + ODAperPlayer[o - rowStart][0] + "</td>")
  268. }
  269. //ODD
  270. $.getAll(linksODD, (i, data) => {
  271. if ($(data).find(".lit-item")[3] != undefined) {
  272. temp = $(data).find(".lit-item")
  273. ODDperPlayer.push([temp[3].innerText.replace(/\./g, ','), temp[4].innerText]);
  274. }
  275. else {
  276. ODDperPlayer.push(["0", "Never"]);
  277. }
  278.  
  279. },
  280. () => {
  281. for (var o = rowStart; o < ODDperPlayer.length + rowStart; o++) {
  282. $(tribeTable + " tr").eq(o).append("<td title=" + ODDperPlayer[o - rowStart][1] + ">" + ODDperPlayer[o - rowStart][0] + "</td>")
  283. }
  284. //ODS
  285. $.getAll(linksODS, (i, data) => {
  286. if ($(data).find(".lit-item")[3] != undefined) {
  287. temp = $(data).find(".lit-item")
  288. ODSperPlayer.push([temp[3].innerText.replace(/\./g, ','), temp[4].innerText]);
  289. }
  290. else {
  291. ODSperPlayer.push(["0", "Never"]);
  292. }
  293.  
  294. },
  295. () => {
  296. for (var o = rowStart; o < ODSperPlayer.length + rowStart; o++) {
  297. $(tribeTable + " tr").eq(o).append("<td title=" + ODSperPlayer[o - rowStart][1] + ">" + ODSperPlayer[o - rowStart][0] + "</td>")
  298. }
  299.  
  300. //loot
  301. $.getAll(linksLoot, (i, data) => {
  302. if ($(data).find(".lit-item")[3] != undefined) {
  303. temp = $(data).find(".lit-item")
  304. lootperPlayer.push([temp[3].innerText.replace(/\./g, ','), temp[4].innerText]);
  305. }
  306. else {
  307. lootperPlayer.push(["0", "Never"]);
  308. }
  309.  
  310. },
  311. () => {
  312. for (var o = rowStart; o < lootperPlayer.length + rowStart; o++) {
  313. $(tribeTable + " tr").eq(o).append("<td title=" + lootperPlayer[o - rowStart][1] + ">" + lootperPlayer[o - rowStart][0] + "</td>")
  314. }
  315. //gathering
  316. $.getAll(linksGathering, (i, data) => {
  317. if ($(data).find(".lit-item")[3] != undefined) {
  318. temp = $(data).find(".lit-item")
  319. gatheredperPlayer.push([temp[3].innerText.replace(/\./g, ','), temp[4].innerText]);
  320. }
  321. else {
  322. gatheredperPlayer.push(["0", "Never"]);
  323. }
  324.  
  325. },
  326. () => {
  327. for (var o = rowStart; o < gatheredperPlayer.length + rowStart; o++) {
  328. $(tribeTable + " tr").eq(o).append("<td title=" + gatheredperPlayer[o - rowStart][1] + ">" + gatheredperPlayer[o - rowStart][0] + "</td>")
  329. //only show combined if loot and gathering are collected
  330. if (statsEnabled["Loot"] == true && statsEnabled["Gathering"] == true) {
  331. $(tribeTable + " tr").eq(o).append("<td>" + numberWithCommas(parseInt(gatheredperPlayer[o - rowStart][0].split(",").join("")) + parseInt(lootperPlayer[o - rowStart][0].split(",").join(""))) + "</td>")
  332. }
  333. else {
  334. if (statsEnabled["Combined"] == true)
  335. $(tribeTable + " tr").eq(o).append("<td>Need both Loot and Gathering enabled to see this column</td>")
  336. }
  337. }
  338. // ODA total
  339. $.getAll(linksODATotal, (i, data) => {
  340. if ($(data).find(".lit-item")[3] != undefined) {
  341. temp = $(data).find(".lit-item")
  342. x = temp[3].innerText;
  343. console.log(x);
  344. if (x.indexOf(" Mil.") > -1) {
  345. x = x.replace(" Mil.", "");
  346. x = x.replace(",", "");
  347. x = parseInt(x) * 10000;
  348. x=x.toString();
  349. }
  350. ODATotalperPlayer.push(x.replace(/\./g, ','));
  351. }
  352. else {
  353. ODATotalperPlayer.push("0");
  354. }
  355.  
  356. },
  357. () => {
  358. for (var o = rowStart; o < ODATotalperPlayer.length + rowStart; o++) {
  359. $(tribeTable + " tr").eq(o).append("<td>" + numberWithCommas(ODATotalperPlayer[o - rowStart]) + "</td>")
  360. }
  361.  
  362. // ODD total
  363. $.getAll(linksODDTotal, (i, data) => {
  364. if ($(data).find(".lit-item")[3] != undefined) {
  365. temp = $(data).find(".lit-item")
  366. x = temp[3].innerText;
  367. console.log(x);
  368. if (x.indexOf(" Mil.") > -1) {
  369. x = x.replace(" Mil.", "");
  370. x = x.replace(",", "");
  371. x = parseInt(x) * 10000;
  372. x=x.toString();
  373. }
  374. ODDTotalperPlayer.push(x.replace(/\./g, ','));
  375. }
  376. else {
  377. ODDTotalperPlayer.push("0");
  378. }
  379.  
  380. },
  381. () => {
  382. for (var o = rowStart; o < ODDTotalperPlayer.length + rowStart; o++) {
  383. $(tribeTable + " tr").eq(o).append("<td>" + numberWithCommas(ODDTotalperPlayer[o - rowStart]) + "</td>")
  384. }
  385.  
  386. // ODS total
  387. $.getAll(linksODSTotal, (i, data) => {
  388. if ($(data).find(".lit-item")[3] != undefined) {
  389. temp = $(data).find(".lit-item")
  390. x = temp[3].innerText;
  391. console.log(x);
  392. if (x.indexOf(" Mil.") > -1) {
  393. x = x.replace(" Mil.", "");
  394. x = x.replace(",", "");
  395. x = parseInt(x) * 10000;
  396. x=x.toString();
  397. }
  398. ODSTotalperPlayer.push(x.replace(/\./g, ','));
  399. }
  400. else {
  401. ODSTotalperPlayer.push("0");
  402. }
  403.  
  404. },
  405. () => {
  406. for (var o = rowStart; o < ODSTotalperPlayer.length + rowStart; o++) {
  407. $(tribeTable + " tr").eq(o).append("<td>" + numberWithCommas(ODSTotalperPlayer[o - rowStart]) + "</td>")
  408. }
  409.  
  410. $("#progress").remove();
  411. sortTableTest(columnStart);
  412. },
  413. (error) => {
  414. console.error(error);
  415. });
  416.  
  417.  
  418.  
  419. },
  420. (error) => {
  421. console.error(error);
  422. });
  423.  
  424.  
  425. },
  426. (error) => {
  427. console.error(error);
  428. });
  429.  
  430. },
  431. (error) => {
  432. console.error(error);
  433. });
  434. },
  435. (error) => {
  436. console.error(error);
  437. });
  438. },
  439. (error) => {
  440. console.error(error);
  441. });
  442.  
  443. },
  444. (error) => {
  445. console.error(error);
  446. });
  447.  
  448.  
  449.  
  450. },
  451. (error) => {
  452. console.error(error);
  453. });
  454. }
  455.  
  456. function sortTableTest(n) {
  457. var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
  458. table = document.getElementById("tableMembers");
  459. switching = true;
  460. // Set the sorting direction to ascending:
  461. dir = "desc";
  462. /* Make a loop that will continue until
  463. no switching has been done: */
  464. while (switching) {
  465. // Start by saying: no switching is done:
  466. switching = false;
  467. rows = table.rows;
  468. /* Loop through all table rows (except the
  469. first, which contains table headers): */
  470. for (i = 1; i < (rows.length - 1); i++) {
  471. // Start by saying there should be no switching:
  472. shouldSwitch = false;
  473. /* Get the two elements you want to compare,
  474. one from current row and one from the next: */
  475. x = rows[i].getElementsByTagName("td")[n];
  476. y = rows[i + 1].getElementsByTagName("td")[n];
  477. /* Check if the two rows should switch place,
  478. based on the direction, asc or desc: */
  479. if (dir == "asc") {
  480. if (Number(x.innerHTML.replace(/\,/g, '')) > Number(y.innerHTML.replace(/\,/g, ''))) {
  481. // If so, mark as a switch and break the loop:
  482. shouldSwitch = true;
  483. break;
  484. }
  485. } else if (dir == "desc") {
  486. if (Number(x.innerHTML.replace(/\,/g, '')) < Number(y.innerHTML.replace(/\,/g, ''))) {
  487. // If so, mark as a switch and break the loop:
  488. shouldSwitch = true;
  489. break;
  490. }
  491. }
  492. }
  493. if (shouldSwitch) {
  494. /* If a switch has been marked, make the switch
  495. and mark that a switch has been done: */
  496. rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
  497. switching = true;
  498. // Each time a switch is done, increase this count by 1:
  499. switchcount++;
  500. } else {
  501. /* If no switching has been done AND the direction is "asc",
  502. set the direction to "desc" and run the while loop again. */
  503. if (switchcount == 0 && dir == "desc") {
  504. dir = "asc";
  505. switching = true;
  506. }
  507. }
  508. }
  509. createBB(tribeTable, rowStart);
  510. $("#BBCODE")[0].value = BBTable;
  511. $("#CSVCODE")[0].value = csvTable;
  512. }
  513.  
  514. function createBB(tableID, rowStart) {
  515. BBTable = "[table]\n";
  516. csvTable = "";
  517.  
  518. //grab rows
  519. for (var i = rowStart - 1; i < $(tableID + " tr").length; i++) {
  520. //grab cells
  521. if (i == rowStart - 1) {
  522. BBTable += "[**]";
  523. }
  524. else {
  525. BBTable += "[*]";
  526. }
  527. for (var j = 0; j < $(tableID + " tr")[i].children.length; j++) {
  528. //add text to code
  529. if (i == rowStart - 1) {
  530. //header row
  531. BBTable += $(tableID + " tr")[i].children[j].innerText;
  532. csvTable += $(tableID + " tr")[i].children[j].innerText;
  533. if (j != $(tableID + " tr")[i].children.length - 1) {
  534. BBTable += "[||]";
  535. csvTable += ";"
  536. }
  537. }
  538. else {
  539. //regular row
  540. BBTable += $(tableID + " tr")[i].children[j].innerText;
  541. csvTable += $(tableID + " tr")[i].children[j].innerText;
  542. if (j != $(tableID + " tr")[i].children.length - 1) {
  543. BBTable += "[|]";
  544. csvTable += ";"
  545. }
  546. }
  547.  
  548. }
  549. if (i == rowStart - 1) {
  550. BBTable += "[/**]\n";
  551. csvTable += "\n";
  552. }
  553. else {
  554. BBTable += "\n";
  555. csvTable += "\n";
  556. }
  557. }
  558. BBTable += "[/table]"
  559. }
  560.  
  561. function numberWithCommas(x) {
  562. // add . to make numbers more readable
  563. x = x.toString();
  564. var pattern = /(-?\d+)(\d{3})/;
  565. while (pattern.test(x))
  566. x = x.replace(pattern, "$1,$2");
  567. return x;
  568. }
  569.  
  570.  
  571. html = "<table id='settingsData' class='vis content-border'><tr>";
  572. for (var i = 0; i < Object.keys(statsEnabled).length; i++) {
  573. html += `
  574. <th align="center" style="width:50px;padding: 5px;">${Object.keys(statsEnabled)[i]}</th>
  575. `;
  576. }
  577. html += "</tr><tr>"
  578. for (var i = 0; i < Object.keys(statsEnabled).length; i++) {
  579. html += `
  580. <td align="center" style="padding: 5px;"><input type="checkbox" ID="${Object.keys(statsEnabled)[i]}" name="${Object.keys(statsEnabled)[i]}"></td>
  581. `;
  582. }
  583. html += `</tr></table><input type="button" class="btn btnSophie" id="getData" onclick="getData()" value="Get data"><br>`;
  584.  
  585. $("#contentContainer").eq(0).prepend(html);
  586.  
  587. for (var i = 0; i < Object.keys(statsEnabled).length; i++) {
  588. $(`#${Object.keys(statsEnabled)[i]}`).prop("checked", statsEnabled[Object.keys(statsEnabled)[i]]);
  589. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement