FV - scrapping

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();
    });
  });
})();