Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name E-sim - MU transactions enhancement
- // @namespace http://history.unixstorm.org/staff/js/
- // @version 0.1
- // @description adds possibility to see up to 50 (value can be changed) pages of MU transactions on one page.
- // @author You
- // @include /^https?:\/\/(.*)\.e-sim\.org\/militaryUnitLogs.html?.*$/
- // @grant none
- // ==/UserScript==
- globalStop = false;
- loadedPages = 0;
- waitingPages = 0;
- reqSent = 0;
- counter = 0;
- max = 50;
- addButtons();
- function addButtons() {
- 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();
- $($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)`)
- .attr('id', 'checkTrans')
- .val(`Load next pages`)
- .click(function(event) {
- start();
- event.preventDefault();
- }
- );
- }
- function start() {
- var $link = $(`#pagination-digg > li.next > a`).attr('href');
- if (!$link) {
- updateButton(`No pages to check!`);
- } else {
- var $last = $($(`#pagination-digg > li:nth-last-child(2)`).html()).attr('href');
- //next page number
- const nextPageNr = parseInt(/&page=(.*)$/.exec($link)[1]);
- //try to get last page number
- lastPage = parseInt(/&page=(.*)$/.exec($last)[1]);
- lastRealPage = lastPage;
- const $pagePosition = $link.indexOf("page=");
- $linkTemplate = $linkTemplate = $link.substr(0, $pagePosition) + 'page=';
- if (lastPage > max) {
- lastPage = max + nextPageNr - 1;
- } else {
- max = lastPage - nextPageNr + 1;
- }
- for (i = nextPageNr, j = 1; j <= max; i++, j++) {
- (function(i) {
- setTimeout(function() {
- load($linkTemplate + i, i);
- }, j * 500);
- })(i);
- }
- }
- }
- function load($link, i) {
- const currentPage = i;
- if (globalStop === false || currentPage < lastRealPage) {
- reqSent++;
- updateButton(`Requests sent: ` + reqSent + ` (max ` + max + `), Loaded pages ` + loadedPages + `...`);
- console.log(`sending request: ` + $link);
- $("<tr>").html(`<th colspan="6" bgcolor="black" height="50px"><strong><a href="` + $link + `">Page ` + currentPage + `</a></strong></th>`)
- .insertAfter(`#container > div.foundation-style.column-margin-both.column-margin-vertical.column.small-8.foundation-text-center.no-style > table > tbody > tr:last-child`)
- .attr('id', 'page' + currentPage);
- waitingPages++;
- var $page = $.get($link, function() {
- processPage($page, $link, currentPage);
- });
- }
- }
- function processPage(page, $link, currentPage) {
- if (globalStop === false || currentPage < lastRealPage) {
- console.log(`proccesing page` + currentPage);
- var $tbody = $(page.responseText).find('tbody')[0];
- $tbody.firstChild.remove();
- $($tbody.innerHTML).insertAfter(`#page` + currentPage)
- .attr('class', 'pageContent' + currentPage);
- loadedPages++;
- updateButton(`Requests sent: ` + reqSent + ` (max ` + max + `), Loaded pages ` + loadedPages + `...`);
- const $nextPage = $(page.responseText).find('li.next')[0];
- if (true) {
- if (currentPage === lastPage) {
- lastCheck();
- const next = currentPage + 1;
- $("<tr>").html(`<th colspan="6" bgcolor="black" height="50px"><strong><a href="` + $linkTemplate + next + `">Continue scanning and go to page ` + next + `</a></strong></th>`)
- .insertAfter(`#container > div.foundation-style.column-margin-both.column-margin-vertical.column.small-8.foundation-text-center.no-style > table > tbody > tr:last-child`)
- .attr('id', 'page' + next);
- }
- } else {
- globalStop = true;
- if (lastRealPage > currentPage) {
- lastRealPage = currentPage;
- console.log(`Last real page: ` + lastRealPage);
- }
- }
- } else {
- console.log(`ignoring: ` + currentPage);
- lastCheck();
- }
- waitingPages--;
- if (waitingPages === 0) {
- //lastCheck();
- }
- }
- function updateButton(text) {
- $(`#checkTrans`).val(text);
- console.log(text);
- }
- function lastCheck() {
- var h = parseInt(lastRealPage) + 1;
- var h2 = parseInt(lastRealPage) + parseInt(lastPage);
- for (h; h <= h2; h++) {
- $(`.pageContent` + h).hide();
- $(`#page` + h).hide();
- }
- updateButton(`Finished, Loaded pages ` + loadedPages);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement