// ==UserScript==
// @name Wish.com - Price filter & more
// @namespace http://tampermonkey.net/
// @version 3.2
// @description Filtering by min/max price, allow hidding free products, see reviews
// @author Shuunen
// @match https://*.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);
};
}
var activeRequests = 0;
function fetchData(id, productEl, delay, noRecursion) {
console.log('will get data for', id);
return new Promise(resolve => {
setTimeout(() => {
const url = 'https://www.wish.com/c/' + id;
console.log('getting data for', id);
fetch(url)
.then(r => r.text())
.then(html => {
const dataMatches = html.match(/"aggregateRating" : ([\w\W\n]+"\n}),/gi);
const dataStr = dataMatches[0];
const data = JSON.parse(
'{' + dataStr.replace('},', '}').replace(/\n/g, '') + '}'
);
const ratings = Math.round(data.aggregateRating.ratingValue * 100) / 100;
const count = Math.round(data.aggregateRating.ratingCount);
console.log(id, ': found a rating of', ratings, 'over', count, 'reviews :)');
let roundedRatings = Math.round(ratings);
let ratingsStr = '';
while(roundedRatings--) {
ratingsStr += '';
}
if(count > 0){
ratingsStr += '