Merge pull request #54 from shwin0901/master

Only count the last week history statistics
This commit is contained in:
Folyd 2020-05-28 23:34:58 +08:00 committed by GitHub
commit 4fb9fd228c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View file

@ -1,5 +1,5 @@
.main {
padding: 2rem;
padding: 2.2rem;
}
.toast {
@ -103,7 +103,7 @@ input:checked + .slider:before {
.stats-link {
color:#121212;
font-size: 15px;
font-size: 14px;
border-radius: 5px;
padding: 0;
text-decoration: none;

View file

@ -12,7 +12,7 @@
body {
scroll-behavior: smooth;
overflow-x: hidden;
width: 280px;
width: 300px;
padding: 0;
margin: 0;
}
@ -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 in the 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 {