-
-
Save Zibri/4081ec9d522f8eda3b52df53231ae6cd to your computer and use it in GitHub Desktop.
Sort Wish.com results by price
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("<style>.overlay { position:absolute; background-color: white; top:0; left:0; width:100%; height:100%; z-index:1000; } .loader { position: fixed; top: 1em; padding: 15px; maring: 15px; border: 1px solid #000000; border-radius: 10px; background-color: #CC0000; color: #FFFFFF; right: 1em; z-index: 999999999999; }</style>").appendTo("head"); | |
$("body").append("<div id='overlay' class='overlay'></div><div id='loader' class='loader'><b>Bezig met inladen en sorteren ...</b></div>"); | |
maxProducts = prompt("Hoeveel producten wil je inladen? (max. 500)"); | |
var app = setInterval(function(){ | |
if ($(".feed-product-item").length < maxProducts){ | |
if($("#loading-img.hide").length == 0){ | |
$("html, body").animate({ scrollTop: $(document).height() }, 0); | |
$('#overlay').css({ height: $(document).height() }); | |
} | |
}else{ clearInterval(app); | |
$('.currency-subscript').remove(); | |
$( ".feed-product-item" ).each(function(){ | |
price = $(this).find(".feed-actual-price").html(); | |
price = price.replace(" € ","").replace("€","").replace(" ","").replace("Free",0); | |
$(this).attr('price', $.trim(price)); | |
if (price == 0 || price > 20){ $(this).remove(); } | |
}) | |
var products = $(".feed-product-item"); | |
products.sort(function (a, b) { | |
// convert to integers from strings | |
a = parseInt($(a).attr("price"), 10); | |
b = parseInt($(b).attr("price"), 10); | |
if(a > b) { return 1;} else if(a < b) { return -1; } else { return 0; } | |
}); | |
// put sorted results back on page | |
$("#feed-grid").html(''); | |
$("#feed-grid").append(products); | |
$("#overlay").remove(); | |
$("#loader").remove(); | |
$("html, body").animate({ scrollTop: 0 }, 0); | |
} | |
},50); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment