dsf
This commit is contained in:
parent
7fb2f8f6cc
commit
695832a391
251 changed files with 44 additions and 44 deletions
39
files/assets/js/new_comments_count.js
Normal file
39
files/assets/js/new_comments_count.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
if (typeof showNewCommentCounts === 'undefined') {
|
||||
function showNewCommentCounts(postId, newTotal) {
|
||||
const comments = JSON.parse(localStorage.getItem("comment-counts")) || {}
|
||||
|
||||
const lastCount = comments[postId]
|
||||
if (lastCount) {
|
||||
const newComments = newTotal - lastCount.c
|
||||
if (newComments > 0) {
|
||||
document.querySelectorAll(`#post-${postId} .new-comments`).forEach(elem => {
|
||||
elem.textContent = ` (+${newComments})`
|
||||
elem.classList.remove("d-none")
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const LAST_CACHE_CLEAN_ID = "last-cache-clean"
|
||||
const EXPIRE_INTERVAL_MILLIS = 5 * 24 * 60 * 60 * 1000
|
||||
const CACHE_CLEAN_INTERVAL = 60 * 60 * 1000 // 1 hour
|
||||
|
||||
function cleanCache() {
|
||||
const lastCacheClean = JSON.parse(localStorage.getItem(LAST_CACHE_CLEAN_ID)) || Date.now()
|
||||
const now = Date.now()
|
||||
|
||||
if (now - lastCacheClean > CACHE_CLEAN_INTERVAL) {
|
||||
const comments = JSON.parse(localStorage.getItem("comment-counts")) || {}
|
||||
|
||||
for (let [key, value] of Object.entries(comments)) {
|
||||
if (now - value.t > EXPIRE_INTERVAL_MILLIS) {
|
||||
delete comments[key]
|
||||
}
|
||||
}
|
||||
window.localStorage.setItem("comment-counts", JSON.stringify(comments))
|
||||
}
|
||||
window.localStorage.setItem(LAST_CACHE_CLEAN_ID, JSON.stringify(now))
|
||||
}
|
||||
|
||||
setTimeout(cleanCache, 500)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue