Skip to content

Instantly share code, notes, and snippets.

@ndkhoa
Last active January 18, 2019 09:43
Show Gist options
  • Select an option

  • Save ndkhoa/959f42b52dec45371b4d954d9d9dd43f to your computer and use it in GitHub Desktop.

Select an option

Save ndkhoa/959f42b52dec45371b4d954d9d9dd43f to your computer and use it in GitHub Desktop.
Re-oder element
javascript:(function()%7Bfunction callback()%7B(function(%24)%7Bvar jQuery%3D%24%3B%24.fn.swap %3D function (elem) %7Belem %3D elem.jquery %3F elem %3A %24(elem)%3Breturn this.each(function () %7B%24(document.createTextNode('')).insertBefore(this).before(elem.before(this)).remove()%3B%7D)%3B%7D%3Bfunction getPrice(e)%7Breturn Number(%24(%24(e).find('.product-item__price--final')%5B0%5D).text().match(%2F%5B0-9%5D%2Fg).join(''))%3B%7Dfunction sortProducts()%7Bproducts %3D %24('.product-item.product-item-flashdeal')%3Bfor (i %3D 0%3B i < products.length - 1%3B i%2B%2B) %7Bvar k %3D i%3Bfor (j %3D i %2B 1%3B j < products.length%3B j%2B%2B) %7Bproducts %3D %24('.product-item.product-item-flashdeal')%3Bp2 %3D %24(products%5Bj%5D)%3Bp1 %3D %24(products%5Bi%5D)%3Bif(getPrice(p1) > getPrice(p2))%7Bk %3D j%3Bp1.swap(p2)%3B%7D%7D%7D%7DloadingTime %3D 1%3BlastHeight %3D 0%3BloadingMorePage %3DsetInterval(function()%7Bif(lastHeight < %24(document).height())%7Bconsole.log("Scrolling to bottom%3A " %2B loadingTime %2B " times")%3B%24("html%2C body").animate(%7B scrollTop%3A %24(document).height() %7D%2C "slow")%3BlastHeight %3D %24(document).height()%3BloadingTime%2B%2B%3B%7D else %7Bconsole.log('Scrolling to top')%3B%24("html%2C body").animate(%7B scrollTop%3A 0 %7D%2C "slow")%3Bconsole.log('Removing product was out of stock')%3B%24('.product-item--disabled-clickable').remove()%3BclearInterval(loadingMorePage)%3BsortProducts()%3B%7D%7D%2C 2500)%7D)(jQuery.noConflict(true))%7Dvar s%3Ddocument.createElement("script")%3Bs.src%3D"https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fjquery%2F1.11.1%2Fjquery.min.js"%3Bif(s.addEventListener)%7Bs.addEventListener("load"%2Ccallback%2Cfalse)%7Delse if(s.readyState)%7Bs.onreadystatechange%3Dcallback%7Ddocument.body.appendChild(s)%3B%7D)()
$.fn.swap = function (elem) {
elem = elem.jquery ? elem : $(elem);
return this.each(function () {
$(document.createTextNode('')).insertBefore(this).before(elem.before(this)).remove();
});
};
function getPrice(e){
return Number($($(e).find('.product-item__price--final')[0]).text().match(/[0-9]/g).join(''));
}
function sortProducts(){
products = $('.product-item.product-item-flashdeal');
for (i = 0; i < products.length - 1; i++) {
var k = i;
for (j = i + 1; j < products.length; j++) {
products = $('.product-item.product-item-flashdeal');
p2 = $(products[j]);
p1 = $(products[i]);
if(getPrice(p1) > getPrice(p2)){
k = j;
p1.swap(p2);
}
}
}
}
loadingTime = 1;
lastHeight = 0;
loadingMorePage =
setInterval(function(){
if(lastHeight < $(document).height()){
console.log("Scrolling to bottom: " + loadingTime + " times");
$("html, body").animate({ scrollTop: $(document).height() }, "slow");
lastHeight = $(document).height();
loadingTime++;
} else {
console.log('Scrolling to top');
$("html, body").animate({ scrollTop: 0 }, "slow");
console.log('Removing product was out of stock');
$('.product-item--disabled-clickable').remove();
clearInterval(loadingMorePage);
sortProducts();
}
}, 2500)
@ndkhoa

ndkhoa commented Jan 18, 2019

Copy link
Copy Markdown
Author

hiepdinh [4:11 PM]
haha
mới thấy có cách này nhanh hơn nữa anh
call trực tiếp cái ajax của nó
rồi rebuild lại cái list html là xong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment