mirror of
https://github.com/Marketscrape/marketscrape-web.git
synced 2026-04-20 13:56:53 -04:00
Merge pull request #66 from alexwholland/alex/-top_ten_results
Limit result history to 10
This commit is contained in:
24
scraper/static/removeOldResult.js
Normal file
24
scraper/static/removeOldResult.js
Normal file
@@ -0,0 +1,24 @@
|
||||
// Get array of all dates
|
||||
var dates = [];
|
||||
for (var i = 0; i < localStorage.length; i++) {
|
||||
var shortened_url = localStorage.key(i);
|
||||
var data = JSON.parse(localStorage.getItem(shortened_url));
|
||||
dates.push(data.date);
|
||||
}
|
||||
|
||||
// Sort the dates in descending order
|
||||
dates.sort(function(a, b) {
|
||||
return new Date(b) - new Date(a);
|
||||
});
|
||||
|
||||
// Select the two most recent dates
|
||||
var mostRecentDates = dates.slice(0, 10);
|
||||
|
||||
// Remove any items that are not in the most recent two dates
|
||||
for (var i = localStorage.length - 1; i >= 0; i--) {
|
||||
var shortened_url = localStorage.key(i);
|
||||
var data = JSON.parse(localStorage.getItem(shortened_url));
|
||||
if (mostRecentDates.indexOf(data.date) === -1) {
|
||||
localStorage.removeItem(shortened_url);
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@
|
||||
</div>
|
||||
|
||||
<script src="{% static 'clearLocalStorage.js' %}"></script>
|
||||
<script src="{% static 'removeOldResult.js' %}"></script>
|
||||
<script src="{% static 'rowResult.js' %}"></script>
|
||||
<script src="{% static 'filterSearchResults.js' %}"></script>
|
||||
<script src="{% static 'displayEmptyMessage.js' %}"></script>
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
image: "{{ image }}",
|
||||
title: "{{ title }}",
|
||||
rating: "{{ price_rating }}",
|
||||
price: "{{ price }}"
|
||||
price: "{{ price }}",
|
||||
date: new Date()
|
||||
};
|
||||
var shortened_url = "{{ shortened_url }}";
|
||||
localStorage.setItem(shortened_url, JSON.stringify(item));
|
||||
|
||||
Reference in New Issue
Block a user