msjanny

fv price checker

May 8th, 2017 (edited)
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Furvilla - Price Checker
  3. // @namespace   Shaun Dreclin
  4. // @description Shows stall prices and sellback value of items on the quickstock and stall management pages.
  5. // @include     https://www.furvilla.com/stall/manage*
  6. // @version     2.0
  7. // @grant       GM_addStyle
  8. // @grant       GM_setValue
  9. // @grant       GM_getValue
  10. // ==/UserScript==
  11.  
  12. GM_addStyle("\
  13. .pricebox {\
  14.     position: absolute;\
  15.     right: 100%;\
  16.     margin-top: -9px;\
  17.     min-width: 50px;\
  18.     padding: 0px 0px 0px 5px;\
  19.     height: 68px;\
  20.     border: 1px solid #daf3fc;\
  21.     border-right: 0px;\
  22.     border-radius: 5px 0px 0px 5px;\
  23.     background: inherit;\
  24.     text-align: right;\
  25.     white-space: nowrap;\
  26. }\
  27. .pricebox span {\
  28.  display: block;\
  29. }\
  30. td:nth-child(6) {\
  31.  min-width: 50px;\
  32. }\
  33. h1 + .widget {\
  34.  overflow: hidden;\
  35. }\
  36. .toggle {\
  37.  height: 32px;\
  38.  line-height: 32px;\
  39.  float: right;\
  40. }\
  41. .toggle:hover {\
  42.  cursor: pointer;\
  43. }");
  44.  
  45. $(document).ready(function() {
  46.   // option to minimize the customizations until we need it
  47.   let isCollapsed = GM_getValue("collapse", false);
  48.   let collapse = $('<i class="toggle fas fa-minus">').click(function() {
  49.     if (isCollapsed) {
  50.       $(this).removeClass('fa-plus').addClass('fa-minus');
  51.       $("h1 + .widget").css("height", "");
  52.       isCollapsed = false;
  53.       GM_setValue("collapse", false);
  54.     }
  55.     else {
  56.       $(this).removeClass('fa-minus').addClass('fa-plus');
  57.       $("h1 + .widget").css("height", "35px");
  58.       isCollapsed = true;
  59.       GM_setValue("collapse", true);
  60.     }
  61.   });
  62.   $("h1 + .widget h3").append(collapse);
  63.   if (isCollapsed) {
  64.     $(this).removeClass('fa-minus').addClass('fa-plus');
  65.     $("h1 + .widget").css("height", "35px");
  66.   }
  67.  
  68.   // first build list of items we need to search
  69.   // todo add sellbacks?
  70.   let items = {}; // key is item ID; value is array of row #s
  71.   let rows = $("form tbody tr");
  72.   rows.each(function(i) {
  73.     const itemImg = $(this).find("img[src*='furvilla.com/img/items/']").attr("src");
  74.     const itemID = itemImg.match(/[0-9]+/g)[1];
  75.  
  76.     if (items[itemID])
  77.       items[itemID].push(i);
  78.     else
  79.       items[itemID] = [i];
  80.   });
  81.  
  82.   //then search the stalls! this way, we can prevent duplicate searches.
  83.   for(const [id, indices] of Object.entries(items)) {
  84.     const url = `https://www.furvilla.com/stalls/search?name=${id}`;
  85.     const sellback = parseInt(rows.eq(indices[0]).find(".net").data("sellback"));
  86.  
  87.     $.get(url, function(data) {
  88.  
  89.       let result = $.parseHTML(data);
  90.       let prices = $(".left-column > .table tbody tr", result);
  91.       let pricebox = $("<div class='pricebox'>");
  92.  
  93.       for (let i = 0; i < 3 && i < prices.length; i++) {
  94.         let price = $("<span>");
  95.         price.append(prices.eq(i).find("td:nth-child(3)").html());
  96.         if (parseInt(prices.eq(i).find("td:nth-child(3)").text()) < sellback && price.find('img[src$="furcoins.gif"]').length)
  97.           price.css("color", "#D00");
  98.         else if (! prices.eq(i).find(".btn").length)
  99.           price.css("color", "#0D0");
  100.         pricebox.append(price);
  101.       }
  102.  
  103.       for (let i = 0; i < indices.length; i++) {
  104.         rows.eq(indices[i]).find("td:first-child")
  105.           .prepend(pricebox.prop('outerHTML'))
  106.           .append($(`<a href="${url}"><i class="fas fa-search"></i></a>`));
  107.       }
  108.     });
  109.   }
  110. });
  111.  
Add Comment
Please, Sign In to add comment