Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.49 KB | None | 0 0
  1. // ==UserScript==
  2. // @name E-sim - transactions enhancement
  3. // @namespace http://history.unixstorm.org/staff/js/
  4. // @version 0.14
  5. // @description adds possibility to load all citizen's transactions on one page and to filter useless transactions like motivations sent. Due to slow e-sim database some scans may take more time.
  6. // @author Michal
  7. // @include /^https?:\/\/(.*)\.e-sim\.org\/citizenTransactions.html?.*$/
  8. // @grant none
  9. // ==/UserScript==
  10. globalStop = false;
  11. loadedPages = 0;
  12. waitingPages = 0;
  13. reqSent = 0;
  14. counter = 0;
  15. counter2 = 0;
  16. max = 25;
  17.  
  18. addButtons();
  19.  
  20.  
  21. function addButtons() {
  22.  
  23. const $button = $(`#logCitizenForm > input[type="submit"]:nth-child(7)`).clone();
  24.  
  25.  
  26. $($button).clone().insertAfter(`#logCitizenForm > input[type="submit"]:nth-child(7)`)
  27. .attr('id', 'checkTrans')
  28. .val(`Load next pages`)
  29. .click(function(event) {
  30. start();
  31. event.preventDefault();
  32.  
  33. }
  34.  
  35. );
  36.  
  37. $($button).clone().insertAfter(`#checkTrans`)
  38. .attr('id', 'widenTable')
  39. .val(`Widen table`)
  40. .click(function(event) {
  41. $(`#userMenu`).toggle();
  42. if (counter % 2 === 0) {
  43. $(`#container > div.foundation-style.column-margin-both.column-margin-vertical.column.small-8.foundation-text-center.no-style > table`).width($(window).width() - 200);
  44. $(`#widenTable`).val(`Standard table`);
  45. } else {
  46. $(`#container > div.foundation-style.column-margin-both.column-margin-vertical.column.small-8.foundation-text-center.no-style > table`).width(740);
  47. $(`#widenTable`).val(`Widen table`);
  48. }
  49. counter++;
  50. event.preventDefault();
  51.  
  52. });
  53.  
  54. $($button).clone().insertAfter(`#widenTable`)
  55. .attr('id', 'hideTrans')
  56. .val('Hide sent motivations')
  57. .click(function(event){
  58. hideTrans();
  59. if (counter2 % 2 === 0) {
  60.  
  61. $(`#hideTrans`).val(`Show sent motivations`);
  62. } else {
  63.  
  64. $(`#hideTrans`).val(`Hide sent motivations`);
  65. }
  66. counter2++;
  67. event.preventDefault();
  68. });
  69.  
  70. }
  71.  
  72.  
  73.  
  74.  
  75. function start() {
  76. var $link = $(`#pagination-digg > li.next > a`).attr('href');
  77.  
  78. if (!$link) {
  79. updateButton(`No pages to check!`);
  80. } else {
  81.  
  82. var $last = $($(`#pagination-digg > li:nth-last-child(2)`).html()).attr('href');
  83.  
  84. //next page number
  85. const nextPageNr = parseInt(/&page=(.*)$/.exec($link)[1]);
  86.  
  87. //try to get last page number
  88. lastPage = parseInt(/&page=(.*)$/.exec($last)[1]);
  89. lastRealPage = lastPage;
  90.  
  91.  
  92. const $pagePosition = $link.indexOf("page=");
  93. $linkTemplate = $linkTemplate = $link.substr(0, $pagePosition) + 'page=';
  94.  
  95.  
  96. if (lastPage == 2147483647) {
  97. lastPage = max + nextPageNr - 1;
  98. } else {
  99. max = lastPage - nextPageNr + 1;
  100.  
  101. }
  102. for (i = nextPageNr, j = 1; j <= max; i++, j++) {
  103.  
  104. (function(i) {
  105.  
  106. setTimeout(function() {
  107.  
  108. load($linkTemplate + i, i);
  109.  
  110. }, j * 500);
  111.  
  112. })(i);
  113. }
  114. }
  115. }
  116.  
  117. function load($link, i) {
  118.  
  119. const currentPage = i;
  120.  
  121. if (globalStop === false || currentPage < lastRealPage) {
  122.  
  123. reqSent++;
  124. updateButton(`Requests sent: ` + reqSent + ` (max ` + max + `), Loaded pages ` + loadedPages + `...`);
  125. console.log(`sending request: ` + $link);
  126.  
  127. $("<tr>").html(`<th colspan="6" bgcolor="black" height="50px"><strong><a href="` + $link + `">Page ` + currentPage + `</a></strong></th>`)
  128. .insertAfter(`#container > div.foundation-style.column-margin-both.column-margin-vertical.column.small-8.foundation-text-center.no-style > table > tbody > tr:last-child`)
  129. .attr('id', 'page' + currentPage);
  130.  
  131. waitingPages++;
  132.  
  133. var $page = $.get($link, function() {
  134. processPage($page, $link, currentPage);
  135.  
  136. });
  137. }
  138.  
  139. }
  140.  
  141. function updateButton(text) {
  142. $(`#checkTrans`).val(text);
  143. }
  144.  
  145. function processPage(page, $link, currentPage) {
  146.  
  147. if (globalStop === false || currentPage < lastRealPage) {
  148.  
  149. console.log(`proccesing page` + currentPage);
  150.  
  151. var $tbody = $(page.responseText).find('tbody')[1];
  152. $tbody.firstChild.remove();
  153.  
  154. $($tbody.innerHTML).insertAfter(`#page` + currentPage)
  155. .attr('class', 'pageContent' + currentPage);
  156.  
  157. loadedPages++;
  158. updateButton(`Requests sent: ` + reqSent + ` (max ` + max + `), Loaded pages ` + loadedPages + `...`);
  159.  
  160. const $nextPage = $(page.responseText).find('li.next')[0];
  161.  
  162. if ($($nextPage).length > 0) {
  163. if (currentPage === lastPage) {
  164. lastCheck();
  165. const next = currentPage + 1;
  166.  
  167. $("<tr>").html(`<th colspan="6" bgcolor="black" height="50px"><strong><a href="` + $linkTemplate + next + `">Continue scanning and go to page ` + next + `</a></strong></th>`)
  168. .insertAfter(`#container > div.foundation-style.column-margin-both.column-margin-vertical.column.small-8.foundation-text-center.no-style > table > tbody > tr:last-child`)
  169. .attr('id', 'page' + next);
  170.  
  171. }
  172. } else {
  173.  
  174. globalStop = true;
  175.  
  176. if (lastRealPage > currentPage) {
  177. lastRealPage = currentPage;
  178. console.log(`Last real page: ` + lastRealPage);
  179. }
  180. }
  181.  
  182. } else {
  183. console.log(`ignoring: ` + currentPage);
  184. lastCheck();
  185. }
  186. waitingPages--;
  187.  
  188. if (waitingPages === 0) {
  189. lastCheck();
  190. }
  191. }
  192.  
  193. function lastCheck() {
  194.  
  195. var h = parseInt(lastRealPage) + 1;
  196. var h2 = parseInt(lastRealPage) + parseInt(lastPage);
  197. for (h; h <= h2; h++) {
  198.  
  199. $(`.pageContent` + h).hide();
  200. $(`#page` + h).hide();
  201.  
  202. }
  203. updateButton(`Finished, Loaded pages ` + loadedPages);
  204.  
  205. }
  206.  
  207. function hideTrans() {
  208. $(`#container > div.foundation-style.column-margin-both.column-margin-vertical.column.small-8.foundation-text-center.no-style > table > tbody > tr`).each(function(){
  209. let checker = $(this).text().match('has sent a motivation package containing');
  210. if(!checker){
  211. }
  212. else {
  213. if(counter2 %2 === 0){
  214. $(this).hide();
  215. }
  216. else {
  217. $(this).show();
  218. }
  219. }
  220. });
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement