mirror of https://gitgud.io/fatchan/jschan.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.3 KiB
35 lines
1.3 KiB
window.addEventListener('DOMContentLoaded', (event) => {
|
|
|
|
const statsElem = document.getElementById('threadstats');
|
|
if (statsElem) {
|
|
const uidElems = document.getElementsByClassName('user-id');
|
|
const uidSet = new Set();
|
|
for(let i = 0; i < uidElems.length; i++) {
|
|
uidSet.add(uidElems[i].innerText);
|
|
}
|
|
window.addEventListener('addPost', function(e) {
|
|
if (e.detail.hover) {
|
|
return; //dont need to handle hovered posts for this
|
|
}
|
|
const newFiles = e.detail.json.files.length;
|
|
const numPosts = +statsElem.children[0].innerText.match(/^(\d+)/g);
|
|
const numFiles = +statsElem.children[1].innerText.match(/^(\d+)/g);
|
|
const filesTotal = numFiles + newFiles;
|
|
const postTotal = numPosts + 1;
|
|
statsElem.children[0].innerText = `${postTotal} repl${postTotal === 1 ? 'y' : 'ies'}`;
|
|
statsElem.children[1].innerText = `${filesTotal} file${filesTotal === 1 ? '' : 's'}`;
|
|
if (e.detail.json.userId) {
|
|
uidSet.add(e.detail.json.userId);
|
|
if (!statsElem.children[2]) {
|
|
//UIDs enabled after thread generated
|
|
const spacer = document.createTextNode(' | ');
|
|
const uidSpan = document.createElement('span');
|
|
statsElem.appendChild(spacer);
|
|
statsElem.appendChild(uidSpan);
|
|
}
|
|
statsElem.children[2].innerText = `${uidSet.size} UID${uidSet.size === 1 ? '' : 's'}`;
|
|
}
|
|
});
|
|
}
|
|
|
|
});
|
|
|