Warning: Geekery ahead!
November 3rd, 2005 | Published in Google Reader
You may have noticed that some Greasemonkey scripts broke with the recent release (for example, the excellent Google Reader Auto-Read). First, a bit of background. Reader uses JavaScript. A lot of it. So much that it would take a while to download even on a broadband connection. What we (and other Google products) do is to compress it before sending it to the user. So this line of code:
FR_Queue_currentQueue.pageDown();
becomes:
t.ma()
Only people care about descriptive names like pageDown
; to a computer, ma
is just as good. It turns out that these compressed names will change from release to release, as we tweak the code (the more often a name is used, the shorter the compressed name that's chosen for it). Greasemonkey scripts that rely on these compressed names (like the aforementioned one) will therefore break.
So far the situation sounds pretty dire. How can more stable scripts be written? The answer turns out be quite simple. Reader has UI controls for most things that you'd want to do from a script. For example, if you want to automatically move the queue down, you can think of that as being equivalent to the user clicking the "Down" button repeatedly. Those buttons have IDs that we promise won't change without a good reason. Through JavaScript, you can simulate user clicks. Therefore, if your Greasemonkey scripts relies on them, you'll be all set. To give an example, I've written a modified version of the auto-read script that uses this method. It has code like the following (the simulateClick
function is included in the script):
simulateClick(getNode("queue-down"));
I hope this helps other Greasemonkey scripts authors that are trying to tweak Reader (and other sites too).
P.S. We just pushed a new Reader release. No new features, but we have fixed a few bugs with unsubscribing and keeping things unread.