A blog about skating and cycling, or vice versa

But I repeat myself#

Tue, 02 Sep 2008 14:12:36 +0000

I read and write to more forums than I probably have time for, plus usenet plus facebook. Apart from anything else, this often means I forget where I've written something when I later want to refer back to it. So, henceforth if I think it is going to be interesting I can easily blog it as well, by highlighting the relevant bit and clicking on the "Blog this" menu toolbar item in Firefox. It generates a blog entry spookily similar to the two which precede this.

OK, so at the moment that's not entirely true, just because the toolbar button in question is still labelled 'test'. Aside from that, though. It sounds dead simple to implement, and it's only quoting/escaping rules that make it otherwise:

//  ==UserScript==
// @name          Blog to Coruskate
// @namespace     http://www.coruskate.net/
// @description   Create new coruskate blog entry with selected text
// @include       *
// ==/UserScript==
 
unsafeWindow.blog=function () {
    var text=window.getSelection();
    var url=window.location.href;
    if(text) text=text.getRangeAt(0).cloneContents();
    else text='';
    var serializer = new XMLSerializer();
    text = serializer.serializeToString(text);
    var body="From "+url+" :\n"+
    "<blockquote>\n" +
    text +
    "</blockquote>\n";
    ;; cnames have been changed to protect the innocent
    var win=window.open("http://go-away-googlebot.coruskate.net/or/this/bit/newentry?BODY="+
			encodeURIComponent(body));
};
In short, even if I could work out the correct number of percents and ampersands to encode all of that into a javascript: url, I would almost certainly be unable to edit it subsequently. So, that becomes a greasemonkey script and the toolbar bookmark is "javascript:blog()"