Javascript, Greasemonkey and clipboards
2006-12-08
2 minutes read

One of the jobs of an archive administrator in Ubuntu processing sync requests. The job is fairly simple: read a sync request (in the form of a bug report), make sure it includes the relevant information and is either filed by or seconded by a person with the appropriate permissions. Then, it’s downloading the source, injecting it into the correct queue and marking the bug as closed.

The by far most boring bit of this is actually closing the bugs: opening the bug report, clicking on the relevant task, marking as “Fix released”, assigning to myself, pasting the update report from an editor and clicking “submit”. Rinse and repeat, today for 73 bugs.

To help this, I started looking into writing a greasemonkey script. Just add a button besides the submit button which would then be labeled DTRT or something like it, but ran into some trouble which is really obvious: Javascript run in the content’s security context can’t access your clipboard. A small hack to greasemonkey.js fixed this and I now have a shiny GM_fromClipboard function. After playing around with this for a while, I thought it wouldn’t help me at all since the javascript is called in the page content’s security context, but any event listeners I add seemingly aren’t. Nice. (This is of course due to the whole concept of closures and how Javascript works.)

Anyway, I ended up with a script that does the right thing. It needs a greasemonkey patch.

Back to posts