Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Furvilla - Price Checker
- // @namespace Shaun Dreclin
- // @description Shows stall prices and sellback value of items on the quickstock and stall management pages.
- // @include https://www.furvilla.com/stall/manage*
- // @version 2.0
- // @grant GM_addStyle
- // @grant GM_setValue
- // @grant GM_getValue
- // ==/UserScript==
- GM_addStyle("\
- .pricebox {\
- position: absolute;\
- right: 100%;\
- margin-top: -9px;\
- min-width: 50px;\
- padding: 0px 0px 0px 5px;\
- height: 68px;\
- border: 1px solid #daf3fc;\
- border-right: 0px;\
- border-radius: 5px 0px 0px 5px;\
- background: inherit;\
- text-align: right;\
- white-space: nowrap;\
- }\
- .pricebox span {\
- display: block;\
- }\
- td:nth-child(6) {\
- min-width: 50px;\
- }\
- h1 + .widget {\
- overflow: hidden;\
- }\
- .toggle {\
- height: 32px;\
- line-height: 32px;\
- float: right;\
- }\
- .toggle:hover {\
- cursor: pointer;\
- }");
- $(document).ready(function() {
- // option to minimize the customizations until we need it
- let isCollapsed = GM_getValue("collapse", false);
- let collapse = $('<i class="toggle fas fa-minus">').click(function() {
- if (isCollapsed) {
- $(this).removeClass('fa-plus').addClass('fa-minus');
- $("h1 + .widget").css("height", "");
- isCollapsed = false;
- GM_setValue("collapse", false);
- }
- else {
- $(this).removeClass('fa-minus').addClass('fa-plus');
- $("h1 + .widget").css("height", "35px");
- isCollapsed = true;
- GM_setValue("collapse", true);
- }
- });
- $("h1 + .widget h3").append(collapse);
- if (isCollapsed) {
- $(this).removeClass('fa-minus').addClass('fa-plus');
- $("h1 + .widget").css("height", "35px");
- }
- // first build list of items we need to search
- // todo add sellbacks?
- let items = {}; // key is item ID; value is array of row #s
- let rows = $("form tbody tr");
- rows.each(function(i) {
- const itemImg = $(this).find("img[src*='furvilla.com/img/items/']").attr("src");
- const itemID = itemImg.match(/[0-9]+/g)[1];
- if (items[itemID])
- items[itemID].push(i);
- else
- items[itemID] = [i];
- });
- //then search the stalls! this way, we can prevent duplicate searches.
- for(const [id, indices] of Object.entries(items)) {
- const url = `https://www.furvilla.com/stalls/search?name=${id}`;
- const sellback = parseInt(rows.eq(indices[0]).find(".net").data("sellback"));
- $.get(url, function(data) {
- let result = $.parseHTML(data);
- let prices = $(".left-column > .table tbody tr", result);
- let pricebox = $("<div class='pricebox'>");
- for (let i = 0; i < 3 && i < prices.length; i++) {
- let price = $("<span>");
- price.append(prices.eq(i).find("td:nth-child(3)").html());
- if (parseInt(prices.eq(i).find("td:nth-child(3)").text()) < sellback && price.find('img[src$="furcoins.gif"]').length)
- price.css("color", "#D00");
- else if (! prices.eq(i).find(".btn").length)
- price.css("color", "#0D0");
- pricebox.append(price);
- }
- for (let i = 0; i < indices.length; i++) {
- rows.eq(indices[i]).find("td:first-child")
- .prepend(pricebox.prop('outerHTML'))
- .append($(`<a href="${url}"><i class="fas fa-search"></i></a>`));
- }
- });
- }
- });
Add Comment
Please, Sign In to add comment