Skip to content

Instantly share code, notes, and snippets.

@rooftopchicken
Last active January 21, 2021 01:45
Show Gist options
  • Select an option

  • Save rooftopchicken/42c60e733fb147043a9907663c45fb53 to your computer and use it in GitHub Desktop.

Select an option

Save rooftopchicken/42c60e733fb147043a9907663c45fb53 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name FV - scrapping
// @version 1.0
// @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
// ==/UserScript==
(function() {
'use strict';
/* globals $:false */
function loadScripts(counter) {
//check every 300ms if pagination has loaded before continuing
// (up to 10 times)
if (counter === undefined) {
loadScripts(0);
}
else if(! $(".modal .pagination").length && counter < 10) {
setTimeout ( function() {
loadScripts(counter + 1);
}, 300);
}
else if (counter < 10) {
$(".modal .pagination a").click(function() {
GM_setValue("scrapPage", $(this).attr('href'));
loadScripts(0);
});
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()) {
loadInventoryBlockScrapping($(".inventory-block-scrapping"), scrapPage);
loadScripts(0);
}
//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(0);
});
//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(0);
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment