SteamTrades - Have List Filter (Barter.vg)

Check if you own the games from someone's have list (instant Compare2Steam) using Barter.vg

  1. // ==UserScript==
  2. // @name SteamTrades - Have List Filter (Barter.vg)
  3. // @icon https://cdn.steamtrades.com/img/favicon.ico
  4. // @namespace Revadike
  5. // @author Revadike
  6. // @version 2.0.0
  7. // @description Check if you own the games from someone's have list (instant Compare2Steam) using Barter.vg
  8. // @support https://www.steamgifts.com/discussion/fN8vR/
  9. // @match https://www.steamtrades.com/trade/*
  10. // @grant unsafeWindow
  11. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
  12. // ==/UserScript==
  13.  
  14. this.$ = this.jQuery = jQuery.noConflict(true);
  15. $(document).ready(addFilter);
  16.  
  17. function addFilter() {
  18. const filter = $(`<div>`, {
  19. id: `filterBtn`,
  20. class: `btn_action green`,
  21. style: `z-index: 16777271; position: fixed; right: 1em; bottom: 1em;`,
  22. html: `<span><i class="fa fa-filter"></i> Filter</span>`
  23. });
  24.  
  25. filter.appendTo(`body`);
  26. filter.click(addSelectorGadget);
  27. }
  28.  
  29. function addSelectorGadget() {
  30. $(`#filterBtn`).hide();
  31.  
  32. if (unsafeWindow.selector_gadget) {
  33. unsafeWindow.selector_gadget.rebind();
  34. setupSelectorGadget();
  35. } else {
  36. $.getScript(`https://dv0akt2986vzh.cloudfront.net/unstable/lib/selectorgadget.js`, () => {
  37. wait_for_script_load(`selector_gadget`, setupSelectorGadget);
  38. });
  39. }
  40. }
  41.  
  42. function setupSelectorGadget() {
  43. let modscript = `line = line.toLowerCase(); line = line.replace("(Early Access)", "");`;
  44. const btnOk = $(`<input>`, { type: `button`, class: `sg_ignore`, value: `Finish` });
  45. const btnJs = $(`<input>`, { type: `button`, class: `sg_ignore`, value: `JS` });
  46. const SG = unsafeWindow.selector_gadget;
  47.  
  48. btnOk.on(`click`, () => finishFilter(SG, modscript))
  49. btnJs.on(`click`, () => modscript = prompt(`Custom javascript to modify 'line' variable (each line)`, modscript));
  50.  
  51. SG.sg_div.append(btnOk);
  52. SG.sg_div.prepend(btnJs);
  53.  
  54. $(selector_gadget.sg_div).find(`[value=XPath]`).remove();
  55. $(selector_gadget.sg_div).find(`[value=X]`).click(() => $(`#filterBtn`).show());
  56. }
  57.  
  58. function finishFilter(SG, modscript) {
  59. const selector = SG.path_output_field.value;
  60.  
  61. if (selector === `No valid path found.`) {
  62. alert(`Please highlight the element(s) containing the games to filter`);
  63. return;
  64. }
  65.  
  66. const bulk_input = getLines(selector).map(line => {
  67. eval(modscript);
  68. return line;
  69. }).join(`\n`);
  70.  
  71. if (bulk_input.length > 40000) {
  72. alert(`Input too large. Please select fewer elements or reduce the input using JS.`);
  73. return;
  74. }
  75.  
  76. const form = $(`<form>`, { action: `https://barter.vg/u/my/c/e/`, method: `POST`, target: `_blank` });
  77. form.append($(`<input>`, { type: `hidden`, name: `bulk_input`, value: bulk_input }));
  78. form.append($(`<input>`, { type: `hidden`, name: `action`, value: `Edit` }));
  79.  
  80. $(`body`).append(form);
  81. form.submit();
  82.  
  83. SG.unbind();
  84. $(`#filterBtn`).show();
  85. }
  86.  
  87. function getLines(selector) {
  88. return [].concat(...$(selector).get().map((elem) => elem.innerText.split(`\n`)));
  89. }