Created
October 22, 2015 19:26
-
-
Save dorukcan/12783dab34b1dbeaa9eb to your computer and use it in GitHub Desktop.
sorts products by price on yemeksepeti.com
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
// ==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