HaloScan Commenting and Trackback

dronoubog
letodarlaa
eldomcolac4t

Displaying when comments are new


WARNING: The following hack is currently not working due to recent changes in the Haloscan code. Do not install this code at this time

If you are not comfortable editing your template and working with HTML code please do not proceed. The code provided is used at your discretion and is not a formal part of the HaloScan offering

The instructions below do not apply to any particular blog package, you may find some steps are different.

You can add in some Javascript to your HaloScan template which will alter the comment link dynamically to display when you have new comments and how many new comments have been added since your last visit.

Step #1: Installation

If you don't have webspace or any idea of how to upload files, Part A will detail how to get this working.
Otherwise, you can skip to part B.

Part A
  1. Backup your template, first.
  2. Go to the template page and click inside the window.
  3. Choose "Select All" in the Edit menu to highlight the whole template.
  4. Then copy and paste the text into a new text file save it as "myBackupBlog.html".*
  5. Next, copy all the code listed in the box below.
  6. Edit your template, and inbetween the <head> and </head> tags, underneath Step #1 of the haloscan code, paste your huge chunk of copied code.

*If something goes wrong, or you don't like this mod, then you can easily just replace everything with this backup copy.

Part B
  1. Backup your template, first.
  2. Go to the template page and click inside the window.
  3. Choose "Select All" in the Edit menu to highlight the whole template.
  4. Then copy and paste the text into a new text file save it as "myBackupBlog.html".*
  5. Copy all the code in the box below, and paste it in a new text file called new_cmts.js
  6. Upload the file and inbetween the <head> and </head> tags, paste this line of text underneath Step #1 of the HaloScan code: <script type="text/javascript" src="http://YOURWEBSPACE/new_cmts.js"> </script>

Step #2: Usage

You now need to edit the comment link in your template.
  1. Open your template.
  2. Locate the comment link code (after the post area).
  3. For the comment link, replace HaloScan('YOURCOMMENTID') with hs_HaloScan('YOURCOMMENTID').
  4. Replace postCount('YOURCOMMENTID') with hs_postCount('YOURCOMMENTID')


<script type=text/javascript>
/* This javascript code uses cookies to keep track of comments the
user has viewed so far, in order to show which comments are new.
This code is free for use/modification, whatever tickles your funnybone. :-D
Have a blast - Jtoxification. Google me for info. */

/*------------------------------------------------------*/
hs_MAXSIZE=3072;

/*Shows when there's only one comment and it hasn't been read yet.*/
hs_sameCountSingle = "# new comment"

/*Shows when there's more than one comment and they haven't been read yet.*/
hs_sameCountText = "# new comments"

/*Shows when there are new comments mixed in with old comments.*/
hs_newCountText = ":(# new)";

/*------------------------------------------------------*/

hs_begin_seperator="+"; hs_seperator="&";  hs_divider="/";  hs_cookie_jar="";  hs_cookie = new Array();  hs_cookie_size=0;  hs_cookie_name = "haloscan_comments";  hs_expire_date =";expires=Fri, 01-Jan-2070 00:00:00 GMT";  hs_search = new RegExp('\\W','gi');
function hs_cookies_enabled_func() {   if (document.cookie == "")   {   document.cookie = "cookies=true";   if (document.cookie.indexOf("cookies=true") == -1)   return false;   }   return true;   }
function hs_enabled_func() {  try  {  if (hs) return true;   else return false;  }   catch(exception)  { return false; }  }
function hs_createArrayFromCookie() {   hs_cookie_jar = hs_cookie_name+"=";   var i;   var tmp = null;  var ray = null;  var str;   var ray3=null;   if (document.cookie == "") return;   ray = (""+document.cookie).split(";");   for (i = 0; i < ray.length; i++)   {   if (ray[i].indexOf(hs_cookie_name) != -1)   {   hs_cookie_jar = ray[i] + hs_divider;   str = (ray[i].split("="))[1];   ray3 = str.split(hs_divider);   if (ray3.length == 1)   {   tmp = str.split(hs_seperator);   hs_cookie[tmp[0].substr(1)] = parseInt(tmp[1]);   hs_cookie_size = 1;  return;   }   hs_cookie_size = ray3.length;   break;   }   }   if (!(i < ray.length)) return;   for(i = 0;i < hs_cookie_size;i++)   {   tmp = ray3[i].split(hs_seperator);   hs_cookie[tmp[0].substr(1)] = parseInt(tmp[1]);   }   }
function hs_newCount(id) {   var tmp = "";   var hs_ct = 0;   var cookie_ct = 0;   var ct = 0;   if (hs[id]) hs_ct = hs[id];   if (hs_cookie[id]) cookie_ct = hs_cookie[id];   ct = hs_ct-cookie_ct;   if (ct < 0) ct = 0;   if (ct==0) postCount(id);   else if ( ct==hs_ct)  {  if (ct >
1) tmp = hs_sameCountText.replace("#",ct);  else tmp = hs_sameCountSingle.replace("#",ct);  }  else   {  postCount(id);  tmp = hs_newCountText.replace("#",ct);   }  return tmp;  }
function hs_postCount(id) {    if (hs_enabled)    {    id = id.replace(hs_search,"_");    if (hs_cookies_enabled)   {   var tmp = hs_newCount(id);    if (tmp.length > 1) document.write(tmp);   }   else postCount(id); }    else document.write("Comments are down temporarily.");   }
function hs_updateCookie(postID,pCount) {   var i = hs_cookie_jar.indexOf(hs_begin_seperator+postID+hs_seperator);   if (i != -1)   {   var tmp_jar = hs_cookie_jar.substring(0,i) + hs_cookie_jar.substr(hs_cookie_jar.indexOf(hs_divider,i)+1);   hs_cookie_jar = tmp_jar;   }   hs_cookie_jar += hs_begin_seperator + postID + hs_seperator + pCount;   while ((hs_cookie_jar.length+hs_expire_date.length) > hs_MAXSIZE)   {   hs_cookie_jar = hs_cookie_name+"="+hs_cookie_jar.substr(hs_cookie_jar.indexOf(hs_divider)+1);  }   document.cookie = hs_cookie_jar + hs_expire_date; hs_cookie_jar += hs_divider;   }
function hs_HaloScan(id) {  if (hs_enabled)   {   id = id.replace(hs_search,"_");   if (hs_cookies_enabled)   {  if (hs[id]) hs_updateCookie(id,hs[id]);   else hs_updateCookie(id,0);  }   HaloScan(id);   }   }

/*Initialization Section:------------------------------------------------*/
hs_cookies_enabled = hs_cookies_enabled_func();
hs_enabled = hs_enabled_func();
if (hs_cookies_enabled) { hs_createArrayFromCookie(); }


NOTE: I've set the maximum size of the cookie created by this code to 3 Kilobytes (3072 bytes, see the very first line of the code.) just in case there's anything else on the page that uses cookies. If you have other scripts on your page that make heavy use of cookies, it'd be a good idea to manage this number to something slightly smaller, otherwise this mod could be adversely affected. (In which case, it'll probably just show things as new most of the time). However, if you're certain that's the only script on your page that utilizes cookies, I recommend you up the number to 4040, leaving some safety room for just in case, since the default maximum cookie size is about 4096 bytes. I also recommend that you do not set the number any lower than 2000 bytes. In general, stay between 2000 - 4040 bytes.

Also, you may change the text displayed for new comments below, provided that you DON'T add
any extra double quotation marks to the texts ! But if you must, then prefix it with a backslash
like this \"

Double quotation marks actually define the start and stop of javascript text, but the backslash makes it
act normal(and the backslash will disappear when viewed from a browser).


Code provided by jtox
Page was generated in 0.3130 seconds