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] murklins.livejournal.com 2009-01-02 07:30 pm (UTC)(link)
Thanks for writing this up! I am going to bookmark it so that next time I write an LJ script I don't have to tap you on the shoulder and confess that I vaguely remember you mentioning a consistent format=light alternative but can't for the life of me recall any specifics. I am not going to look over my script and see if it can benefit from this technique though. I am afraid of all my own code.
afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)

[personal profile] afuna 2009-01-03 01:03 pm (UTC)(link)
Awesome, glad I could (future-)help!

I am not going to look over my script and see if it can benefit from this technique though

My dirty secret: I'm not going over my old scripts either XD

Love ya, and miss ya, babe <3