// ==UserScript== // @name Wish.com - Price filter // @namespace http://tampermonkey.net/ // @version 1.6 // @description Filtering by max price & free status // @author obscenelysad@gmail.com, Shuunen // @match https://www.wish.com/* // @grant none // @downloadURL none // ==/UserScript== $(document).ready(function() { console.log('wish price filter : init'); // Returns a function, that, as long as it continues to be invoked, will not // be triggered. The function will be called after it stops being called for // N milliseconds. If `immediate` is passed, trigger the function on the // leading edge, instead of the trailing. function debounce(func, wait, immediate) { var timeout; return function() { var context = this, args = arguments; var later = function() { timeout = null; if (!immediate) func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; } function showHideProducts() { console.log('wish price filter : showHideProducts'); var maxPrice = parseInt($("#wtc_max_price").val()) || 1000; var hideFree = $("#wtc_hide_free").val(); var items = $(".feed-actual-price"); $.each( items, function() { var priceOk = ($(this).text().replace(/\D/g,'') <= maxPrice); if(priceOk && hideFree && this.textContent.includes('Free')){ priceOk = false; } $(this).parent().parent().parent().parent().toggle(priceOk); }); } if ($("#nav-search").length > 0){ $('#mobile-app-buttons').hide(); $('#nav-search-input-wrapper').width(320); var html = '
'; html += 'Max Price : '; html += '
'; html += 'Hide free : '; html += '
'; $("#header-left").after(html); } var showHideProductsDebounced = debounce(showHideProducts, 500); // trigger twice by default showHideProductsDebounced(); setTimeout(showHideProductsDebounced, 1000); // when window is scrolled window.onscroll = showHideProductsDebounced; // when input value change $("#wtc_max_price").keydown(showHideProductsDebounced); });