Last active
July 31, 2019 08:46
-
-
Save ardacetinkaya/8dc2a683316858b423003224be31d82a to your computer and use it in GitHub Desktop.
Yemeksepeti'nde verilen toplam sipariş miktarı(TL) ve adeti olarak düzenlendi. İlk kaynak: https://eksisozluk.com/toplam-yemeksepeti-com-harcamasini-gosteren-kod--6125159?p=1
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
let changed = true; | |
let itemLength = 0; | |
let oldLength = 0; | |
let tolerance = 0; | |
var totalP = 0; | |
var sleepTime = 1500; | |
var repository = new Map(); | |
function calculate() { | |
var totalAmount=0; | |
$.each($(".order-item"), | |
function(index, value) { | |
var restaurant =$.trim($(value).find('.order-restaurant > .row').find('a').text()); | |
restaurantList(repository,restaurant); | |
var amount = $(value).find('.order-details .amount-info > strong').text().split("TL"); | |
totalAmount+=parseInt(amount); | |
}); | |
console.log(`Toplam harcama: ${String(totalAmount)}`); | |
console.log(repository); | |
} | |
function restaurantList(list, name) { | |
typeof list[name] === 'undefined' ? list[name] = 1 : list[name]++; | |
} | |
function loadItems() { | |
itemLength = document.getElementsByClassName('order-item').length; | |
if (itemLength == oldLength) { | |
changed = false | |
} | |
oldLength = itemLength; | |
window.scrollTo(0, document.body.scrollHeight); | |
setTimeout(function() { | |
if (changed) { | |
loadItems(); | |
tolerance = 0 | |
} else { | |
if (tolerance > 5) | |
calculate(); | |
else { | |
tolerance++; | |
sleepTime = sleepTime - 200; | |
loadItems() | |
} | |
} | |
}, sleepTime) | |
} | |
console.log('Hesaplama yapılıyor lütfen bekleyin...'); | |
loadItems(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment