FV - scrapping

Show full pagination when scrapping, and remember the last page opened

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         FV - scrapping
// @version      1.2.1
// @description  Show full pagination when scrapping, and remember the last page opened
// @author       msjanny (#7302)
// @match        https://www.furvilla.com/career/blacksmith*
// @grant       GM_setValue
// @grant       GM_getValue
// @namespace https://greasyfork.org/users/319295
// ==/UserScript==

(function() {
  'use strict';
  /* globals $:false */

  function loadScripts() {
    //check every 300ms if pagination has loaded before continuing
    if(! $(".modal .pagination").length) {
      setTimeout ( function() {
          loadScripts();
        }, 300);
    }
    else {
      $(".modal .pagination a").click(function() {
        GM_setValue("scrapPage", $(this).attr('href'));
        loadScripts();
      });

      fullPagination();
    }
  }

  function fullPagination() {
    let active = $(".modal .pagination li").index($(".active").eq(0));
    let url = $(".modal .pagination a").eq(0).attr("href").replace(/\d+$/g, '');

    let scrapPage = GM_getValue("scrapPage", "");
    if (scrapPage && scrapPage.match(/\d+$/g)[0] != $(".modal .pagination .active").eq(0).text() && parseInt(scrapPage.match(/\d+$/g)[0]) <= parseInt($(".modal .pagination").eq(0).find('li').eq(-2).text()) ) {
        loadInventoryBlockScrapping($(".inventory-block-scrapping"), scrapPage);
        loadScripts();
    }

    //for each ellipses
    $(".disabled:contains('...')", $(".modal .pagination").eq(1)).each(function(idx) {
      let pos = $(".modal .pagination li").index($(this));
      let minPage = parseInt($(".modal .pagination li").eq(pos - 1).text());
      let maxPage = parseInt($(".modal .pagination li").eq(pos + 1).text());

        //add links
        for (var i = maxPage - 1; i > minPage; i--) {
          //create new link
          let a = $(`<a href="${url}${i}">${i}</a>`);
          a.click(function(e) {
            e.preventDefault();
            GM_setValue("scrapPage", $(this).attr('href'));
            loadInventoryBlockScrapping($(".inventory-block-scrapping"), $(this).attr('href'));
            loadScripts();
          });

          //add link
          $(this).after($("<li>").append(a));
        }

    });
    $(".disabled:contains('...')", $(".modal .pagination").eq(1)).remove();
  }

  $(document).ready(function(){
    //scrapping, pot
    $('.btn[data-url*="scrap/"]').click(function() {
      loadScripts();
    });
  });
})();