my little comment ponies March 18, 2006 10:44 AM   Subscribe

Matt, can you add some more class to your comment HTML so that independent scripts such as my Comment script and MeFi Navigator have a more assured chance of cohabitating? [by a fluke there turned out to be no fatal interactions]

Also, the best way to quote comments is with a DIV. Can you make this possible? [more inside]
posted by MonkeySaltedNuts to Feature Requests at 10:44 AM (25 comments total)

First the DIV quote issue:

My script can append the underlying HTML of part of somebody's comment to the reply box – i.e. it preserves formatting HTML and A links. With this ability, the best way to quote this HTML is to wrap it in something like <div style='padding-left: .4em; border-left: thin solid;'>…</div>. This gives clean displays of quoting quotes of quotes. This wrapper works fine in live preview, but doesn’t make it into the real preview. Since you may have some qualms about passing arbitrary HTML into a comment, could you at least update the HTML filters and stylesheet so that <div class='quote'> can make it into a comment?

Second the HTML class issue:

I thought my script would have problems with MeFi Navigator because that script alters the shape of the DOM. I was lucky that that script obeyed Natural Motherhood principles (e.g. it only used appendChild) so that no absolute paths were affected.

The problem is that without class signposts one has to resort to absolute (numerical index, e.g. '[1]') DOM position to scrape out the necessary info. My current XPaths are:
  COMMENTSpath   = "html/body/div[@id='page']/div[@class='copy' or @class='comments']";   AUTHORsubPath = "span/a[1]/text()";   LINKsubPath   = "span/a[2]/@href";
If some script I want to cohabite with changes the shape of that part of the DOM then such absolute paths would be off.

Could you add some class so the paths could be something like:
  AUTHORsubPath = "span/a[@class=’author’]/text()";  LINKsubPath   = "span/a[@class=’link’]/@href";
or whatever class names you like?

In addition, why does www.metafilter.com and ask.metafilter.com have comment pages that include a <div class=’page’> while metatalk.metafilter.com does not? Not only does my script have to special case this, but my scheme generates things like <a href="/mefi/11372#page">drpynchon</a> to link to the starting post. This link doesn't work in metatalk.metafilter.com.

Finally, since I am asking for class additions, I have another (not ready for prime time) script that scrapes the front pages of blue, green, and brown. Will you please class the things under smallcopy? I currently have to resort to an XPath like:
  IdSubPath = "span[@class='smallcopy']/a[contains(@href, '/mefi/')]/@href";
Adding some more class to your HTML would make it easier to write scripts and may make them more resilient to site HTML changes and cohabitating with other scripts.

PS: anybody that wants to understand and use Xpath should install the Xpather extension.
posted by MonkeySaltedNuts at 10:46 AM on March 18, 2006


also, if div is out, something like <blockquote class='reply'> would work equally as well.
posted by MonkeySaltedNuts at 10:52 AM on March 18, 2006


" ... can you add some more class to your comment HTML ... "

Or, failing that, to the membership?
posted by mr_crash_davis at 11:21 AM on March 18, 2006


Good stuff, monkeysaltednuts. I didn't like accessing nodes by numerical indices, but it seemed the only way (I wrote Mefi Navigator, btw).

I agree with your suggestions, but I also think the onus is on script writers to do everything they can to avoid conflicts. This means, for example, using something like window.addEventListener('load',init()); to run your script on page load, as opposed to simply calling init() somewhere in your script. This was the problem that caused Mefi Navigator not to work with an Asynchronous Flagging script. I had to get people to make this change to their local copy of the Async Flagging script, which is a less than ideal way of bug-fixing, especially as the number of MeFi greasemonkey scripts increases.
posted by matthewr at 12:08 PM on March 18, 2006


I just tried your script, MonkeySaltedNuts, and it's really cool. Couple of quick suggestions: could you test for the site subdomain (i.e. Mefi, Ask, MeTa), and make the highlighted background colour complementary to the site's background colour - the blue on green/grey combination isn't very easy on the eyes. It'd also be nice if you could deselect a comment by clicking away, i.e. clicking outside the comment div would deselect it. Also, perhaps consider making a little diagram (something like this) to indicate what it all does before installing it.

I realise it's only alpha so you might be putting off changes until you hear back from Matt regarding markup changes. Just thought I'd add my two cents, though.
posted by matthewr at 12:22 PM on March 18, 2006


#matthewr: could you test for the site subdomain ... It'd also be nice if you could deselect a comment

Sure I can site class the selection color. Do other people want it?

But why do you want to deselect a comment (other than to avoid the color clashes)? I think always being able to scroll to the last selected comment is useful and accidental clicks could defeat this.
posted by MonkeySaltedNuts at 12:35 PM on March 18, 2006


With pretty much all programs, I like the ability to quickly undo whatever I just did, or at least to get the page to how it was when I started. Having written this, I realise it sounds completely irrational and possibly insane, but it kind of makes sense to me.

Once this is finished, do post it to Projects.
posted by matthewr at 12:46 PM on March 18, 2006


Also, what are "Natural Motherhood principles"? I googled '"natural motherhood" appendChild' and got 0 results.
posted by matthewr at 12:55 PM on March 18, 2006


Hmm. There seems to me that we need a balance between what script writers want and what I can provide while maintaining the site and keeping it looking and working as it does for those not using special scripts.

To me, your first request seems silly. To quote people, I use blockquote, and I will continue to strip out classes and styles inline to keep the site looking and behaving the way it should. You're asking for an exemption and for me to add classes to blockquotes from now on for your script. That seems like asking for too much, as the whole point of greasemonkey is that it works with existing sites. The second issue seems to be with other script writers, not necessarily me.

If you have some simple fixes that don't require me to write special case code for your scripts, provide a sample comment page with the HTML changes made and I'll take a look.
posted by mathowie (staff) at 1:02 PM on March 18, 2006


mathowie: Having reread the first request, I agree that it's a bit unreasonable.

The second request, however, is quite simple, and would help all script-writers. At the end of every comment, where you have the author-name link, and the timestamp perma-link, you'd just add class='author' or class='link' to the links, respectively. You wouldn't have to add anything to stylesheets or anything, since these class attributes just act as flags, in a way, that enable scripts to pick up the right link even if other scripts have already been run. Currently, the method us script-writers have of working out the name of the user who wrote a comment is very fragile and likely to break when multiple scripts run, and there's not much we can do about that. I sympathise with your desire to work on the site for users, not scripters, though.

Also, a little heads-up: when playing around with this sort of thing, I found a cunning way to sneak any class attribute into a blockquote, so I could have posted something with <blockquote class='quote'>. This works on preview (normal and live). I didn't manage to get any style attributes through preview, you'll be glad to hear.
posted by matthewr at 1:23 PM on March 18, 2006


#matthewr: what are "Natural Motherhood principles"

Sorry, that is a term I invented in working on another project to describe DOM changes that preserve existing DOM structure. I don't think it has made it to the web.

It is an analogy between changing the children of a DOM node and how the children of say a human mother can change.

First the children of a mother are only changed by giving birth to a new child and that is appended to the end of the birth order. (Eg. a human with a 1 year old cannot give birth to a 2 year old)

Second while children may die that does not effect the birth order of the other children. In DOM that means that that no child nodes can be deleted. To kill a child you have to hide it by saying style='display: none;. To move a child you have to clone it and hide the original. This would be like having a human 2 week old child named John who dies and then deciding to name a later born child John.
posted by MonkeySaltedNuts at 1:39 PM on March 18, 2006


I'd love to learn XPath, but all this talk of infant death makes me realise the cost to innocent bystanders is too high.

(however, any other faboo links, open to those not clung to Mozilla's ample bosom?)
posted by NinjaPirate at 2:23 PM on March 18, 2006


I don't particularly like the blobbiness of some of MetaFilter's internal structure, but I can't agree that the only way to extract the information you want is through numbered indices. Stricter pattern-matching, both positional and textual, should work. The matching approach would also be more robust for a particular script when known or future unknown scripts stuff in their own buttons or links.

Granted, you have to step outside of XPath usage to qualify your information, but it seems questionable that the onus for making tasks easier for external scripts should be on the site. Although, if Meta were rewritten to be friendlier to script information extraction, I wouldn't exactly bitch about it either. It would make the scripts both less prone to breakage and easier to maintain.

But it gets my vote only if it would fall under the "very minor, almost no time and effort" change description. As best I can determine, the overall percentage of total MF membership who use Greasemonkey scripts is quite small. MetaFilter has much bigger problems which ought to command all the priority attention of Matt Haughey. For example, reworking the entire site's infrastructure (soft and hard) to properly scale for ever-increasing traffic and achieve improved uptime is likely a major wish-list item for almost anyone who regularly visits here.
posted by mdevore at 2:34 PM on March 18, 2006


mdevore: In principle, there's no reason not to pattern-match. My script, however, needs to look at every single username and permalink on the page, and pattern-matching (eg regex?) would make it unacceptably slow. The thing I recommended in my previous comment (originally proposed by MSN) would only mean adding a class attribute to the links in each comment's 'posted by' line. I'm guessing this would be really easy to implement, and wouldn't break anything else.

I agree that script-writing is, rightly, very low down the priority list for Matt. However, I was really surprised by the number of users who downloaded MeFi Navigator (userscripts.org gives you rudimentary stats), given that so few people will have even heard of GreaseMonkey.
posted by matthewr at 2:47 PM on March 18, 2006


Third-party scripts should take Metafilter as it exists, and adapt themselves to any changes. The site shouldn't be constrained from changing because of assumptions or expectations of third-party scripts.

I write this as the first person to produce a third-party script for MetaFilter. My script would have been easier to write, and more useful features could have been added if Matt had regularized MataFilter, but my attempts to contact Matt to coordinate went unanswered. That's Matt's priviledge.
posted by orthogonality at 3:12 PM on March 18, 2006


Oh, and absolute nodes are not absolutely necessary; my third-party script uses both absolute nodes and hueristics to scrape the data it scrapes.
posted by orthogonality at 3:14 PM on March 18, 2006


#orthogonality: I write this as the first person to produce a third-party script for MetaFilter.

I'm sorry, but I can't find the script you are referring to. Can you post a link?

Also, why do you use the term third-party? My understanding is that the first party is MeFi site scripts and the second party is browser user-scripts.

Who is your 2nd party? Do you think that a website that runs a script over MeFi is a defacto 2nd party which makes browser user-scripts 3rd party?

I really cannot understand your terminology.
posted by MonkeySaltedNuts at 8:41 PM on March 18, 2006


First party: content creator.
Second party: web browser user. (An interaction involving no extensions or user scripts would involve only the first two parties.)
Third party: someone else.
posted by Plutor at 9:36 PM on March 18, 2006


First party = MetaFilter
Second party = the user
Third party = someone else

i.e., a third-party script would be a script that was written by someone other than the person using it.
posted by kindall at 9:47 PM on March 18, 2006


yeah #Plutor and #kindall you are kinda right. From a user perspective all user-scripts are 3rd party.

I was thinking from a script perspective in which there are only site-scripts and user-scripts.
posted by MonkeySaltedNuts at 11:03 PM on March 18, 2006


I just read this thread and installed XPather (very cool, thanks). Where I went wrong was doing it with my girl in the same room -- I'm pretty sure I'm never having sex again.
posted by cedar at 4:43 AM on March 19, 2006


Just wanted to toss in that I'd say blockquote is definitely more semantically accurate for quoting than styled div elements. After all, you can style up blockquote just like div, and it degrades more gracefully in regard to its original intent.
posted by secret about box at 6:04 AM on March 19, 2006


What would be nice is if we just had a standard XML output for metafilter. Mefi for regular users could then simply be an XSLT stylesheet applied to it, and script writers could go nuts.
posted by delmoi at 11:45 AM on March 19, 2006


Who is your 2nd party? Do you think that a website that runs a script over MeFi is a defacto 2nd party which makes browser user-scripts 3rd party?

First party is matt, second party is the reader, third party is orthogonality. The parties represent people not software. It's the same as "third party" games for a video game system. It's a very standard term.
posted by delmoi at 11:47 AM on March 19, 2006


MonkeySaltedNuts writes "I'm sorry, but I can't find the script you are referring to."

The "MetaFilthy" Firefox extension. It scrolls readers to the first unread coment in each thread, and allows them to quote others' comments with a back-link to the origibnal comment, using the quoted comments' HTML source (as for example, what I did in the previous paragraph).
posted by orthogonality at 12:06 PM on March 19, 2006


« Older Email from Marshall Oak.   |   Conspiracy theorists turn up in implosion... Newer »

You are not logged in, either login or create an account to post comments