Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dorukcan
Created October 22, 2015 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dorukcan/12783dab34b1dbeaa9eb to your computer and use it in GitHub Desktop.
Save dorukcan/12783dab34b1dbeaa9eb to your computer and use it in GitHub Desktop.
sorts products by price on yemeksepeti.com
// ==UserScript==
// @name Yemeksepeti
// @namespace https://*.yemeksepeti.com/*
// @version 0.1
// @description sorts products by price on yemeksepeti.com
// @author dorukcan kişin
// @author https://twitter.com/johnpaulziller
// @grant none
// ==/UserScript==
String.prototype.toFloat = function(){
return parseFloat(this);
}
var detailBoxes = document.getElementsByClassName('restaurantDetailBox');
for(index=0;index<detailBoxes.length;index++){
var list = detailBoxes[index].getElementsByTagName('ul')[0];
var items = list.childNodes;
var itemsArr = [];
for (var i in items) {
if (items[i].nodeType == 1) { // get rid of the whitespace text nodes
itemsArr.push(items[i]);
}
}
itemsArr.sort(function(a, b) {
return getPrice(a) == getPrice(b)
? 0
: (getPrice(a) > getPrice(b) ? 1 : -1);
});
for (i = 0; i < itemsArr.length; ++i) {
list.appendChild(itemsArr[i]);
}
}
function getPrice(element){
return element.getElementsByClassName('newPrice')[0].innerText.replace(' TL', '').replace(',', '.').toFloat();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment