afuna_archive: (Default)
afuna_archive ([personal profile] afuna_archive) wrote2009-01-02 04:57 pm

Getting more consistent "light" results

One thing that has frustrated me about interacting with LiveJournal programmatically, is that ?format=light does not work on all pages. It's not really something that affects most users would notice, but certain (Greasemonkey) scripts would be much much easier to write if the entry/journal pages could be guaranteed to follow the same format.

Mostly I've kludged around it by working off of the archive pages, which respond to ?format=light, so I could get data consistently. I have a script which scrapes the lj-cut text, so it can be seen in the inbox which does this. [livejournal.com profile] murklins has done me one better, with a script which lj-cuts your inbox, like the entry text. I do not know how I ever lived without this. Lifesaver. Adore, love. Seriously.

But for other pages, it's been a process of trial and error, trying to figure out whether ?format=light is supported (tag page supports it, showing a page based on s1shortcomings). Uh. Archive pages, as mentioned above. Reply pages and entry pages, obviously, using core, I think.

Not affected by ?format=light are friends and recent entries. LJ site scheme pages, meanwhile depend on the user's site scheme, unless you append ?usescheme=blah, which I always forget to /o\

It's all possible, but it can get messy depending on what you're trying to do. Which is why I love that LJ offers a mobile view. Love <3

The gist of it is that LiveJournal offers a minimalistic view for mobile phones/browsers (I suspect screenreaders could benefit). No header graphics, less junk overall, more consistent look/feel, and most importantly if you're hijacking it for scripting, it works consistently! To trigger, you need to supply the appropriate user agent:

GM_xmlhttpRequest({
   method: "GET",
   headers: {"User-Agent":"w"},
   url: $url_here,
   onload: function(details) {
       // do something with details.responseText
   });



The important part is the useragent line. The rest is just the normal stuff you need to fetch and process a page.

I haven't used it in an actual script. And since I don't play around with LJ much anymore, I'm not sure when I will. But it is a potential solution to what has up to now been a tedious problem.

[identity profile] av8rmike.livejournal.com 2009-01-02 03:22 pm (UTC)(link)
http://www.livejournal.com/support/see_request.bml?id=937187

You can't; it's been closed for a few weeks now. Let me know if you can't see the ICs.
afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)

[personal profile] afuna 2009-01-02 03:24 pm (UTC)(link)
I can see them... thanks.
afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)

[personal profile] afuna 2009-01-02 03:36 pm (UTC)(link)
Also, ooh I guess I was wrong about it not affecting "normal" users.

[identity profile] av8rmike.livejournal.com 2009-01-02 03:54 pm (UTC)(link)
Depends how you define "normal"? ;)
I had to do a lot of "code-diving" to try to ascertain how "format=light" was implemented, but the best answer seems to be "haphazardly". I don't know how the developers keep it all straight.
afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)

[personal profile] afuna 2009-01-02 04:35 pm (UTC)(link)
Point :-) And I'm not sure they do! I get the feeling that S2, integration etc, is sort of bolted together or grew organically.

[identity profile] av8rmike.livejournal.com 2009-01-02 04:39 pm (UTC)(link)
If that's the case, it must be a nightmare to maintain the code base, which is why 6A chose to divest themselves of it.

So, why'd you leave Support? Too much code to be done, not enough time? ;)
afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)

[personal profile] afuna 2009-01-02 04:41 pm (UTC)(link)
I have great respect for LJ developers for keeping their sanity.

As for leaving Support, I had a few reasons, and yeah, that was one of them :)