Only count the last week history statistics

This commit is contained in:
shwin0901 2020-05-28 23:13:56 +08:00
parent b499410ab3
commit de454df56c
2 changed files with 8 additions and 2 deletions

View file

@ -61,7 +61,7 @@
</div>
<div class="statistics-page">
<a href="../stats/index.html" target="_blank" class="stats-link">
<b id="stats-week-count">0</b> searchings this week >
<b id="stats-week-count">0</b> searchings last week >
</a>
</div>
<div style="margin-top: 30px; font-size: 11px;text-align: center">

View file

@ -77,10 +77,16 @@ document.addEventListener('DOMContentLoaded', function() {
crateRegistry.onchange = function() {
settings.crateRegistry = crateRegistry.value;
};
let history = JSON.parse(localStorage.getItem("history"));
let statsPage = document.querySelector(".statistics-page");
let statsWeekCount = statsPage.querySelector("#stats-week-count");
let now = new Date();
let weekAgo = now.setDate(now.getDate() - 7);
history = history.filter(({time}) => {
return weekAgo <= time;
});
if(history) {
statsWeekCount.textContent = `${history.length}`
} else {