tkrkt
10/15/2016 - 3:11 PM

steam-wishlist-discount-filter.user.js

// ==UserScript==
// @name        steam wishlist discount filter
// @namespace   https://gist.github.com/tkrkt
// @include     http://steamcommunity.com/profiles/*/wishlist*
// @include     https://steamcommunity.com/profiles/*/wishlist*
// @version     4
// @grant       none
// ==/UserScript==

var filter = false;
var button = document.createElement('button');
button.textContent = 'Discount filter';
button.addEventListener('click', () => {
  filter = !filter;
  Array.from(document.querySelectorAll('.wishlistRow')).forEach((e, i) => {
    var price = e.querySelector('.discount_pct');
    if(price) {
      var discount = parseInt(price.textContent, 10);
      if (filter && discount <= -75) {
        price.style.backgroundColor = 'red';
      } else if (filter && discount <= -50) {
        price.style.backgroundColor = 'orange';
      } else {
        price.style.backgroundColor = '';
      }
    } else if (filter) {
      e.style.display = 'none';
    } else {
      e.style.display = 'block';
    }
  });
}, false);

var container = document.querySelector('#wishlist_sort_options');
container.insertBefore(button, container.firstChild);