Advertisement
Guest User

Untitled

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