Barter.vg Wishlist Match Enhancer

Removes untradable items (0 tradable), and sort list in descending order by number of traders

  1. // ==UserScript==
  2. // @name Barter.vg Wishlist Match Enhancer
  3. // @description Removes untradable items (0 tradable), and sort list in descending order by number of traders
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.1
  6. // @author mcbyte
  7. // @match https://barter.vg/u/*/w/m/
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
  9. // @runat document-end
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. this.$ = this.jQuery = jQuery.noConflict(true);
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. $('#wishGame > option').each(function() {
  19. if (this.text.endsWith('(0)')) {
  20. $(this).remove();
  21. }
  22. });
  23.  
  24. // sort select menu
  25. $('#wishGame > option').each(function() {
  26. var tradeCountObj = this.text.match(/\((\d+)\)/);
  27. if (tradeCountObj != null) {
  28. var tradeCount = tradeCountObj[1];
  29. $(this).attr('dataSort', tradeCount);
  30. console.log(this.text + ' is traded by this many people: ' + tradeCount);
  31. }
  32. });
  33.  
  34. var selectList = $('#wishGame option');
  35.  
  36. selectList.sort(function(a,b){
  37. var aVal = $(a).attr('dataSort');
  38. var bVal = $(b).attr('dataSort');
  39. if (aVal != bVal) {
  40. return bVal - aVal;
  41. } else {
  42. return ($(a).text() > $(b).text() ? 1 : -1);
  43. }
  44. });
  45. console.log(selectList);
  46. $('#wishGame').empty().append(selectList);
  47. $('#wishGame').val('0');
  48. $('#wishGame option:first').text('[ any game on wishlist ] (Enhanced+)');
  49.  
  50. })();