Marc Boucher’s LCT Emails
7/22/2005 8:10 PM
Here is an explanation of what I’ve done.
First I’ve notice that each message has an anchor (<a> tag with "name" and
no "href"), and that they are the only tags with names (until /. changes
something).
This has resulted in a modification of the logic of the initial parsing. No
more lookup for <ul> elements. I’ve created a new function that parse the
children of the node, and replies with the name of the anchor. The loop
looks for <td> elements containing a <a name="xx"> element.
Question. Can we create a TreeWalker that will give only elements with a
name? And if it is possible, will it work faster than the current one?
I’ve also modified the collapseAll() function to get rid of any "complex"
parsing (this function was adding a [+] at a place where there was no [-]).
For this I’ve named all [-] [+] elements and I’m searching for them with
getElementsByName(). There is even a small speed gain in the execution of
this function.
modifications to the [] elements :
[+] removed: commentNode.setAttribute("childId", node.id);
not used elsewhere
simplified: anchor.onclick
added: anchor.name="LCT";
I’ve modified toggleCommentState() to fix the problem with <ul> elements in
comments. An analysis of several situations showed that </ul><ul> separator
usually have no child (null) or a <table>. Now the function look for this
kind of <ul>.
Also, there is a special case where there is no </ul><ul> separator.
ex: http://slashdot.org/comments.pl?sid=156530&cid=13121471
so it’s also looking for a <table>. So far it doesn’t break anything
elsewhere.
Line 69: see if replacing "treeWalker.currentNode.tagName" by "tagName" is
really valid (it works here).
Line 190: the variable "count" is not used ?
Last note: I don’t use Grease Monkey. I use a gecko browser (K-Meleon)
which doesn’t use most of the XUL layer, and GM can’t be loaded. I load LCT
with a bookmarklet that inject a
<script language=’Javascript’
src=’http://a-local-server/js/slashdot-live-comment-tree.user.js’> in the
<head> element.
It works great. I had only to remove the references to GM_ functions (menu
and get/set value).
All this to tell you to double-check all interactions of the script with GM
and FF that my modifications might have broken.
7/22/2005 11:08 PM
The code is not perfect.
I’ve discovered a problem when hidding a comment in a specific situation.
7/23/2005 2:51 AM
The problem is fixed. It was due to the fact that the html structure is not
constant in ./ pages, and a <ul> of the type I was looking for was missing.
Instead of looking for </ul><ul> with child=null or <table>, we’re now expecting
<ul> with child!=’#text’ (if exists). So far it works with all my test cases.
In the meantime I’ve discovered a minor bug.
In expandNode() we discard the [+] <td>. We should discard the parent <tr>.
If you have mozilla installed with a DOM inspector, you can see the old
empty [+] </tr><tr> piling up.
I’ve tried collapseAll() with
document.evaluate("//a[@name=’LCT’]", document …
instead of
document.getElementsByName("LCT")
it’s 50% faster.
7/25/2005 1:51 PM
And here is a newer, better, faster, version.
One again I’ve changed the logic in toggleCommentState().
The purpose is still to check only for <ul> separators. This by avoiding
seeing any other types. The text of the comments box (<td>) seem to always
begin with #text. This is not the case for <ul> TDs.
The script checks the 1st child of <td> elements. If it is #text, it skips
all siblings. The consequence is that it skips <ul> in comments, as well as
other html tags, so it’s faster then before (25-35% with collapse all).
Also, treeWalker.currentNode is now set to the last child of the td header
box. No need to check tags in this cell.
7/26/2005 2:48 PM
I have fixed another problem. When the page layout is the /. text +
comments + login-form, the old version of the script, was adding the LCT
select to the login form (I was not logged in). Parsing is now done with
"//form/font/input[@type=’hidden’ and @name=’sid’]"
Last note. I don’t know if you’ve notice, but I’ve renamed the LCT options
"label" from "Live Comment Tree" to "LCT". In my screen resolution it keeps
all the form’s elements on a single line.
7/27/2005 7:04 PM
Here is a new version.
I’ve stumble on a new exception, and fixed the code. (simplified detection
of the <td> "separator")
I’ve also removed unneeded lines in the parsing code (remainings of the
first version).
No Comments »
No comments yet.
Trackback URL RSS feed for comments on this post. TrackBack URI
Leave a comment
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>






