Post by ⓦ৹₪deⓡ on Sept 24, 2005 22:56:33 GMT -8
This code will show the number of unread posts in new threads. I don't recommend this code if your users browse a considerable amount of threads (I'm talking thousands) because this code stores thread data as cookies and cookies have a max size of 4KB. It will show the number of unread posts in threads marked as new. If a user clears their cookies or uses a different computer, the numbers will not be accurate. It keeps this data in the cookie for 2 weeks. So if a user does not browse a particular thread for 2 weeks, it will no longer store data about that thread. It will not be accurate immediately. It will take a couple of hours or even days before it gets information about the threads you visit. Enjoy.
~Wonder
~Wonder
<script>
//Show Number of Unread Posts v1.0
//Copyright 9-25-2005 by ~Wonder
//May be reposted anywhere as long as this header remains in tact
//Put in Global Footer
if(location.href.match(/board\=/))
{
td=document.getElementsByTagName("td");
for(i=0;i<td.length;i++)
{
if(td[i].className=="windowbg" && td[i].innerHTML.match(/alt="new/) && td[i].innerHTML.match(/thread\=(\d+)/))
{
newposts=parseInt(td[i+2].innerHTML.split(">")[2].split("<")[0]);
if(document.cookie.indexOf(RegExp.$1)!=-1)
{
newposts=newposts-parseInt(document.cookie.split(RegExp.$1+"=")[1].split(';')[0]);
}
td[i].innerHTML+="<br>("+(newposts+1)+" new posts)";
}
}
}
if(location.href.match(/thread\=/))
{
td=document.getElementsByTagName("td");
for(i=0;i<td.length;i++)
{
if(td[i].innerHTML.match(/« Reply #(\d+) on/) && td[i].width=="55%")
{
}
}
thread=location.href.split("thread=")[1];if(thread.indexOf("&")){thread=thread.split("&")[0];}
temp=new Date
temp.setTime(temp.getTime() + 1209600000);
oldposts=0;
if(document.cookie.indexOf(thread+"=")!=-1){oldposts=parseInt(document.cookie.split(thread+"=")[1].split(';')[0])}
if(parseInt(RegExp.$1)>oldposts){document.cookie=thread+"="+RegExp.$1+"; expires="+temp.toGMTString();}
}
</script>