Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. // ==UserScript==
  2. // @name E-sim - MU transactions enhancement
  3. // @namespace http://history.unixstorm.org/staff/js/
  4. // @version 0.1
  5. // @description adds possibility to see up to 50 (value can be changed) pages of MU transactions on one page.
  6. // @author You
  7. // @include /^https?:\/\/(.*)\.e-sim\.org\/militaryUnitLogs.html?.*$/
  8. // @grant none
  9. // ==/UserScript==
  10. globalStop = false;
  11. loadedPages = 0;
  12. waitingPages = 0;
  13. reqSent = 0;
  14. counter = 0;
  15. max = 50;
  16.  
  17. addButtons();
  18.  
  19.  
  20. function addButtons() {
  21.  
  22. const $button = $(`#container > div.foundation-style.column-margin-both.column-margin-vertical.column.small-8.foundation-text-center.no-style > div > form > input[type="submit"]:nth-child(7)`).clone();
  23.  
  24.  
  25. $($button).clone().insertAfter(`#container > div.foundation-style.column-margin-both.column-margin-vertical.column.small-8.foundation-text-center.no-style > div > form > input[type="submit"]:nth-child(7)`)
  26. .attr('id', 'checkTrans')
  27. .val(`Load next pages`)
  28. .click(function(event) {
  29. start();
  30. event.preventDefault();
  31.  
  32. }
  33.  
  34. );
  35.  
  36. }
  37.  
  38.  
  39. function start() {
  40. var $link = $(`#pagination-digg > li.next > a`).attr('href');
  41.  
  42. if (!$link) {
  43. updateButton(`No pages to check!`);
  44. } else {
  45.  
  46. var $last = $($(`#pagination-digg > li:nth-last-child(2)`).html()).attr('href');
  47.  
  48. //next page number
  49. const nextPageNr = parseInt(/&page=(.*)$/.exec($link)[1]);
  50.  
  51. //try to get last page number
  52. lastPage = parseInt(/&page=(.*)$/.exec($last)[1]);
  53. lastRealPage = lastPage;
  54.  
  55.  
  56. const $pagePosition = $link.indexOf("page=");
  57. $linkTemplate = $linkTemplate = $link.substr(0, $pagePosition) + 'page=';
  58.  
  59.  
  60. if (lastPage > max) {
  61. lastPage = max + nextPageNr - 1;
  62. } else {
  63. max = lastPage - nextPageNr + 1;
  64.  
  65. }
  66. for (i = nextPageNr, j = 1; j <= max; i++, j++) {
  67.  
  68. (function(i) {
  69.  
  70. setTimeout(function() {
  71.  
  72. load($linkTemplate + i, i);
  73.  
  74. }, j * 500);
  75.  
  76. })(i);
  77. }
  78. }
  79. }
  80.  
  81. function load($link, i) {
  82.  
  83. const currentPage = i;
  84.  
  85. if (globalStop === false || currentPage < lastRealPage) {
  86.  
  87. reqSent++;
  88. updateButton(`Requests sent: ` + reqSent + ` (max ` + max + `), Loaded pages ` + loadedPages + `...`);
  89. console.log(`sending request: ` + $link);
  90.  
  91. $("<tr>").html(`<th colspan="6" bgcolor="black" height="50px"><strong><a href="` + $link + `">Page ` + currentPage + `</a></strong></th>`)
  92. .insertAfter(`#container > div.foundation-style.column-margin-both.column-margin-vertical.column.small-8.foundation-text-center.no-style > table > tbody > tr:last-child`)
  93. .attr('id', 'page' + currentPage);
  94.  
  95. waitingPages++;
  96.  
  97. var $page = $.get($link, function() {
  98. processPage($page, $link, currentPage);
  99.  
  100. });
  101. }
  102.  
  103. }
  104.  
  105. function processPage(page, $link, currentPage) {
  106.  
  107. if (globalStop === false || currentPage < lastRealPage) {
  108.  
  109. console.log(`proccesing page` + currentPage);
  110.  
  111. var $tbody = $(page.responseText).find('tbody')[0];
  112. $tbody.firstChild.remove();
  113.  
  114. $($tbody.innerHTML).insertAfter(`#page` + currentPage)
  115. .attr('class', 'pageContent' + currentPage);
  116.  
  117. loadedPages++;
  118. updateButton(`Requests sent: ` + reqSent + ` (max ` + max + `), Loaded pages ` + loadedPages + `...`);
  119.  
  120. const $nextPage = $(page.responseText).find('li.next')[0];
  121.  
  122. if (true) {
  123.  
  124. if (currentPage === lastPage) {
  125. lastCheck();
  126. const next = currentPage + 1;
  127.  
  128. $("<tr>").html(`<th colspan="6" bgcolor="black" height="50px"><strong><a href="` + $linkTemplate + next + `">Continue scanning and go to page ` + next + `</a></strong></th>`)
  129. .insertAfter(`#container > div.foundation-style.column-margin-both.column-margin-vertical.column.small-8.foundation-text-center.no-style > table > tbody > tr:last-child`)
  130. .attr('id', 'page' + next);
  131.  
  132. }
  133. } else {
  134.  
  135. globalStop = true;
  136.  
  137. if (lastRealPage > currentPage) {
  138. lastRealPage = currentPage;
  139. console.log(`Last real page: ` + lastRealPage);
  140. }
  141. }
  142.  
  143. } else {
  144. console.log(`ignoring: ` + currentPage);
  145. lastCheck();
  146. }
  147. waitingPages--;
  148.  
  149. if (waitingPages === 0) {
  150. //lastCheck();
  151. }
  152. }
  153.  
  154. function updateButton(text) {
  155. $(`#checkTrans`).val(text);
  156. console.log(text);
  157. }
  158.  
  159. function lastCheck() {
  160.  
  161. var h = parseInt(lastRealPage) + 1;
  162. var h2 = parseInt(lastRealPage) + parseInt(lastPage);
  163. for (h; h <= h2; h++) {
  164.  
  165. $(`.pageContent` + h).hide();
  166. $(`#page` + h).hide();
  167.  
  168. }
  169. updateButton(`Finished, Loaded pages ` + loadedPages);
  170.  
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement