Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Stardew Valley Forum Sort By Views per Day
(() => {
let listItemsElem = document.querySelector('.discussionListItems')
let listItems = [...listItemsElem.querySelectorAll('.discussionListItem')]
listItems = listItems.map(listItem => {
let elems = {}
elems.listItem = listItem
elems.date = listItem.querySelector('.DateTime')
elems.replies = listItem.querySelector('.stats .major dd')
elems.views = listItem.querySelector('.stats .minor dd')
let date = Date.parse(elems.date.textContent)
let replies = parseInt(elems.replies.textContent.replace(',', ''), 10)
let views = parseInt(elems.views.textContent.replace(',', ''), 10)
let days = ((new Date())-date)/1000/60/60/24
let repliesperday = replies/days
let viewsperday = views/days
let views_title = listItem.querySelector('.stats .minor dt')
views_title.textContent = 'Views (' + parseInt(viewsperday,10) + '):'
return { date, replies, views, days, viewsperday, repliesperday, elems }
})
listItems.sort((a,b) => b.viewsperday-a.viewsperday)
listItems.forEach(i => {
let e = i.elems.listItem
listItemsElem.appendChild(e)
})
console.log(listItems)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.